Compare commits
2 Commits
db3cf0ee29
...
b0e2f0e25b
Author | SHA1 | Date | |
---|---|---|---|
b0e2f0e25b | |||
fa2e4b0669 |
@ -16,12 +16,13 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
//implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-webflux'
|
||||
implementation 'org.apache.httpcomponents.client5:httpclient5:5.2.1'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation 'io.projectreactor:reactor-test'
|
||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||
|
||||
//testImplementation 'org.springframework.security:spring-security-test'
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package djmil.cordacheckers;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -26,4 +27,14 @@ public class ApiController {
|
||||
return ResponseEntity.ok(joke);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a Json list of active games
|
||||
*/
|
||||
@GetMapping("/api/activegames")
|
||||
public ResponseEntity<String> dashboard(Principal principal) {
|
||||
|
||||
return ResponseEntity.ok("{ \"ActiveGames\" : [\"game\", \"GAME\", \""+principal.getName()+ "\" ] }" );
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package djmil.cordacheckers;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConfig {
|
||||
|
||||
@Bean
|
||||
PasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
|
||||
@Bean
|
||||
UserDetailsService hardcodedCordaUsers(PasswordEncoder passwordEncoder) {
|
||||
User.UserBuilder users = User.builder();
|
||||
|
||||
UserDetails alice = users
|
||||
.username("alice")
|
||||
.password(passwordEncoder.encode("qaz123"))
|
||||
.build();
|
||||
|
||||
UserDetails bob = users
|
||||
.username("bob")
|
||||
.password(passwordEncoder.encode("qaz123"))
|
||||
.build();
|
||||
|
||||
return new InMemoryUserDetailsManager(alice, bob);
|
||||
}
|
||||
|
||||
}
|
@ -3,14 +3,15 @@ import React, { useState, useEffect } from 'react';
|
||||
|
||||
function App() {
|
||||
|
||||
const [joke, setJoke] = useState(null);
|
||||
const [activeGames, setActiveGames] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/badjokes')
|
||||
fetch('/api/activegames')
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
console.log(data.joke);
|
||||
setJoke(data.joke);
|
||||
.then((games) => {
|
||||
console.log(games.ActiveGames.length);
|
||||
console.log("games: " +games.ActiveGames);
|
||||
setActiveGames(games.ActiveGames);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err.message);
|
||||
@ -21,7 +22,7 @@ function App() {
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<p>
|
||||
Here is your joke: {joke ? <span>{joke}</span> : <span>Loading...</span>}
|
||||
Here is list of your active games: {activeGames ? <span>{activeGames}</span> : <span>Loading...</span>}
|
||||
</p>
|
||||
</header>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user