Package org.apache.sling.jcr.base

## Class AbstractSlingRepository2

- java.lang.Object
- - org.apache.sling.jcr.base.AbstractSlingRepository2

All Implemented Interfaces:
  `javax.jcr.Repository`, `org.apache.sling.jcr.api.SlingRepository`

    @ProviderType
    public abstract class AbstractSlingRepository2
    extends Object
    implements org.apache.sling.jcr.api.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:
  `AbstractSlingRepositoryManager`

### Field Summary

### Fields inherited from interface javax.jcr.Repository

`IDENTIFIER_STABILITY, IDENTIFIER_STABILITY_INDEFINITE_DURATION, IDENTIFIER_STABILITY_METHOD_DURATION, IDENTIFIER_STABILITY_SAVE_DURATION, IDENTIFIER_STABILITY_SESSION_DURATION, LEVEL_1_SUPPORTED, LEVEL_2_SUPPORTED, NODE_TYPE_MANAGEMENT_AUTOCREATED_DEFINITIONS_SUPPORTED, NODE_TYPE_MANAGEMENT_INHERITANCE, NODE_TYPE_MANAGEMENT_INHERITANCE_MINIMAL, NODE_TYPE_MANAGEMENT_INHERITANCE_MULTIPLE, NODE_TYPE_MANAGEMENT_INHERITANCE_SINGLE, NODE_TYPE_MANAGEMENT_MULTIPLE_BINARY_PROPERTIES_SUPPORTED, NODE_TYPE_MANAGEMENT_MULTIVALUED_PROPERTIES_SUPPORTED, NODE_TYPE_MANAGEMENT_ORDERABLE_CHILD_NODES_SUPPORTED, NODE_TYPE_MANAGEMENT_OVERRIDES_SUPPORTED, NODE_TYPE_MANAGEMENT_PRIMARY_ITEM_NAME_SUPPORTED, NODE_TYPE_MANAGEMENT_PROPERTY_TYPES, NODE_TYPE_MANAGEMENT_RESIDUAL_DEFINITIONS_SUPPORTED, NODE_TYPE_MANAGEMENT_SAME_NAME_SIBLINGS_SUPPORTED, NODE_TYPE_MANAGEMENT_UPDATE_IN_USE_SUPORTED, NODE_TYPE_MANAGEMENT_VALUE_CONSTRAINTS_SUPPORTED, OPTION_ACCESS_CONTROL_SUPPORTED, OPTION_ACTIVITIES_SUPPORTED, OPTION_BASELINES_SUPPORTED, OPTION_JOURNALED_OBSERVATION_SUPPORTED, OPTION_LIFECYCLE_SUPPORTED, OPTION_LOCKING_SUPPORTED, OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED, OPTION_NODE_TYPE_MANAGEMENT_SUPPORTED, OPTION_OBSERVATION_SUPPORTED, OPTION_QUERY_SQL_SUPPORTED, OPTION_RETENTION_SUPPORTED, OPTION_SHAREABLE_NODES_SUPPORTED, OPTION_SIMPLE_VERSIONING_SUPPORTED, OPTION_TRANSACTIONS_SUPPORTED, OPTION_UNFILED_CONTENT_SUPPORTED, OPTION_UPDATE_MIXIN_NODE_TYPES_SUPPORTED, OPTION_UPDATE_PRIMARY_NODE_TYPE_SUPPORTED, OPTION_VERSIONING_SUPPORTED, OPTION_WORKSPACE_MANAGEMENT_SUPPORTED, OPTION_XML_EXPORT_SUPPORTED, OPTION_XML_IMPORT_SUPPORTED, QUERY_FULL_TEXT_SEARCH_SUPPORTED, QUERY_JOINS, QUERY_JOINS_INNER, QUERY_JOINS_INNER_OUTER, QUERY_JOINS_NONE, QUERY_LANGUAGES, QUERY_STORED_QUERIES_SUPPORTED, QUERY_XPATH_DOC_ORDER, QUERY_XPATH_POS_INDEX, REP_NAME_DESC, REP_VENDOR_DESC, REP_VENDOR_URL_DESC, REP_VERSION_DESC, SPEC_NAME_DESC, SPEC_VERSION_DESC, WRITE_SUPPORTED`

### Constructor Summary

