KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > security > filter > JbpmAuthenticationFilter


1 package org.jbpm.security.filter;
2
3 import java.io.IOException JavaDoc;
4 import java.security.Principal JavaDoc;
5
6 import javax.servlet.Filter JavaDoc;
7 import javax.servlet.FilterChain JavaDoc;
8 import javax.servlet.FilterConfig JavaDoc;
9 import javax.servlet.ServletException JavaDoc;
10 import javax.servlet.ServletRequest JavaDoc;
11 import javax.servlet.ServletResponse JavaDoc;
12 import javax.servlet.http.HttpServletRequest JavaDoc;
13
14 import org.jbpm.security.Authentication;
15
16 public class JbpmAuthenticationFilter implements Filter JavaDoc {
17
18   public void init(FilterConfig JavaDoc filterConfig) throws ServletException JavaDoc {
19   }
20
21   public void doFilter(ServletRequest JavaDoc servletRequest, ServletResponse JavaDoc servletResponse, FilterChain JavaDoc filterChain) throws IOException JavaDoc, ServletException JavaDoc {
22     String JavaDoc actorId = null;
23
24     // see if we can get the authenticated swimlaneActorId
25
if (servletRequest instanceof HttpServletRequest JavaDoc) {
26       HttpServletRequest JavaDoc httpServletRequest = (HttpServletRequest JavaDoc) servletRequest;
27       Principal JavaDoc userPrincipal = httpServletRequest.getUserPrincipal();
28       if (userPrincipal != null) {
29         actorId = userPrincipal.getName();
30       }
31     }
32
33     // if there is an authenticated user
34
if (actorId != null) {
35       // we put the handling of the request in an authenticated block
36
Authentication.pushAuthenticatedActorId(actorId);
37       try {
38         filterChain.doFilter(servletRequest, servletResponse);
39       } finally {
40         Authentication.popAuthenticatedActorId();
41       }
42       
43     // if this request is not authenticated, we proceed without jbpm authentication
44
} else {
45       filterChain.doFilter(servletRequest, servletResponse);
46     }
47   }
48
49   public void destroy() {
50   }
51
52 }
53
Popular Tags