Further simplified the vote method. (#768)
This commit is contained in:
parent
d97ba21fb3
commit
8860b29131
@ -21,17 +21,13 @@ public class MinuteBasedVoter implements AccessDecisionVoter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int vote(Authentication authentication, Object object, Collection collection) {
|
public int vote(Authentication authentication, Object object, Collection collection) {
|
||||||
String role = authentication
|
return authentication
|
||||||
.getAuthorities()
|
.getAuthorities()
|
||||||
.stream().map(GrantedAuthority::getAuthority)
|
.stream()
|
||||||
.filter("ROLE_USER"::equals)
|
.map(GrantedAuthority::getAuthority)
|
||||||
|
.filter(r -> "ROLE_USER".equals(r) && LocalDateTime.now().getMinute() % 2 != 0)
|
||||||
.findAny()
|
.findAny()
|
||||||
.orElseGet(() -> "ROLE_ADMIN");
|
.map(s -> ACCESS_DENIED)
|
||||||
|
.orElseGet(() -> ACCESS_ABSTAIN);
|
||||||
if ("ROLE_USER".equals(role) && LocalDateTime.now().getMinute() % 2 != 0) {
|
|
||||||
return ACCESS_DENIED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ACCESS_ABSTAIN;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user