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