log.trace("method=" + mi.getMethod() + ", interface=" + iface
+ ", requiredRoles=" + methodRoles);
}
// Check if the caller is allowed to access the method
RunAsIdentity callerRunAsIdentity = SecurityAssociation.peekRunAsIdentity();
if (methodRoles.contains(AnybodyPrincipal.ANYBODY_PRINCIPAL) == false)
{
// The caller is using a the caller identity
if (callerRunAsIdentity == null)
{
// Now actually check if the current caller has one of the required method roles
if (realmMapping.doesUserHaveRole(principal, methodRoles) == false)
{
Set userRoles = realmMapping.getUserRoles(principal);
String method = mi.getMethod().getName();
String msg = "Insufficient method permissions, principal=" + principal
+ ", method=" + method + ", interface=" + iface
+ ", requiredRoles=" + methodRoles + ", principalRoles=" + userRoles;
log.error(msg);
SecurityException e = new SecurityException(msg);
throw new EJBException("checkSecurityAssociation", e);
}
}
// The caller is using a run-as identity
else
{
// Check that the run-as role is in the set of method roles
if (callerRunAsIdentity.doesUserHaveRole(methodRoles) == false)
{
String method = mi.getMethod().getName();
String msg = "Insufficient method permissions, runAsPrincipal=" + callerRunAsIdentity.getName()
+ ", method=" + method + ", interface=" + iface
+ ", requiredRoles=" + methodRoles + ", runAsRoles=" + callerRunAsIdentity.getRunAsRoles();
log.error(msg);
SecurityException e = new SecurityException(msg);
throw new EJBException("checkSecurityAssociation", e);
}
}