Package com.logicaldoc.core.security.user

# Class HibernateUserDAO

java.lang.Object
com.logicaldoc.core.HibernatePersistentObjectDAO<User>
com.logicaldoc.core.security.user.HibernateUserDAO

All Implemented Interfaces:
  `PersistentObjectDAO<User>`, `UserDAO`

@Repository("userDAO") public class HibernateUserDAO extends HibernatePersistentObjectDAO<User> implements UserDAO
Hibernate implementation of `UserDAO`

Since:
  3.0
Author:
  Marco Meschieri - LogicalDOC

## Field Summary

### Fields inherited from interface com.logicaldoc.core.PersistentObjectDAO

`ENTITY`

## Method Summary

Modifier and Type
Method
Description
`void`
`checkPasswordCompliance(User user)`
Checks if the user's password complies the current quality criteria
`long`
`countGuests(Long tenantId)`
Counts the total number of guest users
`long`
`countRegulars(Long tenantId)`
Counts the total number of regular users
`void`
`delete(long userId, int code)`
This method deletes an entity and you can give a deletion code
`void`
`delete(long userId, UserHistory transaction)`
This method deletes the user object and insert a new user history entry.
`User`
`findAdminUser(String tenantName)`
Retrieve the administrator for the given tenant.
`Set<User>`
`findByGroup(long groupId)`
Retrieves the users belonging to a given group.
`User`
`findById(long id)`
This method finds an entity by ID
`List<User>`
`findByLikeUsername(String username)`
This method finds an User by username.
`List<User>`
`findByName(String name)`
This method finds an User by name.
`User`
`findByUsername(String username)`
This method finds an User by its username.
`List<User>`
`findByUsernameAndName(String username, String name)`
This method finds an User by username and name.
`User`
`findByUsernameIgnoreCase(String username)`
This method finds an User by its username.
`Map<String,Generic>`
`findUserSettings(long userId, String namePrefix)`
Retrieves the settings for a user.
`User`
`getUser(String username)`
Depending on the global setting, it invokes findByUsername or findByUsernameIgnoreCase
`UserHistoryDAO`
`getUserHistoryDAO()`
`static boolean`
`ignoreCaseLogin()`
`void`
`init()`
`void`
`initialize(User user)`
Doesn't do anything by default
`boolean`
`isInactive(String username)`
Checks if a user is inactive, that is a user without interactions in the last X days after it has last enabled.
`boolean`
`isPasswordExpired(String username)`
Is password expired.
`void`
`setConfig(ContextProperties config)`
`void`
`setGenericDAO(GenericDAO genericDAO)`
`void`
`setPasswordHistoryDAO(PasswordHistoryDAO passwordHistoryDAO)`
`void`
`setUserHistoryDAO(UserHistoryDAO userHistoryDAO)`
`void`
`store(User user)`
This method persists the entity object
`void`
`store(User user, UserHistory transaction)`
This method persists the user object and insert a new user history entry.

### Methods inherited from class com.logicaldoc.core.HibernatePersistentObjectDAO

`bulkUpdate, count, deleteAll, evict, evict, findByObjectQuery, findByQuery, findByQuery, findByWhere, findIdsByWhere, getDatabaseMetadata, jdbcUpdate, jdbcUpdate, query, queryForDouble, queryForDouble, queryForInt, queryForInt, queryForList, queryForList, queryForList, queryForLong, queryForLong, queryForObject, queryForObject, queryForResultSet, queryForString, queryForString, setSessionFactory`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface com.logicaldoc.core.PersistentObjectDAO

`bulkUpdate, count, count, count, delete, deleteAll, deleteAll, evict, evict, findAll, findAll, findAllIds, findAllIds, findById, findByObjectQuery, findByQuery, findByQuery, findByWhere, findByWhere, findIdsByWhere, findIdsByWhere, getDatabaseMetadata, getDbms, initialize, isMariaDB, isMySQL, isOracle, isPostgreSQL, isSQLServer, jdbcUpdate, jdbcUpdate, query, query, queryForDouble, queryForDouble, queryForInt, queryForInt, queryForList, queryForList, queryForList, queryForLong, queryForLong, queryForObject, queryForObject, queryForResultSet, queryForString, queryForString`

## Method Details

### ignoreCaseLogin

public static boolean ignoreCaseLogin()

### findByName

