Skip to content

Commit 8860b29

Browse files
ambrusadrianzKevinGilmore
authored andcommitted
Further simplified the vote method. (eugenp#768)
1 parent d97ba21 commit 8860b29

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

‎spring-security-custom-voter/src/main/java/org/baeldung/security/MinuteBasedVoter.java‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@ public boolean supports(Class clazz) {
2121

2222
@Override
2323
public int vote(Authentication authentication, Object object, Collection collection) {
24-
String role = authentication
24+
return authentication
2525
.getAuthorities()
26-
.stream().map(GrantedAuthority::getAuthority)
27-
.filter("ROLE_USER"::equals)
26+
.stream()
27+
.map(GrantedAuthority::getAuthority)
28+
.filter(r -> "ROLE_USER".equals(r) && LocalDateTime.now().getMinute() % 2 != 0)
2829
.findAny()
29-
.orElseGet(() -> "ROLE_ADMIN");
30-
31-
if ("ROLE_USER".equals(role) && LocalDateTime.now().getMinute() % 2 != 0) {
32-
return ACCESS_DENIED;
33-
}
34-
35-
return ACCESS_ABSTAIN;
30+
.map(s -> ACCESS_DENIED)
31+
.orElseGet(() -> ACCESS_ABSTAIN);
3632
}
3733
}

0 commit comments

Comments
 (0)