@Test public void isNOTAllowedToAccess() { CoffeeNetApp coffeeNetApp = getAppWithRoles(asList("ROLE_ADMIN", "ROLE_SUPER_ADMIN")); boolean allowedToAccess = coffeeNetApp.isAllowedToAccessBy(new HashSet<>(asList("ROLE_USER", "ROLE_EMPLOYEE"))); assertThat(allowedToAccess, is(false)); }
public boolean isAllowedToAccessBy(Set<String> userAuthorities) { if (authorities == null || authorities.isEmpty()) { return true; } Set<String> userAuthoritiesNN = userAuthorities; if (userAuthorities == null) { userAuthoritiesNN = emptySet(); } boolean isAllowed = false; for (String allowedAuthority : this.authorities) { for (String authority : userAuthoritiesNN) { if (allowedAuthority.equalsIgnoreCase(authority)) { isAllowed = true; break; } } } return isAllowed; }
CoffeeNetApp { public boolean isAllowedToAccessBy(Set<String> userAuthorities) { if (authorities == null || authorities.isEmpty()) { return true; } Set<String> userAuthoritiesNN = userAuthorities; if (userAuthorities == null) { userAuthoritiesNN = emptySet(); } boolean isAllowed = false; for (String allowedAuthority : this.authorities) { for (String authority : userAuthoritiesNN) { if (allowedAuthority.equalsIgnoreCase(authority)) { isAllowed = true; break; } } } return isAllowed; } }
CoffeeNetApp { public boolean isAllowedToAccessBy(Set<String> userAuthorities) { if (authorities == null || authorities.isEmpty()) { return true; } Set<String> userAuthoritiesNN = userAuthorities; if (userAuthorities == null) { userAuthoritiesNN = emptySet(); } boolean isAllowed = false; for (String allowedAuthority : this.authorities) { for (String authority : userAuthoritiesNN) { if (allowedAuthority.equalsIgnoreCase(authority)) { isAllowed = true; break; } } } return isAllowed; } CoffeeNetApp(String name, String url, Set<String> authorities); }
CoffeeNetApp { public boolean isAllowedToAccessBy(Set<String> userAuthorities) { if (authorities == null || authorities.isEmpty()) { return true; } Set<String> userAuthoritiesNN = userAuthorities; if (userAuthorities == null) { userAuthoritiesNN = emptySet(); } boolean isAllowed = false; for (String allowedAuthority : this.authorities) { for (String authority : userAuthoritiesNN) { if (allowedAuthority.equalsIgnoreCase(authority)) { isAllowed = true; break; } } } return isAllowed; } CoffeeNetApp(String name, String url, Set<String> authorities); String getName(); String getUrl(); Set<String> getAuthorities(); boolean isAllowedToAccessBy(Set<String> userAuthorities); }
CoffeeNetApp { public boolean isAllowedToAccessBy(Set<String> userAuthorities) { if (authorities == null || authorities.isEmpty()) { return true; } Set<String> userAuthoritiesNN = userAuthorities; if (userAuthorities == null) { userAuthoritiesNN = emptySet(); } boolean isAllowed = false; for (String allowedAuthority : this.authorities) { for (String authority : userAuthoritiesNN) { if (allowedAuthority.equalsIgnoreCase(authority)) { isAllowed = true; break; } } } return isAllowed; } CoffeeNetApp(String name, String url, Set<String> authorities); String getName(); String getUrl(); Set<String> getAuthorities(); boolean isAllowedToAccessBy(Set<String> userAuthorities);  }