Constructors
`protected` `AbstractSlingRepository2​(AbstractSlingRepositoryManager manager, org.osgi.framework.Bundle usingBundle)` Sets up this abstract SlingRepository implementation.

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`protected abstract javax.jcr.Session` `createAdministrativeSession​(String workspace)` Creates an administrative session to access the indicated workspace.
`protected javax.jcr.Session` `createServiceSession​(Iterable<String> servicePrincipalNames, String workspaceName)` Creates a service-session for the service's `servicePrincipalNames` using a pre-authenticated `Subject`.
`protected javax.jcr.Session` `createServiceSession​(String serviceUserName, String workspace)` Creates a service-session for the service's `serviceUserName` by impersonating the user from an administrative session.
`String` `getDefaultWorkspace()` Returns the default workspace to login to if any of the `login` and `createSession` methods is called without an explicit workspace name.
`String` `getDescriptor​(String name)`
`String[]` `getDescriptorKeys()`
`javax.jcr.Value` `getDescriptorValue​(String key)`
`javax.jcr.Value[]` `getDescriptorValues​(String key)`
`protected javax.jcr.Repository` `getRepository()` Returns the actual repository to which all JCR Repository interface methods implemented by this class are delegated.
`protected AbstractSlingRepositoryManager` `getSlingRepositoryManager()`
`javax.jcr.Session` `impersonateFromService​(String subServiceName, javax.jcr.Credentials credentials, String workspaceName)` Default implementation of the `impersonateFromService(String, Credentials, String)` method taking into account the bundle calling this method.
`boolean` `isSingleValueDescriptor​(String key)`
`boolean` `isStandardDescriptor​(String key)`
`javax.jcr.Session` `login()` Same as calling `login(null, null)`.
`javax.jcr.Session` `login​(String workspace)` Same as calling `login(null, workspace)`.
`javax.jcr.Session` `login​(javax.jcr.Credentials credentials)` Same as calling `login(credentials, null)`.
`javax.jcr.Session` `login​(javax.jcr.Credentials credentials, String workspace)` Logs into the repository at the given `workspace` with the given `credentials` and returns the session returned from the repository.
`javax.jcr.Session` `loginAdministrative​(String workspace)` Login as an administrative user.
`javax.jcr.Session` `loginService​(String subServiceName, String workspace)` Actual implementation of the `loginService(String, String)` method taking into account the bundle calling this method.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### AbstractSlingRepository2

    protected AbstractSlingRepository2​(AbstractSlingRepositoryManager manager,
                                       org.osgi.framework.Bundle usingBundle)

Sets up this abstract SlingRepository implementation.

Parameters:
  `manager` - The `AbstractSlingRepositoryManager` controlling this instance as well as the actual JCR repository instance used by this.
  `usingBundle` - The bundle using this instance. This is used by the `loginService(String, String)` method, which will not be able to login if this parameter is `null`

### Method Detail

#### getSlingRepositoryManager

    protected final AbstractSlingRepositoryManager getSlingRepositoryManager()

Returns:
  The `AbstractSlingRepositoryManager` controlling this instances

#### getRepository

    protected final javax.jcr.Repository getRepository()

Returns the actual repository to which all JCR Repository interface methods implemented by this class are delegated.

Returns:
  The delegated repository.

#### 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 `org.apache.sling.jcr.api.SlingRepository`

#### createAdministrativeSession

    protected abstract javax.jcr.Session createAdministrativeSession​(String workspace)
                                                              throws javax.jcr.RepositoryException

Creates an administrative session to access the indicated workspace.

This method is called by the `loginAdministrative(String)` and `createServiceSession(String, String)` methods.

Parameters:
  `workspace` - The workspace to access or `null` to access the `default workspace`
Returns:
  An administrative session
Throws:
  `javax.jcr.RepositoryException` - If a general error occurs during login
See Also:
  `createServiceSession(String, String)`, `loginAdministrative(String)`

#### createServiceSession

    protected javax.jcr.Session createServiceSession​(String serviceUserName,
                                                     String workspace)
                                              throws javax.jcr.RepositoryException

Creates a service-session for the service's `serviceUserName` by impersonating the user from an administrative session.

The administrative session is created calling `createAdministrativeSession(workspace)` and is logged out before this method returns.

Implementations of this class may overwrite this method with a better implementation, notably one which does not involve a temporary creation of an administrative session.

Parameters:
  `serviceUserName` - The name of the user to create the session for
  `workspace` - The workspace to access or `null` to access the `default workspace`
Returns:
  A session for the given user
Throws:
  `javax.jcr.RepositoryException` - If a general error occurs while creating the session

#### createServiceSession

    protected javax.jcr.Session createServiceSession​(Iterable<String> servicePrincipalNames,
                                                     String workspaceName)
                                              throws javax.jcr.RepositoryException

