Rev 2049 | 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 { |
||
2072 | es | 26 | |
2049 | es | 27 | HttpServletResponse response = (HttpServletResponse) servletResponse; |
2072 | es | 28 | response.setHeader("Cache-Control", "no-cache"); |
2049 | es | 29 | loadSessionProxy(servletRequest); |
30 | filterChain.doFilter(servletRequest, response); |
||
31 | } |
||
2009 | es | 32 | |
33 | |||
2049 | es | 34 | |
35 | |||
2072 | es | 36 | public static UserSession loadSessionProxy(ServletRequest servletRequest) throws 1.5.0/docs/api/java/io/IOException.html">IOException, ServletException |
37 | { |
||
38 | return loadSessionProxy(false,servletRequest); |
||
39 | } |
||
40 | |||
41 | public static UserSession loadSessionProxy(boolean forceReset, ServletRequest servletRequest) throws 1.5.0/docs/api/java/io/IOException.html">IOException, ServletException { |
||
42 | |||
43 | if(forceReset) |
||
44 | servletRequest.setAttribute(SESSION_IN_REQUEST_KEY,null); |
||
45 | |||
2049 | es | 46 | UserSession session = (UserSession) servletRequest.getAttribute(SESSION_IN_REQUEST_KEY); |
47 | |||
48 | try { |
||
49 | if(session == null) { |
||
50 | RegisterSession plugin; |
||
51 | plugin = (RegisterSession) PluginFactory.getPlugin(RegisterSession.class); |
||
52 | session = plugin.openSession(servletRequest); |
||
53 | servletRequest.setAttribute(SESSION_IN_REQUEST_KEY,session); |
||
54 | } |
||
55 | } 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) { |
||
56 | logger.error(e,e); |
||
57 | return null; |
||
58 | } |
||
59 | return session; |
||
60 | } |
||
61 | |||
62 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
63 | public void destroy() { |
||
64 | |||
65 | } |
||
2009 | es | 66 | } |