1 package org.apache.struts2.servlet.interceptor; 2 3 import org.apache.struts2.interceptor.PrincipalProxy; 4 5 import javax.servlet.http.HttpServletRequest; 6 import java.security.Principal; 7 8 /*** 9 * PrincipalProxy implementation for using HttpServletRequest Principal related methods. 10 */ 11 public class ServletPrincipalProxy implements PrincipalProxy { 12 private HttpServletRequest request; 13 14 /*** 15 * Constructs a proxy 16 * 17 * @param request The underlying request 18 */ 19 public ServletPrincipalProxy(HttpServletRequest request) { 20 this.request = request; 21 } 22 23 /*** 24 * True if the user is in the given role 25 * 26 * @param role The role 27 * @return True if the user is in that role 28 */ 29 public boolean isUserInRole(String role) { 30 return request.isUserInRole(role); 31 } 32 33 /*** 34 * Gets the user principal 35 * 36 * @return The principal 37 */ 38 public Principal getUserPrincipal() { 39 return request.getUserPrincipal(); 40 } 41 42 /*** 43 * Gets the user id 44 * 45 * @return The user id 46 */ 47 public String getRemoteUser() { 48 return request.getRemoteUser(); 49 } 50 51 /*** 52 * Is the request using https? 53 * 54 * @return True if using https 55 */ 56 public boolean isRequestSecure() { 57 return request.isSecure(); 58 } 59 60 /*** 61 * Gets the request. 62 * 63 * @return The request 64 * @deprecated To obtain the HttpServletRequest in your action, use 65 * {@link org.apache.struts2.servlet.ServletRequestAware}, since this method will be dropped in future. 66 */ 67 public HttpServletRequest getRequest() { 68 return request; 69 } 70 }