Principal principal = (Principal) invocation.getMetaData("security", "principal");
Object credential = invocation.getMetaData("security", "credential");
if (principal == null)
{
principal = SecurityActions.getPrincipal();
}
if (credential == null)
{
credential = SecurityActions.getCredential();
}
if (authenticationManager == null)
{
SecurityActions.pushSubjectContext(principal, credential, null);
return;
}
// authenticate the current principal
RunAsIdentity callerRunAsIdentity = SecurityActions.peekRunAsIdentity();
if (callerRunAsIdentity == null)
{
// Check the security info from the method invocation
Subject subject = new Subject();
if (authenticationManager.isValid(principal, credential, subject) == false)
{
/* todo support CSIV2 authenticationObserver
// Notify authentication observer
if (authenticationObserver != null)
authenticationObserver.authenticationFailed();
*/
// Check for the security association exception
Exception ex = SecurityActions.getContextException();
if (ex != null)
throw ex;
// Else throw a generic SecurityException
String msg = "Authentication exception, principal=" + principal;
SecurityException e = new SecurityException(msg);
throw e;
}
else
{
SecurityActions.pushSubjectContext(principal, credential, subject);
if (log.isTraceEnabled())
{
log.trace("Authenticated principal=" + principal);
}
}
}