Session session = null;
// Get the request caller which could be set due to SSO
Principal caller = request.getPrincipal();
// The cached web container principal
JBossGenericPrincipal principal = null;
HttpSession hsession = request.getSession(false);
boolean createdSecurityContext = false;
SecurityContext sc = SecurityActions.getSecurityContext();
if (sc == null) {
createdSecurityContext = true;
String securityDomain = SecurityUtil.unprefixSecurityDomain(contextSecurityDomain);
if (securityDomain == null)
securityDomain = SecurityConstants.DEFAULT_WEB_APPLICATION_POLICY;
sc = SecurityActions.createSecurityContext(securityDomain);
SecurityActions.setSecurityContextOnAssociation(sc);
}
try {
Wrapper servlet = null;
try {
servlet = request.getWrapper();
if (servlet != null) {
String name = servlet.getName();
RunAsIdentity runAsIdentity = null;
SecurityActions.pushRunAsIdentity(runAsIdentity);
}
// If there is a session, get the tomcat session for the principal
Manager manager = container.getManager();
if (manager != null && hsession != null) {
try {
session = manager.findSession(hsession.getId());
} catch (IOException ignore) {
}
}
if (caller == null || !(caller instanceof JBossGenericPrincipal)) {
// Look to the session for the active caller security context
if (session != null) {
principal = (JBossGenericPrincipal) session.getPrincipal();
}
if (principal == null) {
Session sessionInternal = request.getSessionInternal(false);
if (sessionInternal != null) {
principal = (JBossGenericPrincipal) sessionInternal.getNote(Constants.FORM_PRINCIPAL_NOTE);
}
}
} else {
// Use the request principal as the caller identity
principal = (JBossGenericPrincipal) caller;
}
// If there is a caller use this as the identity to propagate
if (principal != null) {
if (createdSecurityContext) {
sc.getUtil().createSubjectInfo(principal.getUserPrincipal(), principal.getCredentials(),
principal.getSubject());
}
}
} catch (Throwable e) {
ROOT_LOGGER.failedToDetermineServlet(e);
}