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