View Javadoc

1   /*
2    * $Id: PrincipalProxy.java 439747 2006-09-03 09:22:46Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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  }