1 package com.atlassian.seraph.filter; 2 3 import com.atlassian.seraph.config.SecurityConfig; 4 5 import javax.servlet.http.HttpServletRequest ; 6 import javax.servlet.http.HttpServletRequestWrapper ; 7 import java.security.Principal ; 8 9 12 public class SecurityHttpRequestWrapper extends HttpServletRequestWrapper 13 { 14 private HttpServletRequest request; 15 private SecurityConfig securityConfig; 16 17 public SecurityHttpRequestWrapper(HttpServletRequest request) 18 { 19 super(request); 20 this.request = request; 21 } 22 23 public String getRemoteUser() 24 { 25 Principal user = getUserPrincipal(); 26 if (user == null) 27 { 28 return null; 29 } 30 else 31 { 32 return user.getName(); 33 } 34 } 35 36 public Principal getUserPrincipal() 37 { 38 if (securityConfig == null) 39 { 40 securityConfig = (SecurityConfig) request.getSession().getServletContext().getAttribute(SecurityConfig.STORAGE_KEY); 41 } 42 43 Principal user = securityConfig.getAuthenticator().getUser(request); 44 return user; 45 } 46 } | Popular Tags |