Rev 2018 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2018 | Rev 2049 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | package pt.estgp.es.exemplos.hibernate.web; |
1 | package pt.estgp.es.exemplos.hibernate.web; |
2 | 2 | ||
3 | import org.apache.log4j.Logger; |
3 | import org.apache.log4j.Logger; |
4 | import pt.estgp.es.exemplos.hibernate.HibernateUtils; |
- | |
5 | import pt.estgp.es.exemplos.hibernate.UserSession; |
4 | import pt.estgp.es.exemplos.hibernate.UserSession; |
6 | import pt.estgp.es.exemplos.hibernate.web.pluginSession.PluginFactory; |
5 | import pt.estgp.es.exemplos.hibernate.web.pluginSession.PluginFactory; |
7 | import pt.estgp.es.exemplos.hibernate.web.pluginSession.RegisterSession; |
6 | import pt.estgp.es.exemplos.hibernate.web.pluginSession.RegisterSession; |
8 | 7 | ||
9 | import javax.servlet.*; |
8 | import javax.servlet.*; |
10 | import javax.servlet.http.HttpServletRequest; |
- | |
11 | import javax.servlet.http.HttpServletResponse; |
9 | import javax.servlet.http.HttpServletResponse; |
12 | import java.io.IOException; |
10 | import java.io.IOException; |
13 | 11 | ||
14 | public class SecurityFilter implements 1.5.0/docs/api/java/util/logging/Filter.html">Filter { |
12 | public class SecurityFilter implements 1.5.0/docs/api/java/util/logging/Filter.html">Filter { |
15 | 13 | ||
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 | 14 | ||
19 | @1.5.0/docs/api/java/lang/Override.html">Override |
- | |
20 | public void init(FilterConfig filterConfig) throws ServletException{ |
- | |
21 | 15 | ||
22 | } |
- | |
- | 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); |
|
23 | 17 | ||
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 | 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); |
- | |
33 | - | ||
34 | try { |
- | |
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); |
18 | private static final 1.5.0/docs/api/java/lang/String.html">String SESSION_IN_REQUEST_KEY = "UserSession"; |
40 | } |
19 | @1.5.0/docs/api/java/lang/Override.html">Override |
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) { |
20 | public void init(FilterConfig filterConfig) throws ServletException { |
42 | logger.error(e,e); |
- | |
43 | return null; |
- | |
44 | } |
- | |
45 | return session; |
- | |
46 | } |
- | |
47 | 21 | ||
48 | @1.5.0/docs/api/java/lang/Override.html">Override |
22 | } |
49 | public void destroy() { |
- | |
50 | 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); |
|
51 | } |
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 | } |
|
52 | } |
55 | } |