package com.dbxml.db.common.security;
/*
* dbXML - Native XML Database
* Copyright (c) 1999-2006 The dbXML Group, L.L.C.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* $Id: SimpleSecurityManager.java,v 1.3 2006/02/02 18:53:52 bradford Exp $
*/
import com.dbxml.db.core.security.InvalidCredentialsException;
import com.dbxml.db.core.security.InvalidUserException;
import com.dbxml.db.core.security.SecurityException;
import com.dbxml.util.Configuration;
import com.dbxml.util.dbXMLException;
/**
* SimpleSecurityManager is an incredibly simple SecurityManager
* implementation that allows a single User ID and password to be
* defined for the entire database. The User ID and password are
* defined in the system.xml file instead of being stored in the
* database itself.
*/
public final class SimpleSecurityManager extends SecurityManagerBase {
private static final String USERID = "userid";
private static final String PASSWORD = "password";
private String userID;
private String password;
public void setConfig(Configuration config) throws dbXMLException {
super.setConfig(config);
userID = config.getAttribute(USERID);
password = config.getAttribute(PASSWORD);
}
public void authenticate(String userID, String password) throws SecurityException {
if ( !this.userID.equals(userID) )
throw new InvalidUserException("Unknown User '"+userID+"'");
if ( !this.password.equals(password) )
throw new InvalidCredentialsException("Invalid credentials for User '"+userID+"'");
}
public void access(String path, int mask) throws SecurityException {
}
}