Skip to content

Commit aa5ad19

Browse files
committed
make GameAuthorizationRule high priority to make sure it isn't overshadowed by normal auth
1 parent 6f7cd9f commit aa5ad19

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/main/java/org/developerden/codosseum/auth/GameAuthorizationRule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ protected GameAuthorizationRule(RolesFinder rolesFinder) {
3535
super(rolesFinder);
3636
}
3737

38+
@Override
39+
public int getOrder() {
40+
return Integer.MIN_VALUE + 100;
41+
}
42+
3843
@Override
3944
public Publisher<SecurityRuleResult> check(@Nullable HttpRequest<?> request,
4045
@Nullable Authentication authentication) {
@@ -64,6 +69,8 @@ public Publisher<SecurityRuleResult> check(@Nullable HttpRequest<?> request,
6469
}
6570

6671
private boolean matchesGameId(Authentication authentication, String gameId) {
67-
return gameId.equals(authentication.getAttributes().get("activeGameId"));
72+
return gameId.equals(
73+
String.valueOf(authentication.getAttributes().get(PlayerAuthentication.ACTIVE_GAME_ID))
74+
);
6875
}
6976
}

src/main/java/org/developerden/codosseum/auth/GameAuthorized.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
import java.lang.annotation.RetentionPolicy;
2020
import java.lang.annotation.Target;
2121

22+
/**
23+
* Annotation to specify that a route requires the user to have one of the specified roles in a game.
24+
* If the user does not have one of the specified roles, a 403 Forbidden response will be returned.
25+
*
26+
*/
2227
@Retention(RetentionPolicy.RUNTIME)
2328
@Target(ElementType.METHOD)
2429
public @interface GameAuthorized {

src/main/java/org/developerden/codosseum/controller/UserController.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import io.micronaut.security.rules.SecurityRule;
2323
import io.micronaut.validation.Validated;
2424
import jakarta.inject.Inject;
25-
import org.developerden.codosseum.auth.GameAuthorized;
26-
import org.developerden.codosseum.auth.GameRole;
2725
import org.developerden.codosseum.dto.PlayersMapper;
2826
import org.developerden.codosseum.dto.user.User;
2927
import org.developerden.codosseum.model.player.UserMapper;
@@ -50,7 +48,6 @@ public class UserController {
5048
}
5149

5250
@Get("/@self")
53-
@GameAuthorized(GameRole.PLAYER)
5451
public HttpResponse<User> getSelf(Authentication principal) {
5552
return authService.getUserInfoFromAuth(principal)
5653
.map(userMapper::toDto)

0 commit comments

Comments
 (0)