Class UserManager

  • All Implemented Interfaces:
    ItemLifecycleListener, java.io.Serializable

    public class UserManager
    extends Manager
    The manager for all users and user - related items.

    Here you can create and search employees, customer, user groups, addresses and titles.

    See Also:
    Serialized Form
    • Field Detail

      • BEAN_NAME

        public static final java.lang.String BEAN_NAME
        Identifier of this manager used at core-spring.xml spring configuration.
        See Also:
        Constant Field Values
      • FIELD_NAME

        public static final java.lang.String FIELD_NAME
        Search property constant denoting the address field name to search in.
        See Also:
        Constant Field Values
      • SEARCH_PATTERN

        public static final java.lang.String SEARCH_PATTERN
        Search property constant denoting the address field value to search for.
        See Also:
        Constant Field Values
      • CONFIG_ALLOW_CUSTOMER_ADMIN

        public static final java.lang.String CONFIG_ALLOW_CUSTOMER_ADMIN
        See Also:
        Constant Field Values
      • ALLOW_CUSTOMER_ADMIN_DEFAULT

        public static final boolean ALLOW_CUSTOMER_ADMIN_DEFAULT
        See Also:
        Constant Field Values
    • Constructor Detail

      • UserManager

        public UserManager()
    • Method Detail

      • init

        public void init()
        Description copied from class: Manager
        called once for each tenant, so this method fits best to perform some initialization stuff
        Overrides:
        init in class Manager
      • getInstance

        public static UserManager getInstance()
        Gets the instance of this manager.
        Returns:
        instance of this manager
      • notifyItemRemoval

        protected void notifyItemRemoval​(SessionContext ctx,
                                         Item item)
        Superclass method overridden to avoid calls to ejb layer.
        Overrides:
        notifyItemRemoval in class Manager
        Parameters:
        ctx - the currency session context
        item - the item which is going to be removed
        Since:
        2.10
      • getUserTypeCode

        protected java.lang.String getUserTypeCode()
        Gets the code of the User composed type.
      • getUserGroupTypeCode

        protected java.lang.String getUserGroupTypeCode()
      • getTitleTypeCode

        protected java.lang.String getTitleTypeCode()
      • getAddressTypeCode

        protected java.lang.String getAddressTypeCode()
      • getCustomerType

        protected ComposedType getCustomerType()
      • getEmployeeType

        protected ComposedType getEmployeeType()
      • getAllUsers

        public java.util.Collection getAllUsers()
        Returns all users (excluding all UserGroups).
        Returns:
        a Collection of all users.
      • findUsers

        public java.util.Collection findUsers​(ComposedType type,
                                              java.lang.String uid,
                                              java.lang.String name,
                                              java.lang.String description)
        Searches for specific users.
        Parameters:
        type - The ComposedType which restricts the search or null to search all 'User' types
        uid - The uid to search or null to search all
        name - The name to search or null to search all
        description - The description to search or null to search all
        Returns:
        collection with users, which fulfills the criteria
      • findUsers

        public java.util.Collection<? extends User> findUsers​(ComposedType type,
                                                              java.lang.String uid,
                                                              java.lang.String name,
                                                              java.lang.String description,
                                                              boolean disableRestrictions)
        Searches for specific users.
        Parameters:
        type - The ComposedType which restricts the search or null to search all 'User' types
        uid - The uid to search or null to search all
        name - The name to search or null to search all
        description - The description to search or null to search all
        disableRestrictions - will search restrictions be disabled?
        Returns:
        collection with users, which fulfills the criteria
      • getAllPrincipals

        public java.util.Collection getAllPrincipals()
        Returns absolute every user and usergroup stored in the system. But be warned: this method may be inperformant, especially in larger setups.
        Returns:
        a Collection of all principals.
      • getAllCustomers

        public java.util.Collection getAllCustomers()
        Finds all customer users. Please note that this does not include customer subclasses but just the hybris platform core customer user type!
        Returns:
        a Collection of all customers.
      • getAllEmployees

        public java.util.Collection getAllEmployees()
        Finds all employees. Please note that this does not include employee subclasses but just the hybris platform core employee user type!
        Returns:
        a Collection of all employees.
      • getAllUserGroups

        public java.util.Collection getAllUserGroups()
        Finds all user groups. Please note that this does not include usergroup subclasses but just the hybris platform core usergroup user type!
        Returns:
        a Collection of all user groups.
      • findUserGroups

        public java.util.Collection findUserGroups​(ComposedType type,
                                                   java.lang.String groupId,
                                                   java.lang.String name,
                                                   java.lang.String description)
        Searches for specific users groups.
        Parameters:
        type - The ComposedType which restricts the search or null to search all 'UserGroup' types
        groupId - The groupid to search or null to search all
        name - The name to search or null to search all
        description - The description to search or null to search all
        Returns:
        collection with user groups, which fulfills the criteria
      • findUserGroups

        public java.util.Collection<? extends UserGroup> findUserGroups​(ComposedType type,
                                                                        java.lang.String groupId,
                                                                        java.lang.String name,
                                                                        java.lang.String description,
                                                                        boolean disableRestrictions)
        Searches for specific users groups.
        Parameters:
        type - The ComposedType which restricts the search or null to search all 'UserGroup' types
        groupId - The groupid to search or null to search all
        name - The name to search or null to search all
        description - The description to search or null to search all
        disableRestrictions - will search restrictions be disabled?
        Returns:
        collection with user groups, which fulfills the criteria
      • getAllTitles

        public java.util.Collection getAllTitles()
        Returns all titles.
        Returns:
        a Collection of all titles.
      • getAllAddresses

        public java.util.Collection getAllAddresses()
        Returns all addresses.
        Returns:
        a Collection of all addresses.
      • getUserGroupByGroupID

        public UserGroup getUserGroupByGroupID​(java.lang.String groupID)
                                        throws JaloItemNotFoundException
        Finds a user group by its login name.
        Returns:
        the UserGroup with the specified ID.
        Throws:
        JaloItemNotFoundException - if there is no UserGroup with the specified ID.
      • createCustomer

        public Customer createCustomer​(PK pk,
                                       java.lang.String login)
                                throws ConsistencyCheckException
        Creates a new Customer.
        Parameters:
        pk - the pk for the new item; it will be equipped with type code additionally (-)
        Returns:
        the new Customer
        Throws:
        ConsistencyCheckException - if this login name is already used
      • createEmployee

        public Employee createEmployee​(PK pk,
                                       java.lang.String login)
                                throws ConsistencyCheckException
        Creates a new Employee.
        Parameters:
        pk - the pk for the new item; it will be equipped with type code additionally (-)
        Returns:
        the new Employee
        Throws:
        ConsistencyCheckException - if this login name is already used
      • createUserGroup

        public UserGroup createUserGroup​(PK pkBase,
                                         java.lang.String groupId)
                                  throws ConsistencyCheckException
        Creates a new UserGroup.
        Parameters:
        pkBase - the pk for the new item; it will be equipped with type code additionally (-)
        groupId - the ID of the new UserGroup
        Returns:
        the new UserGroup
        Throws:
        ConsistencyCheckException - if this login name is already used
      • createUser

        public User createUser​(PK pk,
                               java.lang.String uid)
                        throws ConsistencyCheckException
        Creates a new User.
        Parameters:
        pk - the pk for the new item; it will be equipped with type code additionally (-)
        Returns:
        the new User
        Throws:
        ConsistencyCheckException - if this login name is already used
      • createUser

        public User createUser​(PK pkBase,
                               java.lang.String userID,
                               ComposedType type)
                        throws ConsistencyCheckException
        Creates a new User with a specified user type.
        Parameters:
        pkBase - the pk for the new item; it will be equipped with type code additionally (-)
        type - the item type of the new user item
        Returns:
        the new User
        Throws:
        ConsistencyCheckException - if this login name is already used
      • createTitle

        public Title createTitle​(PK pkBase,
                                 java.lang.String code)
                          throws ConsistencyCheckException
        Creates a new Title.
        Parameters:
        pkBase - the pk for the new item; it will be equipped with type code additionally (-)
        code - the code.
        Returns:
        the new Title
        Throws:
        ConsistencyCheckException - if the code is already in use.
      • getTitleByCode

        public Title getTitleByCode​(java.lang.String code)
                             throws JaloItemNotFoundException
        Returns the Title with the specified code.
        Parameters:
        code - the searched code
        Returns:
        the Title with the specified code
        Throws:
        JaloItemNotFoundException - if there is no Title with the specified code
      • getAdminEmployee

        public Employee getAdminEmployee()
        Returns the admin employee. Nevertheless there may be multiple admin employees; these are all members of the admin user group.
        Returns:
        the admin employee
        Throws:
        JaloInternalException - if admin can not be found
      • isAdmin

        public boolean isAdmin​(User user)
      • isAdmin

        public boolean isAdmin​(Employee employee)
      • isAdmin

        public boolean isAdmin​(Customer customer)
      • isCustomersAllowedAsAdmin

        public static boolean isCustomersAllowedAsAdmin()
      • getAnonymousCustomer

        public Customer getAnonymousCustomer()
        Returns the anonymous customer.
        Returns:
        the anonymous customer
        Throws:
        JaloInternalException - if anonymous can not be found
      • getAdminUserGroup

        public UserGroup getAdminUserGroup()
        Returns the admin user group. All members automatically have admin permissions.
        Returns:
        the admin user group
      • getAllAddresses

        public java.util.Collection getAllAddresses​(Item owner)
        Returns all address of the given owner.
        Parameters:
        owner - the Item whose addresses will be returned.
        Returns:
        a Collection of all address of the given owner.
      • createAddress

        public Address createAddress​(Item item)
        Creates address for given item.
        Parameters:
        item - - for this item address will be created
        Returns:
        created address
      • createAddress

        public Address createAddress​(PK pkBase,
                                     Item item,
                                     boolean asCopy)
        Creates address for given item.
        Parameters:
        item - - for this item address will be created
        Returns:
        created address
      • createAddress

        public Address createAddress​(PK pkBase,
                                     Item item)
        Creates address for given item.
        Parameters:
        item - - for this item address will be created
        Returns:
        created address
      • generateCustomerID

        public java.lang.String generateCustomerID()
        Generates a new customer ID using the number series with identifier NumberSeriesConstants.Series#CUSTOMER_ID. This number will be unique in relation to all id's generated by this method before.
        Returns:
        new customer id
        Since:
        public since 3.1-u6, before protected
      • getLoginToken

        public LoginToken getLoginToken​(javax.servlet.http.HttpServletRequest request)
        Tries to get a login token from request. First it tries to extract it from url, then from cookie.
      • getCookieBasedLoginToken

        public CookieBasedLoginToken getCookieBasedLoginToken​(javax.servlet.http.HttpServletRequest request)
      • getURLBasedLoginToken

        public StringBasedLoginToken getURLBasedLoginToken​(javax.servlet.http.HttpServletRequest request)
      • generateLoginTokenCookieValue

        public java.lang.String generateLoginTokenCookieValue​(java.lang.String uid,
                                                              java.lang.String languageISO,
                                                              java.lang.String plainTextPassword)
                                                       throws EJBPasswordEncoderNotFoundException
        Generates a value entry for a CookieBasedLoginToken instance, which will be used by some web apps (like printcockpit, hmc, ...) for an 'auto' login process All occurrences if possible should be replace with generateLoginTokenCookieValue(User, String)
        Returns:
        the generated token. format: ${user PK}${language PK}${password} (sample: 11326704420716009013969790041776ee10c315eba2c75b403ea79136f5b38d)
        Throws:
        EJBPasswordEncoderNotFoundException
      • storeLoginTokenCookie

        public void storeLoginTokenCookie​(java.lang.String name,
                                          java.lang.String uid,
                                          java.lang.String language,
                                          java.lang.String passwd,
                                          java.lang.String path,
                                          java.lang.String domain,
                                          boolean secure,
                                          int ttl,
                                          javax.servlet.http.HttpServletResponse response)
                                   throws EJBPasswordEncoderNotFoundException
        Throws:
        EJBPasswordEncoderNotFoundException
      • isPlainTextPasswordStored

        protected boolean isPlainTextPasswordStored​(User user)
      • writeReplace

        public java.lang.Object writeReplace()
                                      throws java.io.ObjectStreamException
        Specified by:
        writeReplace in class Manager
        Throws:
        java.io.ObjectStreamException
      • setPasswordCheckingStrategy

        public void setPasswordCheckingStrategy​(PasswordCheckingStrategy paramPasswordCheckingStrategy)