Package net.sf.jportlet.service.login

Source Code of net.sf.jportlet.service.login.LoginServiceImpl

/*
* Created on Mar 21, 2003
*/
package net.sf.jportlet.service.login;

import java.util.Enumeration;

import net.sf.jportlet.impl.PortletRequestImpl;
import net.sf.jportlet.portlet.PortletException;
import net.sf.jportlet.portlet.PortletRequest;
import net.sf.jportlet.portlet.User;
import net.sf.jportlet.service.PortletServiceAdapter;
import net.sf.jportlet.service.user.UserNotFoundException;
import net.sf.jportlet.service.user.UserService;


/**
* Implementation of {@link net.sf.jportlet.service.login.LoginService}
*
* @author <a href="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
*/
public class LoginServiceImpl
    extends PortletServiceAdapter
    implements LoginService
{
    //~ Methods ----------------------------------------------------------------

    /**
     * @see net.sf.jportlet.service.login.LoginService#login(net.sf.jportlet.portlet.PortletRequest)
     */
    public boolean login( PortletRequest request )
        throws PortletException
    {
        boolean debug = _log.isDebugEnabled(  );

        if ( debug )
        {
            _log.debug( "login" );
        }

        String userId = ( String ) request.getParameter( LoginService.USER_ID );
        String password = ( String ) request.getParameter( LoginService.PASSWORD );

        if ( debug )
        {
            _log.debug( USER_ID + "=" + userId );
            _log.debug( PASSWORD + "=" + password );
        }

        if ( userId != null )
        {
            userId = userId.trim(  );
            if ( password != null )
            {
                password = password.trim(  );
            }

            UserService usrv = ( UserService ) _serviceContext.getPortletService( UserService.NAME );
            try
            {
                User usr = usrv.getUser( userId );
                if ( usr.matchPassword( password ) )
                {
                    /* Start the session */
                    ( ( PortletRequestImpl ) request ).startSession( usr );

                    /* Notify all the portlets */
                    Enumeration portletNames = _serviceContext.getPortletNames(  );

                    while ( portletNames.hasMoreElements(  ) )
                    {
                        String name = portletNames.nextElement(  ).toString(  );
                        _serviceContext.getPortlet( name ).login( request );
                    }

                    return true;
                }
                else
                {
                    _log.debug( "Password doesn't match" );
                }
            }
            catch ( UserNotFoundException e )
            {
                if ( debug )
                {
                    _log.debug( "User not found" );
                }
            }
        }

        return false;
    }

    /**
     * @see net.sf.jportlet.service.login.LoginService#logout(net.sf.jportlet.portlet.PortletRequest)
     */
    public void logout( PortletRequest request )
        throws PortletException
    {
        if ( _log.isDebugEnabled(  ) )
        {
            _log.debug( "logout" );
        }

        /* Start the session */
        ( ( PortletRequestImpl ) request ).stopSession(  );
    }

    /**
     * @see net.sf.jportlet.service.PortletService#getServiceName()
     */
    public String getServiceName(  )
    {
        return LoginService.NAME;
    }
}
TOP

Related Classes of net.sf.jportlet.service.login.LoginServiceImpl

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.