{
// Security context
org.jboss.security.SecurityContext sc = null;
// Setup callbacks
CallbackHandler cbh = new JASPICallbackHandler();
// Subjects for execution environment
Subject executionSubject = null;
Subject serviceSubject = null;
if (trace)
log.tracef("Callback security: %s", workManager.getCallbackSecurity());
if (SecurityContextAssociation.getSecurityContext() == null ||
workManager.getCallbackSecurity().getDomain() != null)
{
String scDomain = workManager.getCallbackSecurity().getDomain();
if (trace)
log.tracef("Creating security context: %s", scDomain);
if (scDomain == null || scDomain.trim().equals(""))
{
fireWorkContextSetupFailed(securityContext);
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);