log.tracef("Creating security context: %s", scDomain);
if (scDomain == null || scDomain.trim().equals(""))
{
fireWorkContextSetupFailed(ctx);
throw new WorkException(bundle.securityContextSetupFailedSinceCallbackSecurityDomainWasEmpty());
}
sc = SecurityContextFactory.createSecurityContext(scDomain);
SecurityContextAssociation.setSecurityContext(sc);
}
else
{
sc = SecurityContextAssociation.getSecurityContext();
if (trace)
log.tracef("Using security context: %s", sc);
}
executionSubject = sc.getSubjectInfo().getAuthenticatedSubject();
if (executionSubject == null)
{
if (trace)
log.tracef("Creating empty subject");
executionSubject = new Subject();
}
// Resource adapter callback
securityContext.setupSecurityContext(cbh, executionSubject, serviceSubject);
List<Callback> callbacks = new ArrayList<Callback>();
if (workManager.getCallbackSecurity().isMappingRequired())
{
// JCA 1.6: 16.4.4
}
if (workManager.getCallbackSecurity().getDefaultPrincipal() != null)
{
Principal defaultPrincipal = workManager.getCallbackSecurity().getDefaultPrincipal();
CallerPrincipalCallback cpc =
new CallerPrincipalCallback(executionSubject, defaultPrincipal);
callbacks.add(cpc);
}
if (workManager.getCallbackSecurity().getDefaultGroups() != null)
{
String[] defaultGroups = workManager.getCallbackSecurity().getDefaultGroups();
GroupPrincipalCallback gpc =
new GroupPrincipalCallback(executionSubject, defaultGroups);
callbacks.add(gpc);
}
if (callbacks.size() > 0)
{
Callback[] cb = new Callback[callbacks.size()];
cbh.handle(callbacks.toArray(cb));
}
if (trace)
log.tracef("Setting authenticated subject (%s) on security context (%s)", executionSubject, sc);
// Set the authenticated subject
sc.getSubjectInfo().setAuthenticatedSubject(executionSubject);
}
catch (Throwable t)
{
log.securityContextSetupFailed(t.getMessage(), t);
fireWorkContextSetupFailed(ctx);
throw new WorkException(bundle.securityContextSetupFailed(t.getMessage()), t);
}
}
else if (securityContext != null && workManager.getCallbackSecurity() == null)
{
log.securityContextSetupFailedCallbackSecurityNull();
fireWorkContextSetupFailed(ctx);
throw new WorkException(bundle.securityContextSetupFailedSinceCallbackSecurityWasNull());
}
//Fires Context setup complete
fireWorkContextSetupComplete(ctx);