Class 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.IEntity createUser​(net.enilink.komma.core.IEntityManager em, String username, String emailAddress)
      Creates a new user resource.
      static net.enilink.komma.core.IEntity createUser​(net.enilink.komma.core.IEntityManager em, String username, String emailAddress, String encodedPassword)
      Creates a new user resources.
      static String encodePassword​(String password)
      Encode a password for secure storage within a persistent database, sessions, etc.
      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.
      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.
      static List<net.enilink.komma.core.URI> getExternalIds​(Subject subject)
      Returns external IDs from the given subject.
      static net.enilink.komma.core.URI getMailboxURI​(String emailAddress)
      Returns a URI for an email address.
      static net.enilink.komma.core.URI getUserURI​(String username)
      Returns the user's URI for the given user name.
      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.
      static boolean hasUserWithName​(net.enilink.komma.core.IEntityManager em, String username)
      Checks if a user with the given username already exists within the system.
      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.
    • Constructor Detail

      • AccountHelper

        public AccountHelper()
    • Method Detail

      • createUser

        public static net.enilink.komma.core.IEntity createUser​(net.enilink.komma.core.IEntityManager em,
                                                                String username,
                                                                String emailAddress)
                                                         throws IllegalArgumentException
        Creates a new user resource.
        Parameters:
        em - The entity manager to use
        username - 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 IllegalArgumentException
        Creates a new user resources.
        Parameters:
        em - The entity manager to use
        username - The name of the user (nickname)
        emailAddress - The user's email address
        encodedPassword - 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 use
        username - The user's name.
        encodedPassword - The encoded password
        Returns:
        The user entity or else null if 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 use
        externalIds - The user's external IDs.
        Returns:
        The user entity or else null if 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 use
        emailAddress - The user's email address
        Returns:
        true if a user with the given email address already exists, else false.
      • 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 use
        username - The user's name.
        Returns:
        true if a user with the given name already exists, else false.
      • 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 data
        userId - The user ID
        externalIds - List of external IDs