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.portlet.interceptor;
23
24 import org.apache.struts2.interceptor.PrincipalProxy;
25
26 import javax.portlet.PortletRequest;
27 import javax.servlet.http.HttpServletRequest;
28 import java.security.Principal;
29
30 /***
31 * PrincipalProxy implementation for using PortletRequest Principal related methods.
32 */
33 public class PortletPrincipalProxy implements PrincipalProxy {
34
35 private PortletRequest request;
36
37 /***
38 * Constructs a proxy
39 *
40 * @param request The underlying request
41 */
42 public PortletPrincipalProxy(PortletRequest request) {
43 this.request = request;
44 }
45
46 /***
47 * True if the user is in the given role
48 *
49 * @param role The role
50 * @return True if the user is in that role
51 */
52 public boolean isUserInRole(String role) {
53 return request.isUserInRole(role);
54 }
55
56 /***
57 * Gets the user principal
58 *
59 * @return The principal
60 */
61 public Principal getUserPrincipal() {
62 return request.getUserPrincipal();
63 }
64
65 /***
66 * Gets the user id
67 *
68 * @return The user id
69 */
70 public String getRemoteUser() {
71 return request.getRemoteUser();
72 }
73
74 /***
75 * Is the request using https?
76 *
77 * @return True if using https
78 */
79 public boolean isRequestSecure() {
80 return request.isSecure();
81 }
82
83 /***
84 * Gets the request.
85 *
86 * @return The request
87 * @throws UnsupportedOperationException not supported in this implementation.
88 * @deprecated To obtain the HttpServletRequest in your action, use
89 * {@link org.apache.struts2.servlet.ServletRequestAware}, since this method will be dropped in future.
90 */
91 public HttpServletRequest getRequest() {
92 throw new UnsupportedOperationException("Usage of getRequest() method is deprecadet and not supported for this implementation");
93 }
94 }