org.h2.engine
Class User

java.lang.Object
  extended by org.h2.engine.DbObjectBase
      extended by org.h2.engine.RightOwner
          extended by org.h2.engine.User
All Implemented Interfaces:
DbObject

public class User
extends RightOwner

Represents a user object.


Field Summary
 
Fields inherited from class org.h2.engine.DbObjectBase
comment, database, trace
 
Fields inherited from interface org.h2.engine.DbObject
AGGREGATE, COMMENT, CONSTANT, CONSTRAINT, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, TABLE_OR_VIEW, TRIGGER, USER, USER_DATATYPE
 
Constructor Summary
User(Database database, int id, java.lang.String userName, boolean systemUser)
           
 
Method Summary
 void checkAdmin()
          Check if this user has admin rights.
 void checkOwnsNoSchemas()
          Check that this user does not own any schema.
 void checkRename()
          Check if this object can be renamed.
 void checkRight(Table table, int rightMask)
          Checks that this user has the given rights for this database object.
 ObjectArray<DbObject> getChildren()
          Get the list of dependent children (for tables, this includes indexes and so on).
 java.lang.String getCreateSQL()
          Build a SQL statement to re-create this object.
 java.lang.String getCreateSQL(boolean password, boolean ifNotExists)
          Get the CREATE SQL statement for this object.
 java.lang.String getCreateSQLForCopy(Table table, java.lang.String quotedName)
          Build a SQL statement to re-create the object, or to create a copy of the object with a different name or referencing a different table
 java.lang.String getDropSQL()
          Build a SQL statement to drop this object.
 int getType()
          Get the object type.
 boolean isAdmin()
           
 void removeChildrenAndResources(Session session)
          Remove all dependent objects and free all resources (files, blocks in files) of this object.
 void setAdmin(boolean admin)
           
 void setSaltAndHash(byte[] salt, byte[] hash)
          Set the salt and hash of the password for this user.
 void setUserPasswordHash(byte[] userPasswordHash)
          Set the user name password hash.
 boolean validateUserPasswordHash(byte[] userPasswordHash)
          Check the password of this user.
 
Methods inherited from class org.h2.engine.RightOwner
getRightForRole, getRightForTable, grantRight, grantRole, isRoleGranted, revokeRight, revokeRole
 
Methods inherited from class org.h2.engine.DbObjectBase
getComment, getDatabase, getHeadPos, getId, getModificationId, getName, getSQL, initDbObjectBase, invalidate, isTemporary, rename, setComment, setModified, setObjectName, setTemporary, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

User

public User(Database database,
            int id,
            java.lang.String userName,
            boolean systemUser)
Method Detail

setAdmin

public void setAdmin(boolean admin)

isAdmin

public boolean isAdmin()

setSaltAndHash

public void setSaltAndHash(byte[] salt,
                           byte[] hash)
Set the salt and hash of the password for this user.

Parameters:
salt - the salt
hash - the password hash

setUserPasswordHash

public void setUserPasswordHash(byte[] userPasswordHash)
Set the user name password hash. A random salt is generated as well. The parameter is filled with zeros after use.

Parameters:
userPasswordHash - the user name password hash

getCreateSQLForCopy

public java.lang.String getCreateSQLForCopy(Table table,
                                            java.lang.String quotedName)
Description copied from class: DbObjectBase
Build a SQL statement to re-create the object, or to create a copy of the object with a different name or referencing a different table

Specified by:
getCreateSQLForCopy in interface DbObject
Specified by:
getCreateSQLForCopy in class DbObjectBase
Parameters:
table - the new table name
quotedName - the new quoted name
Returns:
the SQL statement

getCreateSQL

public java.lang.String getCreateSQL()
Description copied from class: DbObjectBase
Build a SQL statement to re-create this object.

Specified by:
getCreateSQL in interface DbObject
Specified by:
getCreateSQL in class DbObjectBase
Returns:
the SQL statement

getDropSQL

public java.lang.String getDropSQL()
Description copied from class: DbObjectBase
Build a SQL statement to drop this object.

Specified by:
getDropSQL in interface DbObject
Specified by:
getDropSQL in class DbObjectBase
Returns:
the SQL statement

checkRight

public void checkRight(Table table,
                       int rightMask)
                throws java.sql.SQLException
Checks that this user has the given rights for this database object.

Parameters:
table - the database object
rightMask - the rights required
Throws:
java.sql.SQLException - if this user does not have the required rights

getCreateSQL

public java.lang.String getCreateSQL(boolean password,
                                     boolean ifNotExists)
Get the CREATE SQL statement for this object.

Parameters:
password - true if the password (actually the salt and hash) should be returned
ifNotExists - true if IF NOT EXISTS should be used
Returns:
the SQL statement

validateUserPasswordHash

public boolean validateUserPasswordHash(byte[] userPasswordHash)
Check the password of this user.

Parameters:
userPasswordHash - the password data (the user password hash)
Returns:
true if the user password hash is correct

checkAdmin

public void checkAdmin()
                throws java.sql.SQLException
Check if this user has admin rights. An exception is thrown if he does not have them.

Throws:
java.sql.SQLException - if this user is not an admin

getType

public int getType()
Description copied from class: DbObjectBase
Get the object type.

Specified by:
getType in interface DbObject
Specified by:
getType in class DbObjectBase
Returns:
the object type

getChildren

public ObjectArray<DbObject> getChildren()
Description copied from interface: DbObject
Get the list of dependent children (for tables, this includes indexes and so on).

Specified by:
getChildren in interface DbObject
Overrides:
getChildren in class DbObjectBase
Returns:
the list of children

removeChildrenAndResources

public void removeChildrenAndResources(Session session)
                                throws java.sql.SQLException
Description copied from class: DbObjectBase
Remove all dependent objects and free all resources (files, blocks in files) of this object.

Specified by:
removeChildrenAndResources in interface DbObject
Specified by:
removeChildrenAndResources in class DbObjectBase
Parameters:
session - the session
Throws:
java.sql.SQLException

checkRename

public void checkRename()
Description copied from class: DbObjectBase
Check if this object can be renamed. System objects may not be renamed.

Specified by:
checkRename in interface DbObject
Specified by:
checkRename in class DbObjectBase

checkOwnsNoSchemas

public void checkOwnsNoSchemas()
                        throws java.sql.SQLException
Check that this user does not own any schema. An exception is thrown if he owns one or more schemas.

Throws:
java.sql.SQLException - if this user owns a schema