Created
October 23, 2019 13:41
-
-
Save digimon1740/421de234b9d47a9b18473fc8705de29f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 액세스 매니저 설정 | |
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