{
}
public void doFilter(ServletRequest sRequest, ServletResponse sResponse, FilterChain filterChain) throws IOException, ServletException
{
ComponentManager cm = Jetspeed.getComponentManager();
AuthenticationProvider authProvider = (AuthenticationProvider) cm.getComponent("org.apache.jetspeed.security.AuthenticationProvider");
if (sRequest instanceof HttpServletRequest)
{
HttpServletRequest request = (HttpServletRequest) sRequest;
HttpSession httpSession = PortalSessionValidationFilter.getValidSession(request);
if (userNameHeader == null)
{
synchronized (sem)
{
ShibbolethConfiguration config = (ShibbolethConfiguration) cm.getComponent(
"org.apache.jetspeed.security.shibboleth.ShibbolethConfiguration");
userNameHeader = config.getHeaderMapping().get(ShibbolethConfiguration.USERNAME);
}
}
String username = request.getHeader(userNameHeader);
if (username != null)
{
Subject subject = (Subject) request.getSession().getAttribute(PortalReservedParameters.SESSION_KEY_SUBJECT);
if (subject != null)
{
Principal principal = SubjectHelper.getPrincipal(subject, UserSubjectPrincipal.class);
if (principal != null)
{
if (principal.getName().equals(username))
{
sRequest = wrapperRequest(request, subject, principal);
if (filterChain != null)
{
filterChain.doFilter(sRequest, sResponse);
return;
}
}
}
}
UserManager userManager = (UserManager) cm.getComponent("org.apache.jetspeed.security.UserManager");
AuditActivity audit = (AuditActivity) cm.getComponent("org.apache.jetspeed.audit.AuditActivity");
ShibbolethConfiguration config = (ShibbolethConfiguration) cm.getComponent(
"org.apache.jetspeed.security.shibboleth.ShibbolethConfiguration");
boolean success = false;
if (config.isAuthenticate())
{
try
{
authProvider.authenticate(username, username);
success = true;
}
catch (SecurityException e)
{
throw new ServletException();
}
}
else
{
try
{
// load the user principals (roles, groups, credentials)
User user = userManager.getUser(username);
if (user != null)
{
subject = userManager.getSubject(user);
}
success = true;
}
catch (SecurityException sex)
{
success = false;
}
}
if (success)
{
audit.logUserActivity(username, request.getRemoteAddr(), AuditActivity.AUTHENTICATION_SUCCESS, "ShibbolethFilter");
PortalAuthenticationConfiguration authenticationConfiguration = (PortalAuthenticationConfiguration)
cm.getComponent("org.apache.jetspeed.administration.PortalAuthenticationConfiguration");
if (authenticationConfiguration.isCreateNewSessionOnLogin() && httpSession != null && !httpSession.isNew())
{
request.getSession().invalidate();
}
else
{
UserContentCacheManager userContentCacheManager = (UserContentCacheManager)cm.getComponent("userContentCacheManager");
userContentCacheManager.evictUserContentCache(username, request.getSession().getId());
}
subject = null;
try
{