001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.servlet;
016    
017    import java.security.Principal;
018    
019    import javax.servlet.http.HttpServletRequest;
020    import javax.servlet.http.HttpServletRequestWrapper;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class ProtectedServletRequest extends HttpServletRequestWrapper {
026    
027            public ProtectedServletRequest(
028                    HttpServletRequest request, String remoteUser) {
029    
030                    this(request, remoteUser, null);
031            }
032    
033            public ProtectedServletRequest(
034                    HttpServletRequest request, String remoteUser, String authType) {
035    
036                    super(request);
037    
038                    _remoteUser = remoteUser;
039    
040                    if (remoteUser != null) {
041                            _userPrincipal = new ProtectedPrincipal(remoteUser);
042                    }
043    
044                    _authType = authType;
045            }
046    
047            @Override
048            public String getAuthType() {
049                    if (_authType == null) {
050                            return super.getAuthType();
051                    }
052    
053                    return _authType;
054            }
055    
056            @Override
057            public String getRemoteUser() {
058                    if (_remoteUser != null) {
059                            return _remoteUser;
060                    }
061                    else {
062                            return super.getRemoteUser();
063                    }
064            }
065    
066            @Override
067            public Principal getUserPrincipal() {
068                    if (_userPrincipal != null) {
069                            return _userPrincipal;
070                    }
071                    else {
072                            return super.getUserPrincipal();
073                    }
074            }
075    
076            private String _authType;
077            private String _remoteUser;
078            private Principal _userPrincipal;
079    
080    }