KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > atlassian > seraph > filter > SecurityHttpRequestWrapper


1 package com.atlassian.seraph.filter;
2
3 import com.atlassian.seraph.config.SecurityConfig;
4
5 import javax.servlet.http.HttpServletRequest JavaDoc;
6 import javax.servlet.http.HttpServletRequestWrapper JavaDoc;
7 import java.security.Principal JavaDoc;
8
9 /**
10  * A simple request wrapper used to intercept default Servlet API security methods.
11  */

12 public class SecurityHttpRequestWrapper extends HttpServletRequestWrapper JavaDoc
13 {
14     private HttpServletRequest JavaDoc request;
15     private SecurityConfig securityConfig;
16
17     public SecurityHttpRequestWrapper(HttpServletRequest JavaDoc request)
18     {
19         super(request);
20         this.request = request;
21     }
22
23     public String JavaDoc getRemoteUser()
24     {
25         Principal JavaDoc user = getUserPrincipal();
26         if (user == null)
27         {
28             return null;
29         }
30         else
31         {
32             return user.getName();
33         }
34     }
35
36     public Principal JavaDoc getUserPrincipal()
37     {
38         if (securityConfig == null)
39         {
40             securityConfig = (SecurityConfig) request.getSession().getServletContext().getAttribute(SecurityConfig.STORAGE_KEY);
41         }
42
43         Principal JavaDoc user = securityConfig.getAuthenticator().getUser(request);
44         return user;
45     }
46 }
Popular Tags