package com.dbxml.db.core.security;

/*
 * dbXML - Native XML Database
 * Copyright (C) 1999-2004  The dbXML Group, L.L.C.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: SecurityManager.java,v 1.2 2004/02/12 00:17:57 bradford Exp $
 */

import com.dbxml.db.core.Database;
import com.dbxml.util.Configurable;

/**
 * SecurityManager manages Users, Roles, and Access Control Lists
 * for dbXML.
 */

public interface SecurityManager extends Configurable {
   /**
    * setDatabase sets the Database instance for this SecurityManager.
    * It is the Database that the SecurityManager will be assigned to
    * protect.  It should also be the Database that the SecurityManager
    * uses to manage access control lists (if local).
    *
    * @param The Database instance
    */
   void setDatabase(Database database);

   /**
    * setUserStack sets the User stack for the SecurityManager.
    *
    * @param userStack The UserStack
    */
   void setUserStack(UserStack userStack) throws SecurityException;

   /**
    * setMagicUser sets the User instance that the SecurityManager
    * can use to represent system-level credentials for low level
    * resource access.  The implementation of this method should
    * not be allowed to overwrite an existing value, as the Database
    * will call this method only one time.
    *
    * @param magicUser The magic User
    */
   void setMagicUser(User magicUser) throws SecurityException;

   /**
    * authenticate checks a User against the SecurityManager's access
    * control lists.  If the user ID and password do not check out,
    * a SecurityException is thrown.
    *
    * @param userID the User ID to check
    * @param password the Password to check
    */
   void authenticate(String userID, String password) throws SecurityException;

   /**
    * access performs an access control check against the SecurityManager's
    * access control lists.  If the current user isn't allowed to access
    * the specified path with the defined permission mask, a
    * SecurityException is thrown.
    *
    * @param path the resource path being accessed
    * @param mask The access mask to check against
    */
   void access(String path, int mask) throws SecurityException;

   /**
    * getCurrentUserID returns the currently authenticated User ID.
    *
    * @return The current User ID
    */
   String getCurrentUserID();
}
