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