Skip to content

Instantly share code, notes, and snippets.

@digimon1740
Created October 23, 2019 13:41
Show Gist options
  • Save digimon1740/421de234b9d47a9b18473fc8705de29f to your computer and use it in GitHub Desktop.
Save digimon1740/421de234b9d47a9b18473fc8705de29f to your computer and use it in GitHub Desktop.
// 액세스 매니저 설정
app.accessManager((handler, ctx, permittedRoles) -> {
MyRole userRole = getUserRole(ctx);
if (permittedRoles.contains(userRole)) {
handler.handle(ctx);
} else {
ctx.status(401).result("Unauthorized");
}
});
Role getUserRole(Context ctx) {
// 요청을 확인하여 유저의 권한을 검증
// 일반적으로 Authorization 헤더를 검사한 뒤 수행함
}
enum MyRole implements Role {
ANYONE, ROLE_ONE, ROLE_TWO, ROLE_THREE;
}
app.routes(() -> {
get("/un-secured", ctx -> ctx.result("Hello"), roles(ANYONE));
get("/secured", ctx -> ctx.result("Hello"), roles(ROLE_ONE));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment