|
HSQLDB example source code file (User.java)
The HSQLDB User.java source code
/*
* For work developed by the HSQL Development Group:
*
* Copyright (c) 2001-2010, The HSQL Development Group
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the HSQL Development Group nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*
* For work originally developed by the Hypersonic SQL Group:
*
* Copyright (c) 1995-2000, The Hypersonic SQL Group.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the Hypersonic SQL Group nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE HYPERSONIC SQL GROUP,
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Hypersonic SQL Group.
*/
package org.hsqldb;
import org.hsqldb.HsqlNameManager.HsqlName;
import org.hsqldb.lib.HashSet;
import org.hsqldb.lib.IntValueHashMap;
// fredt@users 20021103 - patch 1.7.2 - fix bug in revokeAll()
// fredt@users 20021103 - patch 1.7.2 - allow for drop table, etc.
// when tables are dropped or renamed, changes are reflected in the
// permissions held in User objects.
// boucherb@users 200208-200212 - doc 1.7.2 - update
// boucherb@users 200208-200212 - patch 1.7.2 - metadata
// unsaved@users - patch 1.8.0 moved right managament to new classes
/**
* A User Object holds the name, password for a
* particular database user.<p>
*
* Enhanced in successive versions of HSQLDB.
*
* @author Thomas Mueller (Hypersonic SQL Group)
* @version 1.8.0
* @since Hypersonic SQL
*/
public class User {
/** true if this user is the sys user. */
private boolean isSys;
/** true if this user is the public user. */
private boolean isPublic;
/** user name. */
private String sName;
/** password. */
private String sPassword;
/** default schema when new Sessions started (defaults to PUBLIC schema) */
private HsqlName initialSchema = null;
/** grantee object. */
private Grantee grantee;
/**
* Constructor
*/
User(String name, String password,
Grantee inGrantee) throws HsqlException {
sName = name;
grantee = inGrantee;
boolean granteeOk = grantee != null
|| GranteeManager.isReserved(name);
if (!granteeOk) {
Trace.doAssert(false,
Trace.getMessage(Trace.MISSING_GRANTEE) + ": "
+ name);
}
setPassword(password);
isSys = name.equals(GranteeManager.SYSTEM_AUTHORIZATION_NAME);
isPublic = name.equals(GranteeManager.PUBLIC_ROLE_NAME);
}
String getName() {
return sName;
}
void setPassword(String password) throws HsqlException {
// TODO:
// checkComplexity(password);
// requires: UserManager.createSAUser(), UserManager.createPublicUser()
sPassword = password;
}
/**
* Checks if this object's password attibute equals
* specified argument, else throws.
*/
void checkPassword(String test) throws HsqlException {
Trace.check(test.equals(sPassword), Trace.ACCESS_IS_DENIED);
}
/**
* Returns true if this User object is for a user with the
* database administrator role.
*/
boolean isSys() {
return isSys;
}
/**
* Returns the initial schema for the user
*/
HsqlName getInitialSchema() {
return initialSchema;
}
/**
* This class does not have access to the SchemaManager, therefore
* caller should verify that the given schemaName exists.
*
* @param schemaName Name of an existing schema. Null value allowed,
* which means use the DB default session schema.
*/
void setInitialSchema(HsqlName schema) {
initialSchema = schema;
}
/**
* Returns true if this User object represents the PUBLIC user
*/
boolean isPublic() {
return isPublic;
}
/**
* Returns the ALTER USER DDL character sequence that preserves the
* this user's current password value and mode. <p>
*
* @return the DDL
*/
String getAlterUserDDL() {
StringBuffer sb = new StringBuffer();
sb.append(Token.T_ALTER).append(' ');
sb.append(Token.T_USER).append(' ');
sb.append(sName).append(' ');
sb.append(Token.T_SET).append(' ');
sb.append(Token.T_PASSWORD).append(' ');
sb.append('"').append(sPassword).append('"');
return sb.toString();
}
/**
* returns the DDL string
* sequence that creates this user.
*
*/
String getCreateUserDDL() {
StringBuffer sb = new StringBuffer(64);
sb.append(Token.T_CREATE).append(' ');
sb.append(Token.T_USER).append(' ');
sb.append(sName).append(' ');
sb.append(Token.T_PASSWORD).append(' ');
sb.append('"').append(sPassword).append('"');
return sb.toString();
}
/**
* Retrieves the redo log character sequence for connecting
* this user
*
* @return the redo log character sequence for connecting
* this user
*/
public String getConnectStatement() {
StringBuffer sb = new StringBuffer();
sb.append(Token.T_CONNECT).append(' ');
sb.append(Token.T_USER).append(' ');
sb.append(sName);
return sb.toString();
}
/**
* Retrieves the Grantee object for this User.
*/
Grantee getGrantee() {
return grantee;
}
/**
* Sets the Grantee object for this User.
* This is done in the constructor for all users except the special
* users SYSTEM and PUBLIC, which have to be set up before the
* Managers are initialized.
*/
void setGrantee(Grantee inGrantee) throws HsqlException {
if (grantee != null) {
Trace.doAssert(false,
Trace.getMessage(Trace.CHANGE_GRANTEE) + ": "
+ sName);
}
grantee = inGrantee;
}
// Legacy wrappers
/**
* Returns true if this User object is for a user with the
* database administrator role.
*/
boolean isAdmin() {
return grantee.isAdmin();
}
/**
* Retrieves a string[] whose elements are the names, of the rights
* explicitly granted with the GRANT command to this <code>User
* object on the <code>Table object identified by the
* <code>name argument.
* * @return array of Strings naming the rights granted to this
* <code>User object on the
Other HSQLDB examples (source code examples)Here is a short list of links related to this HSQLDB User.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.