Author: shane.bryzak(a)jboss.com
Date: 2010-07-16 17:51:51 -0400 (Fri, 16 Jul 2010)
New Revision: 13414
Modified:
branches/community/Seam_2_2/src/main/org/jboss/seam/web/AuthenticationFilter.java
Log:
wrap ContextualHttpServletRequest around all filter processing
Modified:
branches/community/Seam_2_2/src/main/org/jboss/seam/web/AuthenticationFilter.java
===================================================================
---
branches/community/Seam_2_2/src/main/org/jboss/seam/web/AuthenticationFilter.java 2010-07-16
16:24:51 UTC (rev 13413)
+++
branches/community/Seam_2_2/src/main/org/jboss/seam/web/AuthenticationFilter.java 2010-07-16
21:51:51 UTC (rev 13414)
@@ -103,7 +103,7 @@
this.nonceValiditySeconds = value;
}
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain)
+ public void doFilter(ServletRequest request, ServletResponse response, final
FilterChain chain)
throws IOException, ServletException
{
if (!(request instanceof HttpServletRequest))
@@ -111,33 +111,39 @@
throw new ServletException("This filter can only process HttpServletRequest
requests");
}
- HttpServletRequest httpRequest = (HttpServletRequest) request;
- HttpServletResponse httpResponse = (HttpServletResponse) response;
+ final HttpServletRequest httpRequest = (HttpServletRequest) request;
+ final HttpServletResponse httpResponse = (HttpServletResponse) response;
// Force session creation
httpRequest.getSession();
- if (AUTH_TYPE_BASIC.equals(authType))
- processBasicAuth(httpRequest, httpResponse, chain);
- else if (AUTH_TYPE_DIGEST.equals(authType))
- processDigestAuth(httpRequest, httpResponse, chain);
- else
- throw new ServletException("Invalid authentication type");
+ new ContextualHttpServletRequest(httpRequest)
+ {
+ @Override
+ public void process() throws ServletException, IOException, LoginException
+ {
+ if (AUTH_TYPE_BASIC.equals(authType))
+ processBasicAuth(httpRequest, httpResponse, chain);
+ else if (AUTH_TYPE_DIGEST.equals(authType))
+ processDigestAuth(httpRequest, httpResponse, chain);
+ else
+ throw new ServletException("Invalid authentication type");
+ }
+ }.run();
}
private void processBasicAuth(HttpServletRequest request,
HttpServletResponse response, FilterChain chain)
throws IOException, ServletException
{
- Context ctx = new SessionContext( new ServletRequestSessionMap(request) );
- Identity identity = (Identity) ctx.get(Identity.class);
+ Identity identity = Identity.instance();
if (identity == null)
{
throw new ServletException("Identity not found - please ensure that the
Identity component is created on startup.");
}
- Credentials credentials = (Credentials) ctx.get(Credentials.class);
+ Credentials credentials = identity.getCredentials();
boolean requireAuth = false;
@@ -202,15 +208,14 @@
HttpServletResponse response, FilterChain chain)
throws IOException, ServletException
{
- Context ctx = new SessionContext( new ServletRequestSessionMap(request) );
- Identity identity = (Identity) ctx.get(Identity.class);
+ Identity identity = Identity.instance();
if (identity == null)
{
throw new ServletException("Identity not found - please ensure that the
Identity component is created on startup.");
}
- Credentials credentials = (Credentials) ctx.get(Credentials.class);
+ Credentials credentials = identity.getCredentials();
boolean requireAuth = false;
boolean nonceExpired = false;
@@ -227,7 +232,6 @@
String[] vals = split(entry, "=");
headerMap.put(vals[0].trim(), vals[1].replace("\"",
"").trim());
}
-
DigestRequest digestRequest = new DigestRequest();
digestRequest.setHttpMethod(request.getMethod());
@@ -302,18 +306,11 @@
}
private void authenticate(HttpServletRequest request, final String username)
- throws ServletException, IOException
+ throws ServletException, IOException, LoginException
{
- new ContextualHttpServletRequest(request)
- {
- @Override
- public void process() throws ServletException, IOException, LoginException
- {
- Identity identity = Identity.instance();
- identity.getCredentials().setUsername(username);
- identity.authenticate();
- }
- }.run();
+ Identity identity = Identity.instance();
+ identity.getCredentials().setUsername(username);
+ identity.authenticate();
}
private String[] split(String toSplit, String delimiter)