com.atlassian.core.user
Class UserUtils

java.lang.Object
  extended bycom.atlassian.core.user.UserUtils

public class UserUtils
extends java.lang.Object

A utility class for operating on users.

See Also:
GroupUtils

Constructor Summary
UserUtils()
           
 
Method Summary
static void changePassword(com.opensymphony.user.User user, java.lang.String password)
          Changes the password for a given user.
static com.opensymphony.user.User createUser(java.lang.String username, java.lang.String email)
          This method is used when a user is created automatically, or by another user (for example an administrator).
static com.opensymphony.user.User createUser(java.lang.String username, java.lang.String email, java.lang.String fullname)
          This method is used when a user is created automatically, or by another user (for example an administrator).
static com.opensymphony.user.User createUser(java.lang.String username, java.lang.String password, java.lang.String email, java.lang.String fullname)
          Generic method which actually creates users, and fires the given event.
static com.opensymphony.user.User createUser(java.lang.String username, java.lang.String password, java.lang.String email, java.lang.String fullname, java.util.Collection groups)
          Creates a new user with given attributes and associates the user with given collection of groups.
static boolean existsUser(java.lang.String username)
          Checks if a user with given username exists.
static java.util.Collection getAllUsers()
           
static com.opensymphony.user.User getUser(java.lang.String username)
          Retrieves and returns the user by given username.
static com.opensymphony.user.User getUserByEmail(java.lang.String email)
          Return the first user found that matches thie email address.
static java.util.Collection getUsers(java.util.Collection groups)
          Get a list of users in a set of groups (either Group objects or String group names)
static java.util.List getUsersByEmail(java.lang.String email)
          Finds the users by the given e-mail address.
static void removeUser(com.opensymphony.user.User user)
          Removes the given user.
static java.lang.String resetPassword(com.opensymphony.user.User user)
          For a user, create a new password, and dispatch an 'forgot password' event
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserUtils

public UserUtils()
Method Detail

getUser

public static com.opensymphony.user.User getUser(java.lang.String username)
                                          throws com.opensymphony.user.EntityNotFoundException
Retrieves and returns the user by given username. If such user does not exist throws EntityNotFoundException.

Parameters:
username - usename to lookup
Returns:
user looked up by the given username
Throws:
com.opensymphony.user.EntityNotFoundException - if user with given username not found

existsUser

public static boolean existsUser(java.lang.String username)
Checks if a user with given username exists. Returns true if such user exists, false otherwise.

Parameters:
username - username to look up
Returns:
true if user found, false otherwise

getAllUsers

public static java.util.Collection getAllUsers()

getUserByEmail

public static com.opensymphony.user.User getUserByEmail(java.lang.String email)
                                                 throws com.opensymphony.user.EntityNotFoundException
Return the first user found that matches thie email address. There may be many users with the same email address, and this method should not be used to return a single user.

The email address is matched case insensitive. This loops through all users, and so is a O(N) operation.

Parameters:
email - user email
Returns:
The first user that matches the email address
Throws:
com.opensymphony.user.EntityNotFoundException - if no user is found.

getUsersByEmail

public static java.util.List getUsersByEmail(java.lang.String email)
Finds the users by the given e-mail address. E-mail address look-up is done case insensitively. Leading or trailing spaces in the given e-mail address are trimmed before look up.

Parameters:
email - e-mail address
Returns:
always returns a list of users found (even if empty)

getUsers

public static java.util.Collection getUsers(java.util.Collection groups)
Get a list of users in a set of groups (either Group objects or String group names)

Parameters:
groups - collection of groups (either Group objects or String group names)
Returns:
a collection of User objects

createUser

public static com.opensymphony.user.User createUser(java.lang.String username,
                                                    java.lang.String email)
                                             throws com.opensymphony.user.DuplicateEntityException,
                                                    com.opensymphony.user.ImmutableException
This method is used when a user is created automatically, or by another user (for example an administrator). Should not be used for users signing themselves up.

This method will also generate an automatic random password for the user.

Parameters:
username - username
email - user's e-mail address
Returns:
newly created user
Throws:
com.opensymphony.user.DuplicateEntityException - if user already exists
com.opensymphony.user.ImmutableException - if setting the user's password fails

createUser

public static com.opensymphony.user.User createUser(java.lang.String username,
                                                    java.lang.String email,
                                                    java.lang.String fullname)
                                             throws com.opensymphony.user.DuplicateEntityException,
                                                    com.opensymphony.user.ImmutableException
This method is used when a user is created automatically, or by another user (for example an administrator). Should not be used for users signing themselves up.

This method will also generate an automatic random password for the user.

Parameters:
username - username
email - e-mail address
fullname - user's full name
Returns:
newly created user
Throws:
com.opensymphony.user.DuplicateEntityException - if user already exists
com.opensymphony.user.ImmutableException - if setting the user's password fails

createUser

public static com.opensymphony.user.User createUser(java.lang.String username,
                                                    java.lang.String password,
                                                    java.lang.String email,
                                                    java.lang.String fullname)
                                             throws com.opensymphony.user.DuplicateEntityException,
                                                    com.opensymphony.user.ImmutableException
Generic method which actually creates users, and fires the given event.

Parameters:
username - username
password - password
email - e-mail address
fullname - user's full name
Returns:
newly created user
Throws:
com.opensymphony.user.DuplicateEntityException - if user already exists
com.opensymphony.user.ImmutableException - if setting the user's password fails

createUser

public static com.opensymphony.user.User createUser(java.lang.String username,
                                                    java.lang.String password,
                                                    java.lang.String email,
                                                    java.lang.String fullname,
                                                    java.util.Collection groups)
                                             throws com.opensymphony.user.DuplicateEntityException,
                                                    com.opensymphony.user.ImmutableException
Creates a new user with given attributes and associates the user with given collection of groups.

Parameters:
username - username
password - passwod
email - e-mail address
fullname - user's full name
groups - group names (String objects) the user will belong to
Returns:
newly created user
Throws:
com.opensymphony.user.DuplicateEntityException - if user already exists
com.opensymphony.user.ImmutableException - if setting the user's password fails

removeUser

public static void removeUser(com.opensymphony.user.User user)
                       throws java.lang.Exception
Removes the given user. A ImmutableException is thrown if given user cannot be removed.

Parameters:
user - user to remove
Throws:
java.lang.Exception - if user cannot be removed

resetPassword

public static java.lang.String resetPassword(com.opensymphony.user.User user)
                                      throws com.opensymphony.user.ImmutableException
For a user, create a new password, and dispatch an 'forgot password' event

Parameters:
user - The user whose password needs to be reset.
Returns:
new password
Throws:
com.opensymphony.user.ImmutableException - if password cannot be changed

changePassword

public static void changePassword(com.opensymphony.user.User user,
                                  java.lang.String password)
                           throws com.opensymphony.user.ImmutableException
Changes the password for a given user.

Parameters:
user - user to change password for
password - new password
Throws:
com.opensymphony.user.ImmutableException - if password cannot be changed


Copyright © 2008 Atlassian Pty Ltd. All Rights Reserved.