com.atlassian.crowd.embedded.spi
Interface UserDao

All Known Subinterfaces:
InternalUserDao
All Known Implementing Classes:
UserDAOHibernate

public interface UserDao

Responsible for the persistence and retrieval of Users, PasswordCredentials and user attributes.


Method Summary
 User add(User user, PasswordCredential credential)
          Creates a new user with the given details and credentials.
 BatchResult<User> addAll(Set<UserTemplateWithCredentialAndAttributes> users)
          Bulk add of users using JDBC batch support.
 TimestampedUser findByName(long directoryId, String userName)
          Finds and returns the user with the given name and directory ID.
 UserWithAttributes findByNameWithAttributes(long directoryId, String userName)
          Finds and returns the user with attributes with the given name and directory ID.
 PasswordCredential getCredential(long directoryId, String userName)
          Returns the credential for the given user.
 List<PasswordCredential> getCredentialHistory(long directoryId, String userName)
          Returns the previous credentials for the given user, starting with the oldest.
 void remove(User user)
          Removes the user.
 void removeAllUsers(long directoryId, Set<String> userNames)
          Remove all the given users from directory.
 void removeAttribute(User user, String attributeName)
          Removes the attributes for the user with the given name.
 User rename(User user, String newName)
          Changes the user's name to the provided new name.
<T> List<T>
search(long directoryId, EntityQuery<T> query)
          Returns users matching the search query in the given directory, ordered by name.
 void storeAttributes(User user, Map<String,Set<String>> attributes)
          Adds or updates a user's attributes with the new Map of attribute values.
 User update(User user)
          Updates all the user properties of the user with the same directory and case-insensitive name.
 void updateCredential(User user, PasswordCredential credential, int maxCredentialHistory)
          Updates the credential (password) of the user with the same directory and case-insensitive name.
 

Method Detail

findByName

TimestampedUser findByName(long directoryId,
                           String userName)
                           throws UserNotFoundException
Finds and returns the user with the given name and directory ID.

Throws:
UserNotFoundException - if the user could not be found

findByNameWithAttributes

UserWithAttributes findByNameWithAttributes(long directoryId,
                                            String userName)
                                            throws UserNotFoundException
Finds and returns the user with attributes with the given name and directory ID.

Throws:
UserNotFoundException - if the user could not be found

getCredential

PasswordCredential getCredential(long directoryId,
                                 String userName)
                                 throws UserNotFoundException
Returns the credential for the given user. It will always be encrypted.

Throws:
UserNotFoundException - if the user could not be found

getCredentialHistory

List<PasswordCredential> getCredentialHistory(long directoryId,
                                              String userName)
                                              throws UserNotFoundException
Returns the previous credentials for the given user, starting with the oldest. May be an empty list if there are no historical credentials.

Throws:
UserNotFoundException - if the user could not be found

add

User add(User user,
         PasswordCredential credential)
         throws UserAlreadyExistsException,
                IllegalArgumentException,
                DirectoryNotFoundException
Creates a new user with the given details and credentials. The user details cannot be null, but the credential can be.

Parameters:
user - the user to create
credential - the encrypted password for the user, which may be null if the user's password is not yet available
Returns:
the newly created user
Throws:
UserAlreadyExistsException - if a user with the same directory and name (case-insensitive) already exists
IllegalArgumentException - if the user name, directory or any details are null, or if the credential is not encrypted
DirectoryNotFoundException

storeAttributes

void storeAttributes(User user,
                     Map<String,Set<String>> attributes)
                     throws UserNotFoundException
Adds or updates a user's attributes with the new Map of attribute values. The attributes map represents new or updated attributes and does not replace existing attributes unless the key of an attribute matches the key of an existing attribute. Attributes with values of empty sets in the attributes parameter are removed from the user.

Parameters:
user - the user to store attributes for
attributes - new or updated attributes (attributes that don't need changing should not appear in this Map).
Throws:
UserNotFoundException - user with supplied username does not exist.

update

User update(User user)
            throws UserNotFoundException,
                   IllegalArgumentException
Updates all the user properties of the user with the same directory and case-insensitive name.

Parameters:
user - the user details, which should have the same name as the user to modify
Returns:
the updated user
Throws:
UserNotFoundException - if there is no user with the same name (case-insensitive) and directory as the user provided
IllegalArgumentException - if the user name, directory or any details are null

updateCredential

void updateCredential(User user,
                      PasswordCredential credential,
                      int maxCredentialHistory)
                      throws UserNotFoundException,
                             IllegalArgumentException
Updates the credential (password) of the user with the same directory and case-insensitive name. The credential must be encrypted.

Parameters:
user - the user whose password will be modified
Throws:
UserNotFoundException - if there is no user with the same name (case-insensitive) and directory as the user provided
IllegalArgumentException - if the credential is null or not encrypted

rename

User rename(User user,
            String newName)
            throws UserNotFoundException,
                   UserAlreadyExistsException,
                   IllegalArgumentException
Changes the user's name to the provided new name.

Parameters:
user - the user to rename
newName - the new name of the user
Returns:
the updated user
Throws:
UserNotFoundException - if the user cannot be found
UserAlreadyExistsException - if the new name is already used
IllegalArgumentException - if the new name is null

removeAttribute

void removeAttribute(User user,
                     String attributeName)
                     throws UserNotFoundException
Removes the attributes for the user with the given name. Does nothing if the attribute doesn't exist.

Parameters:
user - the user whose attribute will be removed
attributeName - the name of the attribute to be removed
Throws:
UserNotFoundException - if the user cannot be found

remove

void remove(User user)
            throws UserNotFoundException
Removes the user.

Parameters:
user - the user to remove
Throws:
UserNotFoundException - if the user does not exist

search

<T> List<T> search(long directoryId,
                   EntityQuery<T> query)
Returns users matching the search query in the given directory, ordered by name. Returns an empty list if no users match.

Type Parameters:
T - the type of objects to return, which is normally either User or String
Parameters:
directoryId - the ID of the directory to search
query - the search query
Returns:
the list of matching users, or an empty list if no users match

addAll

BatchResult<User> addAll(Set<UserTemplateWithCredentialAndAttributes> users)
Bulk add of users using JDBC batch support.

Parameters:
users - to be added
Returns:
a list of Users that failed to be added

removeAllUsers

void removeAllUsers(long directoryId,
                    Set<String> userNames)
Remove all the given users from directory.

Parameters:
directoryId - the ID of the directory to remove users from
userNames - set of users to be removed


Copyright © 2012 Atlassian. All Rights Reserved.