-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
48 changed files
with
630 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
authorization/src/main/java/eu/solven/kumite/account/JwtUserContextHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package eu.solven.kumite.account; | ||
|
||
import java.util.UUID; | ||
|
||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.ReactiveSecurityContextHolder; | ||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; | ||
|
||
import eu.solven.kumite.security.LoginRouteButNotAuthenticatedException; | ||
import reactor.core.publisher.Mono; | ||
|
||
public class JwtUserContextHolder implements IKumiteUserContextHolder { | ||
|
||
@Override | ||
public Mono<UUID> authenticatedAccountId() { | ||
return ReactiveSecurityContextHolder.getContext().map(securityContext -> { | ||
Authentication authentication = securityContext.getAuthentication(); | ||
|
||
if (authentication instanceof JwtAuthenticationToken jwtAuth) { | ||
UUID accountId = UUID.fromString(jwtAuth.getToken().getSubject()); | ||
|
||
return accountId; | ||
} else { | ||
throw new LoginRouteButNotAuthenticatedException("Expecting a JWT token"); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
js/src/main/resources/static/ui/js/kumite-contest-delete.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { ref, onMounted, onUnmounted } from "vue"; | ||
|
||
import { mapState } from "pinia"; | ||
import { useKumiteStore } from "./store.js"; | ||
|
||
export default { | ||
props: { | ||
contestId: { | ||
type: String, | ||
required: true, | ||
}, | ||
gameId: { | ||
type: String, | ||
required: true, | ||
}, | ||
}, | ||
computed: { | ||
...mapState(useKumiteStore, ["nbGameFetching", "nbContestFetching"]), | ||
...mapState(useKumiteStore, { | ||
game(store) { | ||
return store.games[this.gameId]; | ||
}, | ||
contest(store) { | ||
return store.contests[this.contestId]; | ||
}, | ||
}), | ||
}, | ||
setup(props) { | ||
const store = useKumiteStore(); | ||
|
||
store.loadContestIfMissing(props.gameId, props.contestId); | ||
|
||
return {}; | ||
}, | ||
template: /* HTML */ ` | ||
<button class="btn btn-danger">Archive this contest (force gameOver)</button> | ||
`, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
public/src/main/java/eu/solven/kumite/account/fake_player/RandomPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package eu.solven.kumite.account.fake_player; | ||
|
||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
import eu.solven.kumite.account.KumiteUser; | ||
import eu.solven.kumite.account.KumiteUserRaw; | ||
import eu.solven.kumite.account.KumiteUserRawRaw; | ||
import eu.solven.kumite.player.KumitePlayer; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* Various tools specific to the RandomPlayer. This player is useful to generate activity even for a PRD contest-server, | ||
* circumventing the need for an actual login flow, with an external login provider. | ||
* | ||
* @author Benoit Lacelle | ||
* | ||
*/ | ||
@Slf4j | ||
public class RandomPlayer { | ||
|
||
public static final UUID ACCOUNT_ID = UUID.fromString("FFFFFFFF-FFFF-FFFF-FFFF-000000000000"); | ||
public static final UUID PLAYERID_1 = UUID.fromString("FFFFFFFF-FFFF-FFFF-FFFF-111111111111"); | ||
public static final UUID RANDOM_PLAYERID2 = UUID.fromString("FFFFFFFF-FFFF-FFFF-FFFF-222222222222"); | ||
|
||
public static UUID randomPlayerId(int playerIndex) { | ||
if (playerIndex == 0) { | ||
return PLAYERID_1; | ||
} else if (playerIndex == 1) { | ||
return RANDOM_PLAYERID2; | ||
} else { | ||
throw new IllegalArgumentException("There is no randomPlayer for playerIndex=" + playerIndex); | ||
} | ||
} | ||
|
||
public static boolean isRandomPlayer(UUID playerId) { | ||
if (PLAYERID_1.equals(playerId) || RANDOM_PLAYERID2.equals(playerId)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public static KumiteUser user() { | ||
KumiteUserRawRaw rawRaw = KumiteUserRawRaw.builder().providerId("kumite").sub("randomSub").build(); | ||
KumiteUserRaw raw = KumiteUserRaw.builder() | ||
.rawRaw(rawRaw) | ||
.username("randomUsername") | ||
.email("random@random") | ||
.name("Random User") | ||
.build(); | ||
return KumiteUser.builder().accountId(ACCOUNT_ID).playerId(PLAYERID_1).raw(raw).build(); | ||
} | ||
|
||
public static KumitePlayer randomPlayer() { | ||
return KumitePlayer.builder().playerId(PLAYERID_1).accountId(ACCOUNT_ID).build(); | ||
} | ||
|
||
public static KumitePlayer randomPlayer(int i) { | ||
return KumitePlayer.builder().playerId(randomPlayerId(i)).accountId(ACCOUNT_ID).build(); | ||
} | ||
|
||
public static Set<UUID> randomPlayers() { | ||
return Set.of(RandomPlayer.PLAYERID_1, RandomPlayer.RANDOM_PLAYERID2); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
server/src/main/java/eu/solven/kumite/app/InjectKumiteAccountsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package eu.solven.kumite.app; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
import eu.solven.kumite.account.KumiteUsersRegistry; | ||
import eu.solven.kumite.account.fake_player.FakePlayer; | ||
import eu.solven.kumite.account.fake_player.RandomPlayer; | ||
import eu.solven.kumite.player.IAccountPlayersRegistry; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Configuration | ||
@Slf4j | ||
public class InjectKumiteAccountsConfig { | ||
|
||
@Profile(IKumiteSpringProfiles.P_FAKEUSER) | ||
@Bean | ||
public Void initFakePlayer(KumiteUsersRegistry usersRegistry, IAccountPlayersRegistry accountPlayersRegistry) { | ||
log.info("Registering the {} account and players", IKumiteSpringProfiles.P_FAKEUSER); | ||
|
||
usersRegistry.registerOrUpdate(FakePlayer.user().getRaw()); | ||
accountPlayersRegistry.registerPlayer(FakePlayer.fakePlayer(1)); | ||
|
||
return null; | ||
} | ||
|
||
@Bean | ||
public Void initRandomPlayer(KumiteUsersRegistry usersRegistry, IAccountPlayersRegistry accountPlayersRegistry) { | ||
log.info("Registering the random account and players"); | ||
|
||
usersRegistry.registerOrUpdate(RandomPlayer.user().getRaw()); | ||
accountPlayersRegistry.registerPlayer(RandomPlayer.randomPlayer(1)); | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
server/src/test/java/eu/solven/kumite/app/it/security/TestSecurity_WithFakeUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package eu.solven.kumite.app.it.security; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Map; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
import eu.solven.kumite.account.fake_player.FakePlayer; | ||
import eu.solven.kumite.app.IKumiteSpringProfiles; | ||
import eu.solven.kumite.app.KumiteJackson; | ||
import eu.solven.kumite.app.webflux.api.KumiteLoginController; | ||
import eu.solven.kumite.login.AccessTokenWrapper; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* OAuth2 enables logging-in a subset of APIs, especially the login APIs. | ||
* | ||
* @author Benoit Lacelle | ||
* | ||
*/ | ||
@ExtendWith(SpringExtension.class) | ||
@ActiveProfiles({ IKumiteSpringProfiles.P_UNSAFE, IKumiteSpringProfiles.P_FAKEUSER }) | ||
@Slf4j | ||
public class TestSecurity_WithFakeUser extends TestSecurity_WithOAuth2User { | ||
|
||
@Test | ||
@Override | ||
public void testLoginAccessToken() { | ||
log.debug("About {}", KumiteLoginController.class); | ||
|
||
webTestClient | ||
|
||
.get() | ||
.uri("/api/login/v1/oauth2/token") | ||
.accept(MediaType.APPLICATION_JSON) | ||
.header(HttpHeaders.AUTHORIZATION, | ||
"Basic " + HttpHeaders.encodeBasicAuth(FakePlayer.ACCOUNT_ID.toString(), | ||
"no_password", | ||
StandardCharsets.UTF_8)) | ||
.exchange() | ||
|
||
.expectStatus() | ||
.isOk() | ||
.expectBody(AccessTokenWrapper.class) | ||
.value(token -> { | ||
Map asMap = KumiteJackson.objectMapper().convertValue(token, Map.class); | ||
|
||
Assertions.assertThat(asMap) | ||
.containsKey("access_token") | ||
.containsEntry("token_type", "Bearer") | ||
.containsEntry("player_id", FakePlayer.PLAYER_ID1.toString()) | ||
.containsEntry("expires_in", 3600L) | ||
.hasSize(4); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testLoginAccessToken_invalidUser() { | ||
log.debug("About {}", KumiteLoginController.class); | ||
|
||
webTestClient | ||
|
||
.get() | ||
.uri("/api/login/v1/oauth2/token") | ||
.accept(MediaType.APPLICATION_JSON) | ||
.header(HttpHeaders.AUTHORIZATION, | ||
"Basic " + HttpHeaders | ||
.encodeBasicAuth("someUnknownUser", "no_password", StandardCharsets.UTF_8)) | ||
.exchange() | ||
|
||
.expectStatus() | ||
.isUnauthorized(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tools/src/main/java/eu/solven/kumite/account/IKumiteUserContextHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package eu.solven.kumite.account; | ||
|
||
import java.util.UUID; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
/** | ||
* Give access to the authenticated user. | ||
* | ||
* @author Benoit Lacelle | ||
* | ||
*/ | ||
public interface IKumiteUserContextHolder { | ||
Mono<UUID> authenticatedAccountId(); | ||
} |