/* ======================================================================
   Parts Copyright 2006 University of Leeds, Oxford University, University of the Highlands and Islands.

   Licensed 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.bodington.server.realm;

import org.bodington.sqldatabase.*;

import java.security.*;

/**
 * Created as a super class to Group and User in the same package.
 * This is to allow that in the future users may be entries in an
 * acl and groups can be members of groups.  These things are not
 * implemented yet.
 * 
 * @author Jon Maber
 * @version 1.0
 */
public abstract class Principal extends org.bodington.sqldatabase.SqlPersistentObject implements java.security.Principal
	{

    /**
     * Since this is a subclass of PersistentObject the primary key can be used
     * for the hash code.
     * 
     * @return The primary key of the object.
     */
    public int hashCode()
    	{
		return getPrimaryKey().intValue();
    	}

    /**
     * Uses the primary key as the test.
     * 
     * @param another The other object to test.
     * @return If both references refer to the same object returns true.
     */
    public boolean equals(Object another)
    	{
		if ( !(another instanceof SqlPersistentObject) )
			return false;
		SqlPersistentObject another_obj = (SqlPersistentObject)another;
		return getPrimaryKey().equals( another_obj.getPrimaryKey() );
    	}

	} 
