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