public boolean isCallerInRole(final String... roleNames) {
final SecurityContext securityContext = doPrivileged(securityContext());
if (securityContext == null)
throw new IllegalStateException("No security context established");
RoleGroup roleGroup = null;
RunAs runAs = securityContext.getIncomingRunAs();
if (runAs != null && runAs instanceof RunAsIdentity) {
RunAsIdentity runAsIdentity = (RunAsIdentity) runAs;
roleGroup = runAsIdentity.getRunAsRolesAsRoleGroup();
} else {
AuthorizationManager am = securityContext.getAuthorizationManager();
SecurityContextCallbackHandler scb = new SecurityContextCallbackHandler(securityContext);
roleGroup = am.getSubjectRoles(securityContext.getSubjectInfo().getAuthenticatedSubject(), scb);
}
List<Role> roles = roleGroup.getRoles();
// TODO - Review most performant way.
Set<String> requiredRoles = new HashSet<String>();
for (String current : roleNames) {
requiredRoles.add(current);