001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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                    super(request);
031    
032                    _remoteUser = remoteUser;
033    
034                    if (remoteUser != null) {
035                            _userPrincipal = new ProtectedPrincipal(remoteUser);
036                    }
037            }
038    
039            public String getRemoteUser() {
040                    if (_remoteUser != null) {
041                            return _remoteUser;
042                    }
043                    else {
044                            return super.getRemoteUser();
045                    }
046            }
047    
048            public Principal getUserPrincipal() {
049                    if (_userPrincipal != null) {
050                            return _userPrincipal;
051                    }
052                    else {
053                            return super.getUserPrincipal();
054                    }
055            }
056    
057            private String _remoteUser;
058            private Principal _userPrincipal;
059    
060    }