public List<User> findByName(String name) throws PersistenceException
Description copied from interface: `UserDAO`
This method finds an User by name.

Specified by:
  `findByName` in interface `UserDAO`
Parameters:
  `name` - The name of wanted User.
Returns:
  Collection of selected users.
Throws:
  `PersistenceException` - Error in the database

### findByUsername

public User findByUsername(String username) throws PersistenceException
Description copied from interface: `UserDAO`
This method finds an User by its username. The search is case sensitive.

Specified by:
  `findByUsername` in interface `UserDAO`
Parameters:
  `username` - username of wanted User.
Returns:
  Wanted User or null if user doesn't exist.
Throws:
  `PersistenceException` - Error in the data layer

### findByUsernameIgnoreCase

public User findByUsernameIgnoreCase(String username) throws PersistenceException
Description copied from interface: `UserDAO`
This method finds an User by its username. The search is case insensitive.

Specified by:
  `findByUsernameIgnoreCase` in interface `UserDAO`
Parameters:
  `username` - username of wanted User.
Returns:
  Wanted User or null if user doesn't exist.
Throws:
  `PersistenceException` - Error in the data layer

### findByLikeUsername

public List<User> findByLikeUsername(String username) throws PersistenceException
Description copied from interface: `UserDAO`
This method finds an User by username.

Specified by:
  `findByLikeUsername` in interface `UserDAO`
Parameters:
  `username` - The username of wanted User.
Returns:
  Collection of selected users.
Throws:
  `PersistenceException` - Error in the database

### findByUsernameAndName

public List<User> findByUsernameAndName(String username, String name) throws PersistenceException
Description copied from interface: `UserDAO`
This method finds an User by username and name.

Specified by:
  `findByUsernameAndName` in interface `UserDAO`
Parameters:
  `username` - The username of wanted user
  `name` - The name of wanted user
Returns:
  Collection of selected users
Throws:
  `PersistenceException` - Error in the database

### checkPasswordCompliance

public void checkPasswordCompliance(User user) throws PasswordWeakException, PersistenceException
Description copied from interface: `UserDAO`
Checks if the user's password complies the current quality criteria

Specified by:
  `checkPasswordCompliance` in interface `UserDAO`
Parameters:
  `user` - The user to check
Throws:
  `PasswordWeakException` - Raised when the password does not comply with the quality criteria
  `PersistenceException` - Error in the database

### store

public void store(User user) throws PasswordAlreadyUsedException, PersistenceException
Description copied from interface: `PersistentObjectDAO`
This method persists the entity object

Specified by:
  `store` in interface `PersistentObjectDAO<User>`
Specified by:
  `store` in interface `UserDAO`
Overrides:
  `store` in class `HibernatePersistentObjectDAO<User>`
Parameters:
  `user` - entity to be stored
Throws:
  `PersistenceException` - raised in case of errors in the database
  `PasswordAlreadyUsedException`

### store

public void store(User user, UserHistory transaction) throws PasswordAlreadyUsedException, PersistenceException
Description copied from interface: `UserDAO`
This method persists the user object and insert a new user history entry.

Specified by:
  `store` in interface `UserDAO`
Parameters:
  `user` - the user to store
  `transaction` - entry to log the event
Throws:
  `PersistenceException` - error at database level
  `PasswordAlreadyUsedException`

### isPasswordExpired

public boolean isPasswordExpired(String username)
Description copied from interface: `UserDAO`
Is password expired.

Specified by:
  `isPasswordExpired` in interface `UserDAO`
Parameters:
  `username` - Username of the User to be validated.
Returns:
  True if the password is expired

### isInactive

public boolean isInactive(String username) throws PersistenceException
Description copied from interface: `UserDAO`
Checks if a user is inactive, that is a user without interactions in the last X days after it has last enabled. We look at the `User.getMaxInactivity()` first and then we fallback to the general parameter security.user.maxinactivity

Specified by:
  `isInactive` in interface `UserDAO`
Parameters:
  `username` - identifier of the user
Returns:
  the last interaction time
Throws:
  `PersistenceException` - Error in the database

### countRegulars

public long countRegulars(Long tenantId) throws PersistenceException
Description copied from interface: `UserDAO`
Counts the total number of regular users

Specified by:
  `countRegulars` in interface `UserDAO`
Parameters:
  `tenantId` - identifier of the tenant
