Rev 2018 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2009 | es | 1 | package pt.estgp.es.exemplos.hibernate.web; |
2 | |||
2018 | es | 3 | import org.apache.log4j.Logger; |
2009 | es | 4 | import pt.estgp.es.exemplos.hibernate.UserSession; |
2018 | es | 5 | import pt.estgp.es.exemplos.hibernate.web.pluginSession.PluginFactory; |
6 | import pt.estgp.es.exemplos.hibernate.web.pluginSession.RegisterSession; |
||
2009 | es | 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 { |
||
2018 | es | 13 | |
14 | |||
2009 | es | 15 | |
2049 | es | 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); |
2009 | es | 17 | |
2049 | es | 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 { |
||
2009 | es | 21 | |
2049 | es | 22 | } |
2009 | es | 23 | |
2049 | es | 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 | } |
||
2009 | es | 30 | |
31 | |||
2049 | es | 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 | } |
||
2009 | es | 55 | } |