Further simplified the vote method. (#768)

This commit is contained in:
ambrusadrianz 2016-10-23 22:33:17 +03:00 committed by KevinGilmore
parent d97ba21fb3
commit 8860b29131
1 changed files with 6 additions and 10 deletions

View File

@ -21,17 +21,13 @@ public class MinuteBasedVoter implements AccessDecisionVoter {
@Override
public int vote(Authentication authentication, Object object, Collection collection) {
String role = authentication
return authentication
.getAuthorities()
.stream().map(GrantedAuthority::getAuthority)
.filter("ROLE_USER"::equals)
.stream()
.map(GrantedAuthority::getAuthority)
.filter(r -> "ROLE_USER".equals(r) && LocalDateTime.now().getMinute() % 2 != 0)
.findAny()
.orElseGet(() -> "ROLE_ADMIN");
if ("ROLE_USER".equals(role) && LocalDateTime.now().getMinute() % 2 != 0) {
return ACCESS_DENIED;
}
return ACCESS_ABSTAIN;
.map(s -> ACCESS_DENIED)
.orElseGet(() -> ACCESS_ABSTAIN);
}
}