DeadboltHandler
구현 내에서 onAuthFailure
메서드는 getSubject
을 사용하여 현재 사용자와이를 통해 사용자가 보유한 역할을 얻을 수 있습니다.
public class MyDeadboltHandler implements DeadboltHandler {
private final DeadboltExecutionContextProvider executionContextProvider;
private final DeadboltAnalyzer analyzer;
@Inject
public MyDeadboltHandler(final ExecutionContextProvider ecProvider,
final DeadboltAnalyzer analyzer) {
this.executionContextProvider = ecProvider.get();
this.analyzer =analyzer;
}
public CompletionStage<Result> onAuthFailure(Http.Context context,
Optional<String> content) {
final ExecutionContext executionContext = executionContextProvider.get();
final ExecutionContextExecutor executor = HttpExecution.fromThread(executionContext);
return getSubject(context).thenApplyAsync(maybeSubject ->
maybeSubject.map(subject -> analyzer.hasRole(maybeSubject, "admin") ? /*go to admin section*/
: /*go to non-admin section*/)
.orElseGet(() -> /*no user present*/),
executor);
}
// other methods
}
어디에서나 해당 예제에 주석이 있습니다. /*go to admin section*/
Result
으로 교체해야합니다.
DeadboltAnalyzer
에는 다른 방법이 있으므로, 필요한 경우 analyzer.hasRole(maybeSubject, "admin")
보다 복잡한 검사를 할 수 있습니다.
코드를 보내 주셔서 감사합니다.하지만 람다 표현식과 동시 처리에 익숙하지 않아서'/ * 관리자 섹션 * /'을 Result로 바꾸면 괜찮습니다. 그러나'/ * 사용자가 없습니다 * /' 결과, 오류로 바꿉니다. 내 바보 미안해. –