Skip to content

Instantly share code, notes, and snippets.

@runeflobakk
Created October 30, 2011 20:24
Show Gist options
  • Save runeflobakk/1326386 to your computer and use it in GitHub Desktop.
Save runeflobakk/1326386 to your computer and use it in GitHub Desktop.
Funksjon for å avgjøre om MyPrincipal sitt sikkerhetsnivå er høyt nok for det som kreves av ConfigAttributes
public class SecurityLevelVoter implements AccessDecisionVoter {
private String securityLevelPrefix = "SECURITY_LEVEL_";
//...snip...
private class AcceptingSecurityLevelOf implements Predicate<ConfigAttribute> {
private final int principalSecurityLevel;
public AcceptingSecurityLevelOf(MyPrincipal principal) {
principalSecurityLevel = toInt(principal.getSecurityLevel(), Integer.MIN_VALUE);
}
@Override
public boolean evaluate(ConfigAttribute attribute) {
String requiredSecurityLevel =
removeStart(attribute.getAttribute(), securityLevelPrefix);
return principalSecurityLevel >= toInt(requiredSecurityLevel, Integer.MAX_VALUE);
}
}
//...snip...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment