Class AbstractAuthorizable

    • Field Detail

      • authorizableId

        protected String authorizableId
      • authorizablePath

        protected String authorizablePath
    • Constructor Detail

      • AbstractAuthorizable

        public AbstractAuthorizable​(T client,
                                    String authorizableId)
                             throws org.apache.sling.testing.clients.ClientException,
                                    InterruptedException
        Constructor for an Authorizable, default path to authorizable is expected
        Type Parameters:
        T - any class implementing teh SecurityClient.
        Parameters:
        client - any class implementing the SecurityClient.
        authorizableId - the authorizable ID.
        Throws:
        org.apache.sling.testing.clients.ClientException - if the details of the authorizables cannot be retrieved
        InterruptedException - to mark this method as "waiting"
    • Method Detail

      • getId

        public String getId()
        Description copied from interface: Authorizable
        Get id of authorizable
        Specified by:
        getId in interface Authorizable
        Returns:
        authorizableId
      • getHomePath

        public String getHomePath()
        Description copied from interface: Authorizable
        Get home path to authorizable
        Specified by:
        getHomePath in interface Authorizable
        Returns:
        path to authorizable
      • getHomeUrl

        public String getHomeUrl()
        Description copied from interface: Authorizable
        Get home URL to authorizable
        Specified by:
        getHomeUrl in interface Authorizable
        Returns:
        URL to authorizable
      • getJsonAsString

        public String getJsonAsString​(String propsFilter,
                                      int... expectedStatus)
                               throws org.apache.sling.testing.clients.ClientException
        Description copied from interface: Authorizable
        String representation of authorizable http://localhost:4502/home/groups/default/administrators.rw.json?props=replication,modification,memberOf, membersTotal,members,profile/*&ml=2000
        Specified by:
        getJsonAsString in interface Authorizable
        Parameters:
        propsFilter - properties filter
        expectedStatus - list of allowed HTTP Status to be returned.
        Returns:
        the string representing a json
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
      • getUserPropertiesJsonAsString

        public String getUserPropertiesJsonAsString​(int... expectedStatus)
                                             throws org.apache.sling.testing.clients.ClientException
        Description copied from interface: Authorizable
        Get user properties JSON representation as string
        Specified by:
        getUserPropertiesJsonAsString in interface Authorizable
        Parameters:
        expectedStatus - status to be
        Returns:
        user properties JSON representation as String
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
      • exists

        public static boolean exists​(SecurityClient client,
                                     String authorizableId)
                              throws org.apache.sling.testing.clients.ClientException
        Throws:
        org.apache.sling.testing.clients.ClientException
      • exists

        public boolean exists()
                       throws org.apache.sling.testing.clients.ClientException
        Description copied from interface: Authorizable
        Check if the authorizable exists
        Specified by:
        exists in interface Authorizable
        Returns:
        true if the authorizable exists
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request failed
      • exists

        public boolean exists​(String query)
                       throws org.apache.sling.testing.clients.ClientException
        Throws:
        org.apache.sling.testing.clients.ClientException
      • delete

        public org.apache.sling.testing.clients.SlingHttpResponse delete​(int... expectedStatus)
                                                                  throws org.apache.sling.testing.clients.ClientException
        Description copied from interface: Authorizable
        Deletes an authorizable.
        Specified by:
        delete in interface Authorizable
        Parameters:
        expectedStatus - list of allowed HTTP Status to be returned.
        Returns:
        Sling response
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
      • create

        public <T extends SecurityClient> Authorizable create​(T client,
                                                              Class<? extends AbstractAuthorizable> authorizableClass,
                                                              String authorizableId,
                                                              org.apache.sling.testing.clients.util.FormEntityBuilder formParameters,
                                                              int... expectedStatus)
                                                       throws org.apache.sling.testing.clients.ClientException
        Description copied from interface: Authorizable
        Creates a new Authorizable.
        Specified by:
        create in interface Authorizable
        Type Parameters:
        T - client type
        Parameters:
        client - any class implementing the SecurityClient.
        authorizableClass - Authorizable class to be created.
        authorizableId - the ID for the new authorizable.
        formParameters - form parameters.
        expectedStatus - list of allowed HTTP Status to be returned. If not set, http status 201 (CREATED) is assumed.
        Returns:
        created Authorizable
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
      • getMemberOf

        public Map<String,​Authorizable> getMemberOf()
                                                   throws org.apache.sling.testing.clients.ClientException,
                                                          InterruptedException
        Description copied from interface: Authorizable
        Get members authorizable is assigned to.
        Specified by:
        getMemberOf in interface Authorizable
        Returns:
        list of Authorizable
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
        InterruptedException - to mark this method as "waiting"
      • getMembers

        public Map<String,​Authorizable> getMembers()
                                                  throws org.apache.sling.testing.clients.ClientException,
                                                         InterruptedException
        Description copied from interface: Authorizable
        Get members assigned to the authorizable.
        Specified by:
        getMembers in interface Authorizable
        Returns:
        list of Authorizable
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
        InterruptedException - to mark this method as "waiting"
      • isImpersonated

        public boolean isImpersonated()
                               throws org.apache.sling.testing.clients.ClientException
        Description copied from interface: Authorizable
        Check if authorizable is impersonated.
        Specified by:
        isImpersonated in interface Authorizable
        Returns:
        true if authorizable is impersonated.
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
      • getProfile

        public com.fasterxml.jackson.databind.JsonNode getProfile()
                                                           throws org.apache.sling.testing.clients.ClientException
        Description copied from interface: Authorizable
        Get profile attributes for authorizable.
        Specified by:
        getProfile in interface Authorizable
        Returns:
        JsonNode containing profile properties
        Throws:
        org.apache.sling.testing.clients.ClientException - If something fails during request/response cycle
      • doPost

        public org.apache.sling.testing.clients.SlingHttpResponse doPost​(org.apache.sling.testing.clients.util.FormEntityBuilder formParameters,
                                                                         int... expectedStatus)
                                                                  throws org.apache.sling.testing.clients.ClientException
        POST request to AuthorizableServlet.
        Parameters:
        formParameters - form parameters.
        expectedStatus - list of allowed HTTP Status to be returned.
        Returns:
        executed request
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request failed
      • doGet

        public org.apache.sling.testing.clients.SlingHttpResponse doGet​(List<org.apache.http.NameValuePair> parameters,
                                                                        int... expectedStatus)
                                                                 throws org.apache.sling.testing.clients.ClientException
        GET request to AuthorizableServlet.
        Parameters:
        parameters - url parameters.
        expectedStatus - list of allowed HTTP Status to be returned.
        Returns:
        executed request
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request failed
      • getAuthorizableClass

        public static Class<? extends AbstractAuthorizable> getAuthorizableClass​(String authorizableType)
        Get authorizable Class.
        Parameters:
        authorizableType - Allowed values: "user" or "group" (fallback).
        Returns:
        a Class extending AbstractAuthorizable
      • getQuery

        public static String getQuery​(String authorizableId)
      • buildAuthorizablePath

        public static String buildAuthorizablePath​(String authorizableId,
                                                   String rootPath,
                                                   String intermediatePath)
                                            throws org.apache.sling.testing.clients.ClientException
        Get home path of the authorizable (user/group) in repository. Either user is created in a user defined structure (intermediatePath is set while creation) or within the default structure
        Parameters:
        authorizableId - the ID of the authorizable
        rootPath - the rootPath of the authorizable
        intermediatePath - the parent path the user will be created.
        Returns:
        the authorizable path
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request failed
      • encodePathToURL

        protected static String encodePathToURL​(String authorizableHomePath)
                                         throws org.apache.sling.testing.clients.ClientException
        Get url of the authorizable (user/group) in repository. Either user is created in a user defined structure (intermediatePath is set while creation) or within the default structure

        JCR escaping works similar to URL encoding, meaning that special chars doGet %-encoded. so to avoid % being interpreted by the URL as an URL Encoding we must URL encode the % to doGet a valid URL

        Parameters:
        authorizableHomePath - the home path of the authorizable
        Returns:
        authorizable url
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request failed
      • encodeURI

        protected static String encodeURI​(String unescapedPath)
                                   throws org.apache.sling.testing.clients.ClientException
        Escape path to URI
        Parameters:
        unescapedPath - unescaped path
        Returns:
        escaped path
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request failed
      • buildAuthorizableList

        protected Map<String,​Authorizable> buildAuthorizableList​(com.fasterxml.jackson.databind.JsonNode authorizableJsonNode)
                                                                throws org.apache.sling.testing.clients.ClientException,
                                                                       InterruptedException
        Build list of Authorizables as Map: key = id of authorizable.
        Parameters:
        authorizableJsonNode - JSON node of an authorizable; TODO; format
        Returns:
        list of Authorizable
        Throws:
        org.apache.sling.testing.clients.ClientException - if the request failed
        InterruptedException - to mark this method as "waiting"