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