Returns:
  total number of regular users
Throws:
  `PersistenceException` - Error in the database

### countGuests

public long countGuests(Long tenantId) throws PersistenceException
Description copied from interface: `UserDAO`
Counts the total number of guest users

Specified by:
  `countGuests` in interface `UserDAO`
Parameters:
  `tenantId` - identifier of the tenant
Returns:
  total number of guest users
Throws:
  `PersistenceException` - Error in the database

### delete

public void delete(long userId, int code) throws PersistenceException
Description copied from interface: `PersistentObjectDAO`
This method deletes an entity and you can give a deletion code

Specified by:
  `delete` in interface `PersistentObjectDAO<User>`
Overrides:
  `delete` in class `HibernatePersistentObjectDAO<User>`
Parameters:
  `userId` - ID of the entity which should be deleted
  `code` - Deletion code
Throws:
  `PersistenceException` - raised in case of errors in the database

### delete

public void delete(long userId, UserHistory transaction) throws PersistenceException
Description copied from interface: `UserDAO`
This method deletes the user object and insert a new user history entry.

Specified by:
  `delete` in interface `UserDAO`
Parameters:
  `userId` - The id of the user to delete
  `transaction` - entry to log the event
Throws:
  `PersistenceException` - error at database level

### getUserHistoryDAO

public UserHistoryDAO getUserHistoryDAO()

### setUserHistoryDAO

public void setUserHistoryDAO(UserHistoryDAO userHistoryDAO)

### initialize

public void initialize(User user) throws PersistenceException
Description copied from class: `HibernatePersistentObjectDAO`
Doesn't do anything by default

Specified by:
  `initialize` in interface `PersistentObjectDAO<User>`
Overrides:
  `initialize` in class `HibernatePersistentObjectDAO<User>`
Parameters:
  `user` - The entity to be initialised
Throws:
  `PersistenceException` - Error in the database

### findUserSettings

public Map<String,Generic> findUserSettings(long userId, String namePrefix) throws PersistenceException
Description copied from interface: `UserDAO`
Retrieves the settings for a user. The settings are stored as Generics of type usersetting.

Specified by:
  `findUserSettings` in interface `UserDAO`
Parameters:
  `userId` - Identifier of the user
  `namePrefix` - Name prefix of the property (optional)
Returns:
  The map setting_name-generic
Throws:
  `PersistenceException` - Error in the database

### setGenericDAO

public void setGenericDAO(GenericDAO genericDAO)

### findAdminUser

public User findAdminUser(String tenantName) throws PersistenceException
Description copied from interface: `UserDAO`
Retrieve the administrator for the given tenant. The general rule is that the administrator's username is:

1. admin if the tenant is default
2. adminTenantname in all other cases

Specified by:
  `findAdminUser` in interface `UserDAO`
Parameters:
  `tenantName` - name of the tenant
Returns:
  the user to administrate the tenant
Throws:
  `PersistenceException` - Error in the database

### findByGroup

public Set<User> findByGroup(long groupId) throws PersistenceException
Description copied from interface: `UserDAO`
Retrieves the users belonging to a given group.

Specified by:
  `findByGroup` in interface `UserDAO`
Parameters:
  `groupId` - Identifier of the group
Returns:
  the set of groups
Throws:
  `PersistenceException` - Error in the database

### findById

public User findById(long id) throws PersistenceException
Description copied from interface: `PersistentObjectDAO`
This method finds an entity by ID

Specified by:
  `findById` in interface `PersistentObjectDAO<User>`
Overrides:
  `findById` in class `HibernatePersistentObjectDAO<User>`
Parameters:
  `id` - ID of the entity
Returns:
  Entity with given ID
Throws:
  `PersistenceException` - raised in case of errors in the database

### getUser

public User getUser(String username) throws PersistenceException
Description copied from interface: `UserDAO`
Depending on the global setting, it invokes findByUsername or findByUsernameIgnoreCase

Specified by:
  `getUser` in interface `UserDAO`
Parameters:
  `username` - The username of the user
Returns:
  The found user
Throws:
  `PersistenceException` - Error in the data layer

### setPasswordHistoryDAO

public void setPasswordHistoryDAO(PasswordHistoryDAO passwordHistoryDAO)

### setConfig

public void setConfig(ContextProperties config)

### init

@PostConstruct public void init()