}
private RestrictionResult checkRolesRestriction(Profile profile,
RolesRestriction restriction, OnAccessDenial onMethodAccessDenial,
OnAccessDenial onResourceAccessDenial) {
RestrictionResult restrictionResult = new RestrictionResult();
List<Role> roles = restriction.getRoles();
if (roles.size() == 0){
throw new RestrictionAnnotationException("You must specify the roles in the 'roles' attribute within the @Roles annotation.");
}
switch (restriction.getPolicy()){
case CONJUNCTION:
if (!profile.getRoles().containsAll(restriction.getRolesAsStrings())){
restrictionResult.setRestricted();
restrictionResult.setRestrictionReason(RestrictionReason.ROLE_NOT_PLAYED_BY_USER);
restrictionResult.setDestination(this.getDestination(onMethodAccessDenial, onResourceAccessDenial));
restrictionResult.setHttp403(this.isHttp403(onMethodAccessDenial, onResourceAccessDenial));
}
break;
case DISJUNCTION:
boolean hasRole = false;
for (Role role : roles){
if (profile.getRoles().contains(role.getRole())){
hasRole = true;
break;
}
}
if (!hasRole){
restrictionResult.setRestricted();
restrictionResult.setRestrictionReason(RestrictionReason.ROLE_NOT_PLAYED_BY_USER);
restrictionResult.setDestination(this.getDestination(onMethodAccessDenial, onResourceAccessDenial));
restrictionResult.setHttp403(this.isHttp403(onMethodAccessDenial, onResourceAccessDenial));
}
break;
}
return restrictionResult;
}