Creates a service-session for the service's `servicePrincipalNames` using a pre-authenticated `Subject`.

Implementations of this class may overwrite this method to meet additional needs wrt the the nature of the principals, the `Subject` or additional attributes passed to the repository login.

Parameters:
  `servicePrincipalNames` - The names of the service principals to create the session for
  `workspaceName` - The workspace to access or `null` to access the `default workspace`
Returns:
  A new service session
Throws:
  `javax.jcr.RepositoryException` - If a general error occurs while creating the session.

#### login

    public javax.jcr.Session login()
                            throws javax.jcr.LoginException,
                                   javax.jcr.RepositoryException

Same as calling `login(null, null)`.

This method may be overwritten.

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

#### login

    public javax.jcr.Session login​(javax.jcr.Credentials credentials)
                            throws javax.jcr.LoginException,
                                   javax.jcr.RepositoryException

Same as calling `login(credentials, null)`.

This method may be overwritten.

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

#### login

    public javax.jcr.Session login​(String workspace)
                            throws javax.jcr.LoginException,
                                   javax.jcr.NoSuchWorkspaceException,
                                   javax.jcr.RepositoryException

Same as calling `login(null, workspace)`.

This method may be overwritten.

Specified by:
  `login` in interface `javax.jcr.Repository`
Parameters:
  `workspace` - The workspace to access or `null` to access the `default workspace`
Returns:
  the result of calling `login(null, workspace)`.
Throws:
  `javax.jcr.LoginException` - If login is not possible
  `javax.jcr.RepositoryException` - If another error occurrs during login
  `javax.jcr.NoSuchWorkspaceException`
See Also:
  `login(Credentials, String)`

#### login

    public javax.jcr.Session login​(javax.jcr.Credentials credentials,
                                   String workspace)
                            throws javax.jcr.LoginException,
                                   javax.jcr.NoSuchWorkspaceException,
                                   javax.jcr.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 `javax.jcr.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`
Throws:
  `javax.jcr.LoginException` - If login is not possible
  `javax.jcr.NoSuchWorkspaceException` - if the desired workspace is not available
  `javax.jcr.RepositoryException` - If another error occurrs during login

#### loginService

    public final javax.jcr.Session loginService​(String subServiceName,
                                                String workspace)
                                         throws javax.jcr.LoginException,
                                                javax.jcr.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 `org.apache.sling.jcr.api.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:
  `javax.jcr.LoginException` - if the service name cannot be derived or if logging is as the user to which the service name maps is not allowed
  `javax.jcr.RepositoryException` - If a general error occurs while creating the session

#### impersonateFromService

    public javax.jcr.Session impersonateFromService​(String subServiceName,
                                                    javax.jcr.Credentials credentials,
                                                    String workspaceName)
                                             throws javax.jcr.LoginException,
                                                    javax.jcr.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 `org.apache.sling.jcr.api.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:
  `javax.jcr.LoginException` - If the current session does not have sufficient access to perform the operation.
  `javax.jcr.RepositoryException` - If another error occurs.
Since:
  2.4

#### loginAdministrative

    public final javax.jcr.Session loginAdministrative​(String workspace)
                                                throws javax.jcr.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 `org.apache.sling.jcr.api.SlingRepository`
Parameters:
  `workspace` - The workspace to access or `null` to access the `default workspace`
Returns:
  An administrative session
Throws:
  `javax.jcr.RepositoryException` - If the login fails or has been disabled

#### getDescriptor

    public String getDescriptor​(String name)

Specified by:
  `getDescriptor` in interface `javax.jcr.Repository`

#### getDescriptorKeys

    public String[] getDescriptorKeys()

Specified by:
  `getDescriptorKeys` in interface `javax.jcr.Repository`

#### getDescriptorValue

    public javax.jcr.Value getDescriptorValue​(String key)

Specified by:
  `getDescriptorValue` in interface `javax.jcr.Repository`

#### getDescriptorValues

    public javax.jcr.Value[] getDescriptorValues​(String key)

Specified by:
  `getDescriptorValues` in interface `javax.jcr.Repository`

#### isSingleValueDescriptor

    public boolean isSingleValueDescriptor​(String key)

Specified by:
  `isSingleValueDescriptor` in interface `javax.jcr.Repository`

#### isStandardDescriptor

    public boolean isStandardDescriptor​(String key)

Specified by:
  `isStandardDescriptor` in interface `javax.jcr.Repository`