Package org.h2.engine
Class User
- java.lang.Object
-
- org.h2.engine.DbObject
-
- org.h2.engine.RightOwner
-
- org.h2.engine.User
-
- All Implemented Interfaces:
HasSQL
public final class User extends RightOwner
Represents a user object.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
admin
private byte[]
passwordHash
private byte[]
salt
private boolean
systemUser
-
Fields inherited from class org.h2.engine.DbObject
AGGREGATE, comment, COMMENT, CONSTANT, CONSTRAINT, database, DOMAIN, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, SYNONYM, TABLE_OR_VIEW, trace, TRIGGER, USER
-
Fields inherited from interface org.h2.util.HasSQL
ADD_PLAN_INFORMATION, DEFAULT_SQL_FLAGS, NO_CASTS, QUOTE_ONLY_WHEN_REQUIRED, REPLACE_LOBS_FOR_TRACE, TRACE_SQL_FLAGS
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkAdmin()
Checks if this user has admin rights.void
checkSchemaAdmin()
Checks if this user has schema admin rights for every schema.void
checkSchemaOwner(Schema schema)
Checks if this user has schema owner rights for the specified schema.void
checkTableRight(Table table, int rightMask)
Checks that this user has the given rights for the specified table.java.util.ArrayList<DbObject>
getChildren()
Get the list of dependent children (for tables, this includes indexes and so on).java.lang.String
getCreateSQL()
Construct the CREATE ...java.lang.String
getCreateSQL(boolean password)
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 tableint
getType()
Get the object type.private boolean
hasSchemaRight(Schema schema)
See if this user has owner rights for the specified schemaboolean
hasTableRight(Table table, int rightMask)
See if this user has the given rights for this database object.boolean
isAdmin()
void
removeChildrenAndResources(SessionLocal session)
Delete all dependent children objects and resources 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.(package private) boolean
validateUserPasswordHash(byte[] userPasswordHash)
Check the password of this user.-
Methods inherited from class org.h2.engine.RightOwner
checkOwnsNoSchemas, getRightForObject, getRightForRole, grantRight, grantRole, isRoleGranted, isSchemaRightGrantedRecursive, isTableRightGrantedRecursive, rename, revokeRight, revokeRole, revokeTemporaryRightsOnRoles
-
Methods inherited from class org.h2.engine.DbObject
checkRename, getComment, getCreateSQLForMeta, getDatabase, getDropSQL, getId, getModificationId, getName, getSQL, getSQL, invalidate, isTemporary, isValid, setComment, setModified, setObjectName, setTemporary, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.h2.util.HasSQL
getTraceSQL
-
-
-
-
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 salthash
- 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:DbObject
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 classDbObject
- Parameters:
table
- the new tablequotedName
- the quoted name- Returns:
- the SQL statement
-
getCreateSQL
public java.lang.String getCreateSQL()
Description copied from class:DbObject
Construct the CREATE ... SQL statement for this object.- Specified by:
getCreateSQL
in classDbObject
- Returns:
- the SQL statement
-
getCreateSQL
public java.lang.String getCreateSQL(boolean password)
Get the CREATE SQL statement for this object.- Parameters:
password
- true if the password (actually the salt and hash) should be returned- Returns:
- the SQL statement
-
validateUserPasswordHash
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()
Checks if this user has admin rights. An exception is thrown if user doesn't have them.- Throws:
DbException
- if this user is not an admin
-
checkSchemaAdmin
public void checkSchemaAdmin()
Checks if this user has schema admin rights for every schema. An exception is thrown if user doesn't have them.- Throws:
DbException
- if this user is not a schema admin
-
checkSchemaOwner
public void checkSchemaOwner(Schema schema)
Checks if this user has schema owner rights for the specified schema. An exception is thrown if user doesn't have them.- Parameters:
schema
- the schema- Throws:
DbException
- if this user is not a schema owner
-
hasSchemaRight
private boolean hasSchemaRight(Schema schema)
See if this user has owner rights for the specified schema- Parameters:
schema
- the schema- Returns:
- true if the user has the rights
-
checkTableRight
public void checkTableRight(Table table, int rightMask)
Checks that this user has the given rights for the specified table.- Parameters:
table
- the tablerightMask
- the rights required- Throws:
DbException
- if this user does not have the required rights
-
hasTableRight
public boolean hasTableRight(Table table, int rightMask)
See if this user has the given rights for this database object.- Parameters:
table
- the database object, or null for schema-only checkrightMask
- the rights required- Returns:
- true if the user has the rights
-
getType
public int getType()
Description copied from class:DbObject
Get the object type.
-
getChildren
public java.util.ArrayList<DbObject> getChildren()
Description copied from class:DbObject
Get the list of dependent children (for tables, this includes indexes and so on).- Overrides:
getChildren
in classDbObject
- Returns:
- the list of children, or
null
-
removeChildrenAndResources
public void removeChildrenAndResources(SessionLocal session)
Description copied from class:DbObject
Delete all dependent children objects and resources of this object.- Specified by:
removeChildrenAndResources
in classDbObject
- Parameters:
session
- the session
-
-