Class AccountHelper
- java.lang.Object
-
- net.enilink.platform.security.auth.AccountHelper
-
public class AccountHelper extends Object
Helper class for managing user accounts.
-
-
Constructor Summary
Constructors Constructor Description AccountHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static net.enilink.komma.core.IEntitycreateUser(net.enilink.komma.core.IEntityManager em, String username, String emailAddress)Creates a new user resource.static net.enilink.komma.core.IEntitycreateUser(net.enilink.komma.core.IEntityManager em, String username, String emailAddress, String encodedPassword)Creates a new user resources.static StringencodePassword(String password)Encode a password for secure storage within a persistent database, sessions, etc.static net.enilink.komma.core.IEntityfindUser(net.enilink.komma.core.IEntityManager em, String username, String encodedPassword)Checks if a user with the given username and password exists within the system.static net.enilink.komma.core.IEntityfindUser(net.enilink.komma.core.IEntityManager em, List<net.enilink.komma.core.URI> externalIds)Checks if a user with the given external IDs exists within the system.static List<net.enilink.komma.core.URI>getExternalIds(Subject subject)Returns external IDs from the given subject.static net.enilink.komma.core.URIgetMailboxURI(String emailAddress)Returns a URI for an email address.static net.enilink.komma.core.URIgetUserURI(String username)Returns the user's URI for the given user name.static booleanhasUserWithEmail(net.enilink.komma.core.IEntityManager em, String emailAddress)Checks if a user with the given -mail address already exists within the system.static booleanhasUserWithName(net.enilink.komma.core.IEntityManager em, String username)Checks if a user with the given username already exists within the system.static voidlinkExternalIds(net.enilink.komma.core.IEntityManager em, net.enilink.komma.core.IReference userId, List<net.enilink.komma.core.URI> externalIds)Associates a user ID with one ore more external IDs.
-
-
-
Method Detail
-
createUser
public static net.enilink.komma.core.IEntity createUser(net.enilink.komma.core.IEntityManager em, String username, String emailAddress) throws IllegalArgumentExceptionCreates a new user resource.- Parameters:
em- The entity manager to useusername- The name of the user (nickname)emailAddress- The user's email address- Returns:
- The user resource
- Throws:
IllegalArgumentException- If the user with the given id already exists in the database.
-
createUser
public static net.enilink.komma.core.IEntity createUser(net.enilink.komma.core.IEntityManager em, String username, String emailAddress, String encodedPassword) throws IllegalArgumentExceptionCreates a new user resources.- Parameters:
em- The entity manager to useusername- The name of the user (nickname)emailAddress- The user's email addressencodedPassword- The already encoded password- Returns:
- The user resource
- Throws:
IllegalArgumentException- If the user with the given id already exists in the database.
-
encodePassword
public static String encodePassword(String password)
Encode a password for secure storage within a persistent database, sessions, etc.- Parameters:
password- The password to encode- Returns:
- A password hash generated with SHA-1 or a comparable algorithm
-
findUser
public static net.enilink.komma.core.IEntity findUser(net.enilink.komma.core.IEntityManager em, String username, String encodedPassword)Checks if a user with the given username and password exists within the system.- Parameters:
em- The entity manager to useusername- The user's name.encodedPassword- The encoded password- Returns:
- The user entity or else
nullif the user was not found.
-
findUser
public static net.enilink.komma.core.IEntity findUser(net.enilink.komma.core.IEntityManager em, List<net.enilink.komma.core.URI> externalIds)Checks if a user with the given external IDs exists within the system.- Parameters:
em- The entity manager to useexternalIds- The user's external IDs.- Returns:
- The user entity or else
nullif the user was not found.
-
getExternalIds
public static List<net.enilink.komma.core.URI> getExternalIds(Subject subject)
Returns external IDs from the given subject. The external IDs are constructed from OpenID, Kerberos or other principals contained in the subject.- Parameters:
subject- The subject with principals for external IDs.- Returns:
- List of extracted external IDs.
-
getMailboxURI
public static net.enilink.komma.core.URI getMailboxURI(String emailAddress)
Returns a URI for an email address.- Parameters:
emailAddress- An email address- Returns:
- A URI with the mailto: scheme
-
getUserURI
public static net.enilink.komma.core.URI getUserURI(String username)
Returns the user's URI for the given user name.- Parameters:
username- The user's name.- Returns:
- The user's URI.
-
hasUserWithEmail
public static boolean hasUserWithEmail(net.enilink.komma.core.IEntityManager em, String emailAddress)Checks if a user with the given -mail address already exists within the system.- Parameters:
em- The entity manager to useemailAddress- The user's email address- Returns:
trueif a user with the given email address already exists, elsefalse.
-
hasUserWithName
public static boolean hasUserWithName(net.enilink.komma.core.IEntityManager em, String username)Checks if a user with the given username already exists within the system.- Parameters:
em- The entity manager to useusername- The user's name.- Returns:
trueif a user with the given name already exists, elsefalse.
-
linkExternalIds
public static void linkExternalIds(net.enilink.komma.core.IEntityManager em, net.enilink.komma.core.IReference userId, List<net.enilink.komma.core.URI> externalIds)Associates a user ID with one ore more external IDs.- Parameters:
em- The entity manager for storing the datauserId- The user IDexternalIds- List of external IDs
-
-