Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/GGInAFilter.java @ 3485:71ba3cf3ec5e
Refactor Authentication to allow to pass the Freatures to the user class
The Features class can be used to receive the allowed features for the users
roles.
flys-client/trunk@5183 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 10 Aug 2012 07:06:18 +0000 |
parents | 8255247da645 |
children | a4c9296f6efa |
comparison
equal
deleted
inserted
replaced
3484:83845aa322ea | 3485:71ba3cf3ec5e |
---|---|
1 package de.intevation.flys.client.server; | 1 package de.intevation.flys.client.server; |
2 | 2 |
3 import java.io.IOException; | 3 import java.io.IOException; |
4 import java.util.Enumeration; | |
4 | 5 |
5 import javax.servlet.Filter; | 6 import javax.servlet.Filter; |
6 import javax.servlet.FilterChain; | 7 import javax.servlet.FilterChain; |
7 import javax.servlet.FilterConfig; | 8 import javax.servlet.FilterConfig; |
9 import javax.servlet.ServletContext; | |
8 import javax.servlet.ServletException; | 10 import javax.servlet.ServletException; |
9 import javax.servlet.ServletRequest; | 11 import javax.servlet.ServletRequest; |
10 import javax.servlet.ServletResponse; | 12 import javax.servlet.ServletResponse; |
11 | 13 |
12 import javax.servlet.http.HttpServletRequest; | 14 import javax.servlet.http.HttpServletRequest; |
17 | 19 |
18 import de.intevation.flys.client.server.auth.Authentication; | 20 import de.intevation.flys.client.server.auth.Authentication; |
19 import de.intevation.flys.client.server.auth.AuthenticationException; | 21 import de.intevation.flys.client.server.auth.AuthenticationException; |
20 import de.intevation.flys.client.server.auth.AuthenticationFactory; | 22 import de.intevation.flys.client.server.auth.AuthenticationFactory; |
21 import de.intevation.flys.client.server.auth.User; | 23 import de.intevation.flys.client.server.auth.User; |
24 import de.intevation.flys.client.server.features.Features; | |
22 | 25 |
23 | 26 |
24 /** ServletFilter used for GGInA authentification and certain authorisation. */ | 27 /** ServletFilter used for GGInA authentification and certain authorisation. */ |
25 public class GGInAFilter implements Filter { | 28 public class GGInAFilter implements Filter { |
26 | 29 |
27 /** Private logger. */ | 30 /** Private logger. */ |
28 private static Logger logger = Logger.getLogger(GGInAFilter.class); | 31 private static Logger logger = Logger.getLogger(GGInAFilter.class); |
29 | 32 |
30 private boolean deactivate = false; | 33 private boolean deactivate = false; |
31 private String authmethod; | 34 private String authmethod; |
35 private ServletContext sc; | |
32 | 36 |
33 | 37 |
34 /** | 38 /** |
35 * Initialize. | 39 * Initialize. |
36 * | 40 * |
39 @Override | 43 @Override |
40 public void init(FilterConfig config) | 44 public void init(FilterConfig config) |
41 throws ServletException | 45 throws ServletException |
42 { | 46 { |
43 String deactivate = config.getInitParameter("deactivate"); | 47 String deactivate = config.getInitParameter("deactivate"); |
44 this.authmethod = config.getServletContext().getInitParameter( | 48 this.sc = config.getServletContext(); |
45 "authentication"); | 49 this.authmethod = sc.getInitParameter("authentication"); |
46 if (deactivate != null && deactivate.equalsIgnoreCase("true")) { | 50 if (deactivate != null && deactivate.equalsIgnoreCase("true")) { |
47 this.deactivate = true; | 51 this.deactivate = true; |
48 } | 52 } |
49 | 53 |
50 } | 54 } |
67 } | 71 } |
68 | 72 |
69 HttpServletRequest sreq = (HttpServletRequest) req; | 73 HttpServletRequest sreq = (HttpServletRequest) req; |
70 | 74 |
71 String requesturi = sreq.getRequestURI(); | 75 String requesturi = sreq.getRequestURI(); |
76 for (Enumeration e = req.getAttributeNames() ; e.hasMoreElements() ;) { | |
77 logger.debug(e.nextElement()); | |
78 } | |
72 | 79 |
73 logger.debug("Request for: " + requesturi); | 80 logger.debug("Request for: " + requesturi); |
74 | 81 |
75 // Allow access to login pages | 82 // Allow access to login pages |
76 // TODO Maybe replace with Filter <url-pattern> | 83 // TODO Maybe replace with Filter <url-pattern> |
131 public void destroy() { | 138 public void destroy() { |
132 } | 139 } |
133 | 140 |
134 private Authentication auth(User user, String encoding) | 141 private Authentication auth(User user, String encoding) |
135 throws AuthenticationException, IOException { | 142 throws AuthenticationException, IOException { |
143 Features features = (Features)sc.getAttribute(Features.CONTEXT_ATTRIBUTE); | |
136 return AuthenticationFactory.getInstance(this.authmethod).auth( | 144 return AuthenticationFactory.getInstance(this.authmethod).auth( |
137 user.getName(), user.getPassword(), encoding); | 145 user.getName(), user.getPassword(), encoding, features); |
138 } | 146 } |
139 } | 147 } |
140 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 148 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |