001    /**
002     * Copyright (c) 2000-2011 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.portlet;
016    
017    import com.liferay.portal.kernel.servlet.ProtectedPrincipal;
018    
019    import java.security.Principal;
020    
021    import javax.portlet.RenderRequest;
022    import javax.portlet.filter.RenderRequestWrapper;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class ProtectedRenderRequest extends RenderRequestWrapper {
028    
029            public ProtectedRenderRequest(
030                    RenderRequest renderRequest, String remoteUser) {
031    
032                    super(renderRequest);
033    
034                    _remoteUser = remoteUser;
035    
036                    if (remoteUser != null) {
037                            _userPrincipal = new ProtectedPrincipal(remoteUser);
038                    }
039            }
040    
041            @Override
042            public String getRemoteUser() {
043                    if (_remoteUser != null) {
044                            return _remoteUser;
045                    }
046                    else {
047                            return super.getRemoteUser();
048                    }
049            }
050    
051            @Override
052            public Principal getUserPrincipal() {
053                    if (_userPrincipal != null) {
054                            return _userPrincipal;
055                    }
056                    else {
057                            return super.getUserPrincipal();
058                    }
059            }
060    
061            private String _remoteUser;
062            private Principal _userPrincipal;
063    
064    }