1 package org.jbpm.security.filter; 2 3 import java.io.IOException ; 4 import java.security.Principal ; 5 6 import javax.servlet.Filter ; 7 import javax.servlet.FilterChain ; 8 import javax.servlet.FilterConfig ; 9 import javax.servlet.ServletException ; 10 import javax.servlet.ServletRequest ; 11 import javax.servlet.ServletResponse ; 12 import javax.servlet.http.HttpServletRequest ; 13 14 import org.jbpm.security.Authentication; 15 16 public class JbpmAuthenticationFilter implements Filter { 17 18 public void init(FilterConfig filterConfig) throws ServletException { 19 } 20 21 public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException , ServletException { 22 String actorId = null; 23 24 if (servletRequest instanceof HttpServletRequest ) { 26 HttpServletRequest httpServletRequest = (HttpServletRequest ) servletRequest; 27 Principal userPrincipal = httpServletRequest.getUserPrincipal(); 28 if (userPrincipal != null) { 29 actorId = userPrincipal.getName(); 30 } 31 } 32 33 if (actorId != null) { 35 Authentication.pushAuthenticatedActorId(actorId); 37 try { 38 filterChain.doFilter(servletRequest, servletResponse); 39 } finally { 40 Authentication.popAuthenticatedActorId(); 41 } 42 43 } else { 45 filterChain.doFilter(servletRequest, servletResponse); 46 } 47 } 48 49 public void destroy() { 50 } 51 52 } 53 | Popular Tags |