Rev 2009 | Rev 2049 | 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.HibernateUtils; |
5 | import pt.estgp.es.exemplos.hibernate.UserSession; |
||
2018 | es | 6 | import pt.estgp.es.exemplos.hibernate.web.pluginSession.PluginFactory; |
7 | import pt.estgp.es.exemplos.hibernate.web.pluginSession.RegisterSession; |
||
2009 | es | 8 | |
9 | import javax.servlet.*; |
||
10 | import javax.servlet.http.HttpServletRequest; |
||
11 | import javax.servlet.http.HttpServletResponse; |
||
12 | import java.io.IOException; |
||
13 | |||
14 | public class SecurityFilter implements 1.5.0/docs/api/java/util/logging/Filter.html">Filter { |
||
2018 | es | 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 | private static final 1.5.0/docs/api/java/lang/String.html">String SESSION_IN_REQUEST_KEY = "UserSession"; |
||
18 | |||
2009 | es | 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 { |
||
2018 | es | 26 | HttpServletResponse response = (HttpServletResponse) servletResponse; |
27 | loadSessionProxy(servletRequest); |
||
28 | filterChain.doFilter(servletRequest, response); |
||
29 | } |
||
2009 | es | 30 | |
2018 | es | 31 | public static UserSession loadSessionProxy(ServletRequest servletRequest) throws 1.5.0/docs/api/java/io/IOException.html">IOException, ServletException{ |
32 | UserSession session = (UserSession) servletRequest.getAttribute(SESSION_IN_REQUEST_KEY); |
||
2009 | es | 33 | |
34 | try { |
||
2018 | es | 35 | if(session == null) { |
36 | RegisterSession plugin; |
||
37 | plugin = (RegisterSession) PluginFactory.getPlugin(RegisterSession.class); |
||
38 | session = plugin.openSession(servletRequest); |
||
39 | servletRequest.setAttribute(SESSION_IN_REQUEST_KEY,session); |
||
2009 | es | 40 | } |
2018 | es | 41 | } 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) { |
42 | logger.error(e,e); |
||
43 | return null; |
||
44 | } |
||
45 | return session; |
||
2009 | es | 46 | } |
47 | |||
48 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
49 | public void destroy() { |
||
50 | |||
51 | } |
||
52 | } |