Package org.jasig.portal.persondir.support

Source Code of org.jasig.portal.persondir.support.PersonManagerCurrentUserProvider

/**
* Licensed to Jasig under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Jasig licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.jasig.portal.persondir.support;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jasig.portal.security.IPerson;
import org.jasig.portal.security.IPersonManager;
import org.jasig.portal.url.IPortalRequestUtils;
import org.jasig.services.persondir.support.ICurrentUserProvider;

/**
* Provides the username of the current portal user
*
* @author Eric Dalquist
* @version $Revision: 19776 $
*/
public class PersonManagerCurrentUserProvider implements ICurrentUserProvider {
    protected final Log logger = LogFactory.getLog(this.getClass());
   
    private IPersonManager personManager;
    private IPortalRequestUtils portalRequestUtils;
   

    public IPersonManager getPersonManager() {
        return personManager;
    }
    /**
     * @param personManager the personManager to set
     */
    public void setPersonManager(IPersonManager personManager) {
        this.personManager = personManager;
    }

    public IPortalRequestUtils getPortalRequestUtils() {
        return portalRequestUtils;
    }
    /**
     * @param portalRequestUtils the portalRequestUtils to set
     */
    public void setPortalRequestUtils(IPortalRequestUtils portalRequestUtils) {
        this.portalRequestUtils = portalRequestUtils;
    }



    /* (non-Javadoc)
     * @see org.jasig.services.persondir.support.ICurrentUserProvider#getCurrentUserName()
     */
    public String getCurrentUserName() {
        final HttpServletRequest portalRequest;
        try {
            portalRequest = this.portalRequestUtils.getCurrentPortalRequest();
        }
        catch (IllegalStateException ise) {
            this.logger.warn("No current portal request available, cannot determine current user name.");
            return null;
        }
       
        final IPerson person = this.personManager.getPerson(portalRequest);
        if (person == null) {
            this.logger.warn("IPersonManager returned no IPerson for request, cannot determine current user name. " + portalRequest);
            return null;
        }
       
        return person.getUserName();
    }
}
TOP

Related Classes of org.jasig.portal.persondir.support.PersonManagerCurrentUserProvider

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.