Set<Object> credentials = subject.getPrivateCredentials();
Object credential = !credentials.isEmpty() ? credentials.iterator().next() : null;
org.jboss.security.SecurityContext new_jb_securityContext = SecurityContextFactory.createSecurityContext(securityDomain);
SecurityContextAssociation.setSecurityContext(new_jb_securityContext);
if (rolesGroup != null) {
RoleGroup roleGroup = new SimpleRoleGroup(rolesGroup);
Identity identity = CredentialIdentityFactory.createIdentity(principal, credential, roleGroup);
new_jb_securityContext.getUtil().createSubjectInfo(identity, subject);
new_jb_securityContext.getSubjectInfo().setRoles(roleGroup);
} else {
Identity identity = CredentialIdentityFactory.createIdentity(principal, credential);
new_jb_securityContext.getUtil().createSubjectInfo(identity, subject);
}
if (new_jb_runAs != null) {
new_jb_securityContext.setOutgoingRunAs(new_jb_runAs);
}
return new JBossContainerContext(null, null, null);
} else {
RoleGroup old_jb_roleGroup = old_jb_securityContext.getSubjectInfo().getRoles();
if (rolesGroup != null) {
old_jb_securityContext.getSubjectInfo().setRoles(new SimpleRoleGroup(rolesGroup));
}
RunAs old_jb_runAs = old_jb_securityContext.getOutgoingRunAs();
if (new_jb_runAs != null) {
old_jb_securityContext.setOutgoingRunAs(new_jb_runAs);
}