Class AbstractSlingRepository2

java.lang.Object
org.apache.sling.jcr.base.AbstractSlingRepository2
All Implemented Interfaces:
Repository, SlingRepository

@ProviderType public abstract class AbstractSlingRepository2 extends Object implements SlingRepository
The AbstractSlingRepository2 is an abstract implementation of the SlingRepository version 2.3 interface (phasing loginAdministrative(String) out in favor of loginService(String, String)) which provides default support for attached repositories. Implementations of the SlingRepository interface may wish to extend this class to benefit from default implementations of most methods. To be able to know the calling bundle to implement the loginService(String, String) method the bundle using the repository service has to be provided in the constructor. The premise of this abstract class is that an instance of an implementation of this abstract class is handed out to each consumer of the SlingRepository service. Each instance is generally based on the same delegated repository instance.
Since:
API version 2.4 (bundle version 2.3)
See Also:
  • Method Details

    • getDefaultWorkspace

      public final String getDefaultWorkspace()
      Returns the default workspace to login to if any of the login and createSession methods is called without an explicit workspace name.

      This method may return null in which case the actual default workspace used depends on the underlying JCR Repository implementation.

      Specified by:
      getDefaultWorkspace in interface SlingRepository
      Returns:
      null if the configured default workspace name is empty, SLING-256
    • login

      public Session login() throws LoginException, RepositoryException
      Same as calling login(null, null).

      This method may be overwritten.

      Specified by:
      login in interface Repository
      Returns:
      the result of calling login(null, null).
      Throws:
      LoginException - If login is not possible
      RepositoryException - If another error occurrs during login
      See Also:
    • login

      public Session login(Credentials credentials) throws LoginException, RepositoryException
      Same as calling login(credentials, null).

      This method may be overwritten.

      Specified by:
      login in interface Repository
      Parameters:
      credentials - The Credentials to use to login.
      Returns:
      the result of calling login(credentials, null).
      Throws:
      LoginException - If login is not possible
      RepositoryException - If another error occurrs during login
      See Also:
    • login

      Same as calling login(null, workspace).

      This method may be overwritten.

      Specified by:
      login in interface Repository
      Parameters:
      workspace - The workspace to access or null to access the default workspace
      Returns:
      the result of calling login(null, workspace).
      Throws:
      LoginException - If login is not possible
      RepositoryException - If another error occurrs during login
      NoSuchWorkspaceException - if the specified workspaceName is not recognized.
      See Also:
    • login

      public Session login(Credentials credentials, String workspace) throws LoginException, NoSuchWorkspaceException, RepositoryException
      Logs into the repository at the given workspace with the given credentials and returns the session returned from the repository.

      This method logs in as a guest if null credentials are provided. The method may be overwritten to implement a different behaviour as indicated by the JCR specification for this method to use external mechanisms to login instead of leveraging provided credentials.

      This method may be overwritten.

      Specified by:
      login in interface Repository
      Parameters:
      credentials - The Credentials to use to login. If this is null JCR GuestCredentials are used to login.
      workspace - The workspace to access or null to access the default workspace
      Returns:
      a valid session for the user to access the repository.
      Throws:
      LoginException - If login is not possible
      NoSuchWorkspaceException - if the desired workspace is not available
      RepositoryException - If another error occurrs during login
    • loginService

      public final Session loginService(String subServiceName, String workspace) throws LoginException, RepositoryException
      Actual implementation of the loginService(String, String) method taking into account the bundle calling this method. This method uses the ServiceUserMapper service to map the named service to a user and then calls the createServiceSession(String, String) method actually create a session for that user.
      Specified by:
      loginService in interface SlingRepository
      Parameters:
      subServiceName - An optional subService identifier (may be null)
      workspace - The workspace to access or null to access the default workspace
      Returns:
      A session authenticated with the service user
      Throws:
      LoginException - if the service name cannot be derived or if logging is as the user to which the service name maps is not allowed
      RepositoryException - If a general error occurs while creating the session
      See Also:
    • impersonateFromService

      public Session impersonateFromService(String subServiceName, Credentials credentials, String workspaceName) throws LoginException, RepositoryException
      Default implementation of the impersonateFromService(String, Credentials, String) method taking into account the bundle calling this method. This method uses the ServiceUserMapper service to map the named service to a user and then calls the createServiceSession(String, String) method actually create a session for that user. This service session is then impersonated to the subject identified by the specified credentials.
      Specified by:
      impersonateFromService in interface SlingRepository
      Parameters:
      subServiceName - An optional subService identifier (may be null)
      credentials - A valid non-null Credentials object
      workspaceName - The workspace to access or null to access the default workspace
      Returns:
      a new Session object
      Throws:
      LoginException - If the current session does not have sufficient access to perform the operation.
      RepositoryException - If another error occurs.
      Since:
      2.4
    • loginAdministrative

      public final Session loginAdministrative(String workspace) throws RepositoryException
      Login as an administrative user. This method is deprecated and its use can be completely disabled by setting disableLoginAdministrative to true.

      This implementation cannot be overwritten but, unless disabled, forwards to the createAdministrativeSession(String) method.

      Specified by:
      loginAdministrative in interface SlingRepository
      Parameters:
      workspace - The workspace to access or null to access the default workspace
      Returns:
      An administrative session
      Throws:
      RepositoryException - If the login fails or has been disabled
    • getDescriptor

      public String getDescriptor(String name)
      Description copied from interface: Repository

      A convenience method. The call

      String s = repository.getDescriptor(key);

      is equivalent to

      Value v = repository.getDescriptorValue(key);
      String s = (v == null) ? null : v.getString();

      Specified by:
      getDescriptor in interface Repository
      Parameters:
      name - a descriptor key.
      Returns:
      a descriptor value in string form.
    • getDescriptorKeys

      public String[] getDescriptorKeys()
      Description copied from interface: Repository
      Returns a string array holding all descriptor keys available for this implementation, both the standard descriptors defined by the string constants in this interface and any implementation-specific descriptors. Used in conjunction with Repository.getDescriptorValue(String key) and Repository.getDescriptorValues(String key) to query information about this repository implementation.
      Specified by:
      getDescriptorKeys in interface Repository
      Returns:
      a string array holding all descriptor keys.
    • getDescriptorValue

      public Value getDescriptorValue(String key)
      Description copied from interface: Repository
      The value of a single-value descriptor is found by passing the key for that descriptor to this method. If key is the key of a multi-value descriptor or not a valid key this method returns null.
      Specified by:
      getDescriptorValue in interface Repository
      Parameters:
      key - a descriptor key.
      Returns:
      The value of the indicated descriptor
    • getDescriptorValues

      public Value[] getDescriptorValues(String key)
      Description copied from interface: Repository
      The value array of a multi-value descriptor is found by passing the key for that descriptor to this method. If key is the key of a single-value descriptor then this method returns that value as an array of size one. If key is not a valid key this method returns null.
      Specified by:
      getDescriptorValues in interface Repository
      Parameters:
      key - a descriptor key.
      Returns:
      the value array for the indicated descriptor
    • isSingleValueDescriptor

      public boolean isSingleValueDescriptor(String key)
      Description copied from interface: Repository
      Returns true if key is a valid single-value descriptor; otherwise returns false.
      Specified by:
      isSingleValueDescriptor in interface Repository
      Parameters:
      key - a descriptor key.
      Returns:
      whether the specified desdfriptor is multi-valued.
    • isStandardDescriptor

      public boolean isStandardDescriptor(String key)
      Description copied from interface: Repository
      Returns true if key is a standard descriptor defined by the string constants in this interface and false if it is either a valid implementation-specific key or not a valid key.
      Specified by:
      isStandardDescriptor in interface Repository
      Parameters:
      key - a descriptor key.
      Returns:
      whether key is a standard descriptor.