Class AbstractSlingRepository2
- java.lang.Object
-
- org.apache.sling.jcr.base.AbstractSlingRepository2
-
- All Implemented Interfaces:
Repository
,SlingRepository
@ProviderType public abstract class AbstractSlingRepository2 extends java.lang.Object implements SlingRepository
TheAbstractSlingRepository2
is an abstract implementation of theSlingRepository
version 2.3 interface (phasingloginAdministrative(String)
out in favor ofloginService(String, String)
) which provides default support for attached repositories. Implementations of theSlingRepository
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 theloginService(String, String)
method the bundle using the repository service has to be provided in theconstructor
. The premise of this abstract class is that an instance of an implementation of this abstract class is handed out to each consumer of theSlingRepository
service. Each instance is generally based on the samedelegated 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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getDefaultWorkspace()
Returns the default workspace to login to if any of thelogin
andcreateSession
methods is called without an explicit workspace name.java.lang.String
getDescriptor(java.lang.String name)
A convenience method.java.lang.String[]
getDescriptorKeys()
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.Value
getDescriptorValue(java.lang.String key)
The value of a single-value descriptor is found by passing the key for that descriptor to this method.Value[]
getDescriptorValues(java.lang.String key)
The value array of a multi-value descriptor is found by passing the key for that descriptor to this method.Session
impersonateFromService(java.lang.String subServiceName, Credentials credentials, java.lang.String workspaceName)
Default implementation of theimpersonateFromService(String, Credentials, String)
method taking into account the bundle calling this method.boolean
isSingleValueDescriptor(java.lang.String key)
Returnstrue
ifkey
is a valid single-value descriptor; otherwise returnsfalse
.boolean
isStandardDescriptor(java.lang.String key)
Returnstrue
ifkey
is a standard descriptor defined by the string constants in this interface andfalse
if it is either a valid implementation-specific key or not a valid key.Session
login()
Same as callinglogin(null, null)
.Session
login(java.lang.String workspace)
Same as callinglogin(null, workspace)
.Session
login(Credentials credentials)
Same as callinglogin(credentials, null)
.Session
login(Credentials credentials, java.lang.String workspace)
Logs into the repository at the givenworkspace
with the givencredentials
and returns the session returned from the repository.Session
loginAdministrative(java.lang.String workspace)
Login as an administrative user.Session
loginService(java.lang.String subServiceName, java.lang.String workspace)
Actual implementation of theloginService(String, String)
method taking into account the bundle calling this method.
-
-
-
Method Detail
-
getDefaultWorkspace
public final java.lang.String getDefaultWorkspace()
Returns the default workspace to login to if any of thelogin
andcreateSession
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 interfaceSlingRepository
- Returns:
- null if the configured default workspace name is empty, SLING-256
-
login
public Session login() throws LoginException, RepositoryException
Same as callinglogin(null, null)
.This method may be overwritten.
- Specified by:
login
in interfaceRepository
- Returns:
- the result of calling
login(null, null)
. - Throws:
LoginException
- If login is not possibleRepositoryException
- If another error occurrs during login- See Also:
login(Credentials, String)
-
login
public Session login(Credentials credentials) throws LoginException, RepositoryException
Same as callinglogin(credentials, null)
.This method may be overwritten.
- Specified by:
login
in interfaceRepository
- Parameters:
credentials
- TheCredentials
to use to login.- Returns:
- the result of calling
login(credentials, null)
. - Throws:
LoginException
- If login is not possibleRepositoryException
- If another error occurrs during login- See Also:
login(Credentials, String)
-
login
public Session login(java.lang.String workspace) throws LoginException, NoSuchWorkspaceException, RepositoryException
Same as callinglogin(null, workspace)
.This method may be overwritten.
- Specified by:
login
in interfaceRepository
- Parameters:
workspace
- The workspace to access ornull
to access thedefault workspace
- Returns:
- the result of calling
login(null, workspace)
. - Throws:
LoginException
- If login is not possibleRepositoryException
- If another error occurrs during loginNoSuchWorkspaceException
- if the specifiedworkspaceName
is not recognized.- See Also:
login(Credentials, String)
-
login
public Session login(Credentials credentials, java.lang.String workspace) throws LoginException, NoSuchWorkspaceException, RepositoryException
Logs into the repository at the givenworkspace
with the givencredentials
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 interfaceRepository
- Parameters:
credentials
- TheCredentials
to use to login. If this isnull
JCRGuestCredentials
are used to login.workspace
- The workspace to access ornull
to access thedefault workspace
- Returns:
- a valid session for the user to access the repository.
- Throws:
LoginException
- If login is not possibleNoSuchWorkspaceException
- if the desired workspace is not availableRepositoryException
- If another error occurrs during login
-
loginService
public final Session loginService(java.lang.String subServiceName, java.lang.String workspace) throws LoginException, RepositoryException
Actual implementation of theloginService(String, String)
method taking into account the bundle calling this method. This method uses theServiceUserMapper
service to map the named service to a user and then calls thecreateServiceSession(String, String)
method actually create a session for that user.- Specified by:
loginService
in interfaceSlingRepository
- Parameters:
subServiceName
- An optional subService identifier (may benull
)workspace
- The workspace to access ornull
to access thedefault 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 allowedRepositoryException
- If a general error occurs while creating the session- See Also:
- Service Authentication
-
impersonateFromService
public Session impersonateFromService(java.lang.String subServiceName, Credentials credentials, java.lang.String workspaceName) throws LoginException, RepositoryException
Default implementation of theimpersonateFromService(String, Credentials, String)
method taking into account the bundle calling this method. This method uses theServiceUserMapper
service to map the named service to a user and then calls thecreateServiceSession(String, String)
method actually create a session for that user. This service session is then impersonated to the subject identified by the specifiedcredentials
.- Specified by:
impersonateFromService
in interfaceSlingRepository
- Parameters:
subServiceName
- An optional subService identifier (may benull
)credentials
- A valid non-nullCredentials
objectworkspaceName
- The workspace to access ornull
to access thedefault 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(java.lang.String workspace) throws RepositoryException
Login as an administrative user. This method is deprecated and its use can be completely disabled by settingdisableLoginAdministrative
totrue
.This implementation cannot be overwritten but, unless disabled, forwards to the
createAdministrativeSession(String)
method.- Specified by:
loginAdministrative
in interfaceSlingRepository
- Parameters:
workspace
- The workspace to access ornull
to access thedefault workspace
- Returns:
- An administrative session
- Throws:
RepositoryException
- If the login fails or has been disabled
-
getDescriptor
public java.lang.String getDescriptor(java.lang.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 interfaceRepository
- Parameters:
name
- a descriptor key.- Returns:
- a descriptor value in string form.
-
getDescriptorKeys
public java.lang.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 withRepository.getDescriptorValue(String key)
andRepository.getDescriptorValues(String key)
to query information about this repository implementation.- Specified by:
getDescriptorKeys
in interfaceRepository
- Returns:
- a string array holding all descriptor keys.
-
getDescriptorValue
public Value getDescriptorValue(java.lang.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. Ifkey
is the key of a multi-value descriptor or not a valid key this method returnsnull
.- Specified by:
getDescriptorValue
in interfaceRepository
- Parameters:
key
- a descriptor key.- Returns:
- The value of the indicated descriptor
-
getDescriptorValues
public Value[] getDescriptorValues(java.lang.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. Ifkey
is the key of a single-value descriptor then this method returns that value as an array of size one. Ifkey
is not a valid key this method returnsnull
.- Specified by:
getDescriptorValues
in interfaceRepository
- Parameters:
key
- a descriptor key.- Returns:
- the value array for the indicated descriptor
-
isSingleValueDescriptor
public boolean isSingleValueDescriptor(java.lang.String key)
Description copied from interface:Repository
Returnstrue
ifkey
is a valid single-value descriptor; otherwise returnsfalse
.- Specified by:
isSingleValueDescriptor
in interfaceRepository
- Parameters:
key
- a descriptor key.- Returns:
- whether the specified desdfriptor is multi-valued.
-
isStandardDescriptor
public boolean isStandardDescriptor(java.lang.String key)
Description copied from interface:Repository
Returnstrue
ifkey
is a standard descriptor defined by the string constants in this interface andfalse
if it is either a valid implementation-specific key or not a valid key.- Specified by:
isStandardDescriptor
in interfaceRepository
- Parameters:
key
- a descriptor key.- Returns:
- whether
key
is a standard descriptor.
-
-