Package org.opensaml.storage.impl
Class LDAPStorageService
- All Implemented Interfaces:
Component
,DestructableComponent
,IdentifiableComponent
,IdentifiedComponent
,InitializableComponent
,StorageCapabilities
,StorageCapabilitiesEx
,StorageService
Implementation of
StorageService
that stores data in an LDAP. Does not support
expiration or versioning at this time.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate PooledConnectionFactory
LDAP connection factory.private LdapAttribute[]
Attributes to include in merge operations.private final org.slf4j.Logger
Class logger. -
Constructor Summary
ConstructorsConstructorDescriptionLDAPStorageService
(PooledConnectionFactory factory, LdapAttribute... attrs) Creates a new LDAP storage service. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Creates a new record in the store with an expiration.Executes aDeleteOperation
on the supplied DN.boolean
Deletes an existing record from the store.deleteAttribute
(String dn, String attrName) Executes aModifyOperation
on the supplied DN, removing the supplied attribute.void
deleteContext
(String context) Forcibly removes all records in a given context along with any associated resources devoted to maintaining the context.boolean
deleteWithVersion
(long version, String context, String key) Deletes an existing record from the store if it currently has a specified version.protected void
protected void
boolean
Returns true iff the storage implementation manages data independent of a single server node.boolean
Returns true iff the storage implementation manages data independent of the client.Executes aMergeOperation
with the supplied entry.<T> StorageRecord<T>
Returns an existing record from the store, if one exists.<T> Pair<Long,
StorageRecord<T>> Returns an existing record from the store, along with its version.void
Manually trigger a cleanup of expired records.private Response<SearchResult>
Executes a object levelSearchOperation
on the supplied DN, returning the supplied attributes.boolean
Updates an existing record in the store.void
updateContextExpiration
(String context, Long expiration) Updates the expiration time of all records in the context.boolean
updateExpiration
(String context, String key, Long expiration) Updates expiration of an existing record in the store.updateWithVersion
(long version, String context, String key, String value, Long expiration) Updates an existing record in the store, if a version matches.Methods inherited from class org.opensaml.storage.AbstractStorageService
create, create, delete, deleteWithVersion, getCapabilities, getCleanupInterval, getCleanupTask, getCleanupTaskTimer, getContextSize, getKeySize, getValueSize, read, setCleanupInterval, setCleanupTaskTimer, setContextSize, setKeySize, setValueSize, update, update, updateExpiration, updateWithVersion, updateWithVersion
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent
setId
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
getId
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, initialize, isDestroyed, isInitialized
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.shibboleth.utilities.java.support.component.IdentifiedComponent
getId
Methods inherited from interface org.opensaml.storage.StorageCapabilities
getContextSize, getKeySize, getValueSize
-
Field Details
-
log
private final org.slf4j.Logger logClass logger. -
connectionFactory
LDAP connection factory. -
defaultAttributes
Attributes to include in merge operations.
-
-
Constructor Details
-
LDAPStorageService
Creates a new LDAP storage service.- Parameters:
factory
- to retrieve LDAP connections fromattrs
- to include in all LDAP entries
-
-
Method Details
-
isServerSide
public boolean isServerSide()Returns true iff the storage implementation manages data independent of the client.- Specified by:
isServerSide
in interfaceStorageCapabilitiesEx
- Returns:
- true iff the storage implementation manages data independent of the client
-
isClustered
public boolean isClustered()Returns true iff the storage implementation manages data independent of a single server node.- Specified by:
isClustered
in interfaceStorageCapabilitiesEx
- Returns:
- true iff the storage implementation manages data independent of a single server node
-
doInitialize
- Overrides:
doInitialize
in classAbstractStorageService
- Throws:
ComponentInitializationException
-
doDestroy
protected void doDestroy()- Overrides:
doDestroy
in classAbstractStorageService
-
create
public boolean create(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable @Positive Long expiration) throws IOException Creates a new record in the store with an expiration.- Specified by:
create
in interfaceStorageService
- Parameters:
context
- a storage context labelkey
- a key unique to contextvalue
- value to storeexpiration
- expiration for record, or null- Returns:
- true iff record was inserted, false iff a duplicate was found
- Throws:
IOException
- if fatal errors occur in the insertion process
-
read
@Nullable public <T> StorageRecord<T> read(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException Returns an existing record from the store, if one exists.- Specified by:
read
in interfaceStorageService
- Type Parameters:
T
- type of record- Parameters:
context
- a storage context labelkey
- a key unique to context- Returns:
- the record read back, if present, or null
- Throws:
IOException
- if errors occur in the read process
-
read
@Nonnull public <T> Pair<Long,StorageRecord<T>> read(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Positive long version) throws IOException Returns an existing record from the store, along with its version.The first member of the pair returned will contain the version of the record in the store, or will be null if no record exists. The second member will contain the record read back. If null, the record either didn't exist (if the first member was also null) or the record was the same version as that supplied by the caller.
- Specified by:
read
in interfaceStorageService
- Type Parameters:
T
- type of record- Parameters:
context
- a storage context labelkey
- a key unique to contextversion
- only return record if newer than supplied version- Returns:
- a pair consisting of the version of the record read back, if any, and the record itself
- Throws:
IOException
- if errors occur in the read process
-
update
public boolean update(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable @Positive Long expiration) throws IOException Updates an existing record in the store.- Specified by:
update
in interfaceStorageService
- Parameters:
context
- a storage context labelkey
- a key unique to contextvalue
- updated valueexpiration
- expiration for record, or null- Returns:
- true if the update succeeded, false if the record does not exist
- Throws:
IOException
- if errors occur in the update process
-
updateWithVersion
@Nullable public Long updateWithVersion(@Positive long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nonnull @NotEmpty String value, @Nullable @Positive Long expiration) throws IOException, VersionMismatchException Updates an existing record in the store, if a version matches.- Specified by:
updateWithVersion
in interfaceStorageService
- Parameters:
version
- only update if the current version matches this valuecontext
- a storage context labelkey
- a key unique to contextvalue
- updated valueexpiration
- expiration for record, or null- Returns:
- the version of the record after update, null if no record exists
- Throws:
IOException
- if errors occur in the update processVersionMismatchException
- if the record has already been updated to a newer version
-
updateExpiration
public boolean updateExpiration(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key, @Nullable @Positive Long expiration) throws IOException Updates expiration of an existing record in the store.- Specified by:
updateExpiration
in interfaceStorageService
- Parameters:
context
- a storage context labelkey
- a key unique to contextexpiration
- expiration for record, or null- Returns:
- true if the update succeeded, false if the record does not exist
- Throws:
IOException
- if errors occur in the update process
-
delete
public boolean delete(@Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException Deletes an existing record from the store.- Specified by:
delete
in interfaceStorageService
- Parameters:
context
- a storage context labelkey
- a key unique to context- Returns:
- true iff the record existed and was deleted
- Throws:
IOException
- if errors occur in the deletion process
-
deleteWithVersion
public boolean deleteWithVersion(@Positive long version, @Nonnull @NotEmpty String context, @Nonnull @NotEmpty String key) throws IOException, VersionMismatchException Deletes an existing record from the store if it currently has a specified version.- Specified by:
deleteWithVersion
in interfaceStorageService
- Parameters:
version
- record version to deletecontext
- a storage context labelkey
- a key unique to context- Returns:
- true iff the record existed and was deleted
- Throws:
IOException
- if errors occur in the deletion processVersionMismatchException
- if the record has already been updated to a newer version
-
reap
Manually trigger a cleanup of expired records. The method MAY return without guaranteeing that cleanup has already occurred.- Specified by:
reap
in interfaceStorageService
- Parameters:
context
- a storage context label- Throws:
IOException
- if errors occur in the cleanup process
-
updateContextExpiration
public void updateContextExpiration(@Nonnull @NotEmpty String context, @Nullable @Positive Long expiration) throws IOException Updates the expiration time of all records in the context.- Specified by:
updateContextExpiration
in interfaceStorageService
- Parameters:
context
- a storage context labelexpiration
- a new expiration timestamp, or null- Throws:
IOException
- if errors occur in the cleanup process
-
deleteContext
Forcibly removes all records in a given context along with any associated resources devoted to maintaining the context.- Specified by:
deleteContext
in interfaceStorageService
- Parameters:
context
- a storage context label- Throws:
IOException
- if errors occur in the cleanup process
-
merge
Executes aMergeOperation
with the supplied entry.- Parameters:
entry
- to merge- Returns:
- response for the merge operation
- Throws:
LdapException
- if the operation fails
-
search
@Nonnull private Response<SearchResult> search(@Nonnull String dn, String... attrs) throws LdapException Executes a object levelSearchOperation
on the supplied DN, returning the supplied attributes.- Parameters:
dn
- to search onattrs
- to return- Returns:
- response for the search operation
- Throws:
LdapException
- if the operation fails
-
deleteAttribute
@Nonnull private Response<Void> deleteAttribute(@Nonnull String dn, @Nonnull String attrName) throws LdapException Executes aModifyOperation
on the supplied DN, removing the supplied attribute.- Parameters:
dn
- to modifyattrName
- to remove- Returns:
- response for the modify operation
- Throws:
LdapException
- if the operation fails
-
delete
Executes aDeleteOperation
on the supplied DN.- Parameters:
dn
- to delete- Returns:
- response for the delete operation
- Throws:
LdapException
- if the operation fails
-