01: /*
02: * $Id: ServletPrincipalProxy.java 559543 2007-07-25 18:05:51Z apetrelli $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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: package org.apache.struts2.servlet.interceptor;
22:
23: import org.apache.struts2.interceptor.PrincipalProxy;
24:
25: import javax.servlet.http.HttpServletRequest;
26: import java.security.Principal;
27:
28: /**
29: * PrincipalProxy implementation for using HttpServletRequest Principal related methods.
30: */
31: public class ServletPrincipalProxy implements PrincipalProxy {
32: private HttpServletRequest request;
33:
34: /**
35: * Constructs a proxy
36: *
37: * @param request The underlying request
38: */
39: public ServletPrincipalProxy(HttpServletRequest request) {
40: this .request = request;
41: }
42:
43: /**
44: * True if the user is in the given role
45: *
46: * @param role The role
47: * @return True if the user is in that role
48: */
49: public boolean isUserInRole(String role) {
50: return request.isUserInRole(role);
51: }
52:
53: /**
54: * Gets the user principal
55: *
56: * @return The principal
57: */
58: public Principal getUserPrincipal() {
59: return request.getUserPrincipal();
60: }
61:
62: /**
63: * Gets the user id
64: *
65: * @return The user id
66: */
67: public String getRemoteUser() {
68: return request.getRemoteUser();
69: }
70:
71: /**
72: * Is the request using https?
73: *
74: * @return True if using https
75: */
76: public boolean isRequestSecure() {
77: return request.isSecure();
78: }
79:
80: /**
81: * Gets the request.
82: *
83: * @return The request
84: * @deprecated To obtain the HttpServletRequest in your action, use
85: * {@link org.apache.struts2.servlet.ServletRequestAware}, since this method will be dropped in future.
86: */
87: public HttpServletRequest getRequest() {
88: return request;
89: }
90: }
|