//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010  huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/willow
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : willow@lists.sourceforge.net 
 */
//----------------------------END  LICENSE-----------------------------
package org.huihoo.willow.realm;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.huihoo.willow.LifecycleException;
import org.huihoo.workflow.usermodel.WorkflowParticipant;


public class NoneDatabaseRealm  extends RealmBase
{
	protected static Log log = LogFactory.getLog(NoneDatabaseRealm.class);
	/**
	 * Descriptive information about this RealmDatabase implementation.
	 */
	protected static final String info = "NoneDatabaseRealm/1.0";

	/**
	 * Descriptive information about this RealmDabtase implementation.
	 */
	protected static final String name = "NoneDatabaseRealm";
	
	//------------------------------------------------------------- Properties
	
	/**
	 * Return descriptive information about this Realm implementation and
	 * the corresponding version number, in the format
	 * <code>&lt;description&gt;/&lt;version&gt;</code>.
	 */
	public String getInfo()
	{
		return info;
	}
	// --------------------------------------------------------- Public Methods
	public WorkflowParticipant authenticate(String username, String credentials)
	{		
		// Construct a WorkflowParticipant that represents this user
		if (debug >= 2)
		{
			log(sm.getString("userDatabaseRealm.authenticateSuccess", username));
		}
		
		return new RealmParticipant(username,null,credentials,null);
	}
	
	/**
	 * Prepare for the beginning of active use of the public methods of this
	 * component.  This method should be called before any of the public
	 * methods of this component are utilized.  It should also send a
	 * LifecycleEvent of type START_EVENT to any registered listeners.
	 *
	 * @exception LifecycleException if this component detects a fatal error
	 *  that prevents this component from being used
	 */
	public void start() throws LifecycleException
	{
		// Validate and update our current component state
		if (started)
		{
			log.info(sm.getString("userdatabaseRealm.alreadyStarted"));
			return;
		}
		lifecycle.fireLifecycleEvent(START_EVENT, null);
		started = true;
	}
	/**
	 * Gracefully terminate the active use of the public methods of this
	 * component.  This method should be the last one called on a given
	 * instance of this component.  It should also send a LifecycleEvent
	 * of type STOP_EVENT to any registered listeners.
	 *
	 * @exception LifecycleException if this component detects a fatal error
	 *  that needs to be reported
	 */
	public void stop() throws LifecycleException
	{
		// Validate and update our current component state
		if (!started)
		{
			log.info(sm.getString("userdatabaseRealm.notStarted"));
			return;
		}
		lifecycle.fireLifecycleEvent(STOP_EVENT, null);
		started = false;
	}

	protected String getName()
	{
		return this.name;
	}

	protected String getPassword(String username)
	{
		return null;
	}
	protected WorkflowParticipant getParticipant(String username)
	{
		return null;
	}
}
