Class SecurityClient

  • All Implemented Interfaces:
    Closeable, AutoCloseable, org.apache.http.client.HttpClient
    Direct Known Subclasses:
    CQSecurityClient

    public class SecurityClient
    extends CQClient
    Client for managing authorizables, such as users or groups
    • Constructor Detail

      • SecurityClient

        public SecurityClient​(org.apache.http.impl.client.CloseableHttpClient http,
                              org.apache.sling.testing.clients.SlingClientConfig config)
                       throws org.apache.sling.testing.clients.ClientException
        Throws:
        org.apache.sling.testing.clients.ClientException
      • SecurityClient

        public SecurityClient​(URI serverUrl,
                              String user,
                              String password)
                       throws org.apache.sling.testing.clients.ClientException
        Throws:
        org.apache.sling.testing.clients.ClientException
    • Method Detail

      • getLoginUrl

        public String getLoginUrl()
        Get the login page
        Returns:
        the login url
      • getAdminUrl

        public String getAdminUrl()
        URL for Security Admin
        Returns:
        the admin url
      • deleteAuthorizables

        public void deleteAuthorizables​(Authorizable[] authorizables,
                                        int... expectedStatus)
                                 throws org.apache.sling.testing.clients.ClientException
        Delete a list of authorizables.
        Parameters:
        authorizables - Authorizable
        expectedStatus - list of allowed HTTP Status to be returned
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request failed
      • createUser

        public User createUser​(String userId,
                               int... expectedStatus)
                        throws org.apache.sling.testing.clients.ClientException,
                               InterruptedException
        Creates a new user with password the same as userId.
        Parameters:
        userId - the user ID for the new user.
        expectedStatus - list of allowed HTTP Status to be returned
        Returns:
        User
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request failed
        InterruptedException - to mark this method as "waiting"
      • createUser

        public User createUser​(String userId,
                               String intermediatePath,
                               int... expectedStatus)
                        throws org.apache.sling.testing.clients.ClientException,
                               InterruptedException
        Creates a new user with password the same as userId in a defined root path.
        Parameters:
        userId - the user ID for the new user.
        intermediatePath - the root path user will be created.
        expectedStatus - list of allowed HTTP Status to be returned.
        Returns:
        User
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
        InterruptedException - to mark this method as "waiting"
      • createUser

        public <T extends GroupUser createUser​(String userId,
                                                 String password,
                                                 T[] assignedGroups,
                                                 int... expectedStatus)
                                          throws org.apache.sling.testing.clients.ClientException,
                                                 InterruptedException
        Creates a new user and assigns him to a list of given Authorizables.
        Type Parameters:
        T - group type
        Parameters:
        userId - the user ID for the new user.
        password - the password to be assigned.
        assignedGroups - groups the user will be assigned to as Group-Array.
        expectedStatus - list of allowed HTTP Status to be returned.
        Returns:
        User
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
        InterruptedException - to mark this method as "waiting"
      • createUser

        public <T extends GroupUser createUser​(String userId,
                                                 String password,
                                                 String intermediatePath,
                                                 Map<String,​String> profileMap,
                                                 T[] assignedGroups,
                                                 int... expectedStatus)
                                          throws org.apache.sling.testing.clients.ClientException,
                                                 InterruptedException
        Creates a new user with a Profile and assigns him to a list of given Authorizables.
        Type Parameters:
        T - group type
        Parameters:
        userId - the user ID for the new user.
        password - the password to be assigned.
        intermediatePath - the root path user will be created.
        profileMap - profile properties to be set for the new user.
        assignedGroups - groups the user will be assigned to as Authorizable-Array.
        expectedStatus - list of allowed HTTP Status to be returned.
        Returns:
        User
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/ response cycle
        InterruptedException - to mark this method as "waiting"
      • createUser

        @Deprecated
        public <T extends GroupUser createUser​(String userId,
                                                 String password,
                                                 String intermediatePath,
                                                 Map<String,​String> profileMap,
                                                 boolean waitForIndexing,
                                                 T[] assignedGroups,
                                                 int... expectedStatus)
                                          throws org.apache.sling.testing.clients.ClientException,
                                                 InterruptedException
        Deprecated.
        waitForIndexing is not used anymore and it's ignored. Use createGroup(String, String, String, String, Group[], int...).
        Creates a new user with a Profile and assigns him to a list of given Authorizables.
        Type Parameters:
        T - group type
        Parameters:
        userId - the user ID for the new user.
        password - the password to be assigned.
        intermediatePath - the root path user will be created.
        profileMap - profile properties to be set for the new user.
        waitForIndexing - whether or not to wait for indexing to be completed after creating the user
        assignedGroups - groups the user will be assigned to as Authorizable-Array.
        expectedStatus - list of allowed HTTP Status to be returned.
        Returns:
        User
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/ response cycle
        InterruptedException - to mark this method as "waiting"
      • createGroup

        public Group createGroup​(String groupId,
                                 int... expectedStatus)
                          throws org.apache.sling.testing.clients.ClientException,
                                 InterruptedException
        Creates a new group.
        Parameters:
        groupId - the group ID for the new group.
        expectedStatus - list of allowed HTTP Status to be returned.
        Returns:
        Group
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
        InterruptedException - to mark this method as "waiting"
      • createGroup

        public Group createGroup​(String groupId,
                                 String intermediatePath,
                                 int... expectedStatus)
                          throws org.apache.sling.testing.clients.ClientException,
                                 InterruptedException
        Creates a new group.
        Parameters:
        groupId - the group ID for the new group.
        intermediatePath - the root path user will be created.
        expectedStatus - list of allowed HTTP Status to be returned.
        Returns:
        Group
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
        InterruptedException - to mark this method as "waiting"
      • createGroup

        public Group createGroup​(String groupId,
                                 Group[] assignedGroups,
                                 int... expectedStatus)
                          throws org.apache.sling.testing.clients.ClientException,
                                 InterruptedException
        Creates a new group and assigns him to a list of given Authorizables.
        Parameters:
        groupId - the group ID for the new group.
        assignedGroups - groups the user will be assigned to as Authorizable-Array.
        expectedStatus - list of allowed HTTP Status to be returned.
        Returns:
        Group
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
        InterruptedException - to mark this method as "waiting"
      • createGroup

        public Group createGroup​(String groupId,
                                 String intermediatePath,
                                 String givenName,
                                 String aboutMe,
                                 Group[] assignedGroups,
                                 int... expectedStatus)
                          throws org.apache.sling.testing.clients.ClientException,
                                 InterruptedException
        Creates a new group and assigns him to a list of given Authorizables.
        Parameters:
        groupId - the group ID for the new group.
        intermediatePath - the root path user will be created.
        givenName - the name of the group.
        aboutMe - description of the group.
        assignedGroups - groups the user will be assigned to
        expectedStatus - list of allowed HTTP Status to be returned.
        Returns:
        Group
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
        InterruptedException - to mark this method as "waiting"
      • getLoginTokenCookie

        public String getLoginTokenCookie​(int... expectedStatus)
                                   throws org.apache.sling.testing.clients.ClientException
        Get the login token cookie to authenticate future requests.
        Parameters:
        expectedStatus - list of allowed HTTP Status to be returned. If not set, http status 302 (REDIRECT (to the requested resource)) is assumed.
        Returns:
        the login-token cookie to be used for further requests.
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle