Save This Page
Home » struts-2.1.8.1-src » org.apache.struts2.servlet » interceptor » [javadoc | source]
    1   /*
    2    * $Id: ServletPrincipalProxy.java 651946 2008-04-27 13:41:38Z apetrelli $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
   10    * with the License.  You may obtain a copy of the License at
   11    *
   12    *  http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing,
   15    * software distributed under the License is distributed on an
   16    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   17    * KIND, either express or implied.  See the License for the
   18    * specific language governing permissions and limitations
   19    * under the License.
   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   }

Save This Page
Home » struts-2.1.8.1-src » org.apache.struts2.servlet » interceptor » [javadoc | source]