// Get remote user name set by web container
String userName = context.getRequest().getRemoteUser();
if ( userName == null )
{
if (ntlmAuthRequired){
throw new PipelineException("Authorization failed.");
} else if (context.getRequest().getUserPrincipal() != null){
userName = context.getRequest().getUserPrincipal().getName();
}
} else {
if (omitDomain && networkDomain != null){
userName = StringUtils.stripStart( userName , networkDomain+"\\");
}
}
// check whether principal name stored in session subject equals the remote user name passed by the web container
if (subject != null)
{
Principal subjectUserPrincipal = SubjectHelper.getPrincipal(subject, User.class);
if ((subjectUserPrincipal == null) || !subjectUserPrincipal.getName().equals(userName))
{
subject = null;
}
}
if ( subject == null ){
if (userName != null){
try
{
User user = userMgr.getUser(userName);
if ( user != null )
{
subject = userMgr.getSubject(user);
}
} catch (SecurityException sex)
{
subject = null;
}
if (subject == null && this.ntlmAuthRequired){
throw new PipelineException("Authorization failed for user '"+userName+"'.");
}
}
if (subject == null){
// create anonymous user
subject = userMgr.getSubject(userMgr.getUser(userMgr.getAnonymousUser()));