Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2001 | es | 1 | package pt.estgp.es.exemplos.hibernate.web; |
2 | |||
3 | import org.apache.log4j.Logger; |
||
4 | import pt.estgp.es.exemplos.hibernate.UserSession; |
||
5 | import pt.estgp.es.exemplos.hibernate.web.pluginSession.PluginFactory; |
||
6 | import pt.estgp.es.exemplos.hibernate.web.pluginSession.RegisterSession; |
||
7 | |||
8 | import javax.servlet.*; |
||
9 | import javax.servlet.http.HttpServletResponse; |
||
10 | import java.io.IOException; |
||
11 | |||
12 | public class SecurityFilter implements 1.5.0/docs/api/java/util/logging/Filter.html">Filter { |
||
13 | |||
14 | |||
15 | |||
16 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(SecurityFilter.class); |
||
17 | |||
18 | private static final 1.5.0/docs/api/java/lang/String.html">String SESSION_IN_REQUEST_KEY = "UserSession"; |
||
19 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
20 | public void init(FilterConfig filterConfig) throws ServletException { |
||
21 | |||
22 | } |
||
23 | |||
24 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
25 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws 1.5.0/docs/api/java/io/IOException.html">IOException, ServletException { |
||
26 | HttpServletResponse response = (HttpServletResponse) servletResponse; |
||
27 | loadSessionProxy(servletRequest); |
||
28 | filterChain.doFilter(servletRequest, response); |
||
29 | } |
||
30 | |||
31 | |||
32 | |||
33 | public static UserSession loadSessionProxy(ServletRequest servletRequest) throws 1.5.0/docs/api/java/io/IOException.html">IOException, ServletException { |
||
34 | |||
35 | UserSession session = (UserSession) servletRequest.getAttribute(SESSION_IN_REQUEST_KEY); |
||
36 | |||
37 | try { |
||
38 | if(session == null) { |
||
39 | RegisterSession plugin; |
||
40 | plugin = (RegisterSession) PluginFactory.getPlugin(RegisterSession.class); |
||
41 | session = plugin.openSession(servletRequest); |
||
42 | servletRequest.setAttribute(SESSION_IN_REQUEST_KEY,session); |
||
43 | } |
||
44 | } catch (1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException | 1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException | 1.5.0/docs/api/java/lang/InstantiationException.html">InstantiationException e) { |
||
45 | logger.error(e,e); |
||
46 | return null; |
||
47 | } |
||
48 | return session; |
||
49 | } |
||
50 | |||
51 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
52 | public void destroy() { |
||
53 | |||
54 | } |
||
55 | } |