Class BaseSession
- java.lang.Object
-
- org.nuxeo.ecm.directory.BaseSession
-
- All Implemented Interfaces:
AutoCloseable
,EntrySource
,Session
- Direct Known Subclasses:
CoreDirectorySession
,LDAPSession
,MemoryDirectorySession
,MongoDBSession
,MultiDirectorySession
,SQLSession
public abstract class BaseSession extends Object implements Session, EntrySource
Base session class with helper methods common to all kinds of directory sessions.- Since:
- 5.2M4
- Author:
- Anahide Tchertchian
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BaseSession.FieldDetector
Visitor for a query to check if it contains a reference to a given field.
-
Field Summary
Fields Modifier and Type Field Description protected boolean
autoincrementId
protected boolean
computeMultiTenantId
protected Directory
directory
protected String
directoryName
protected static String
MULTI_TENANT_ID_FORMAT
protected String
passwordHashAlgorithm
protected PermissionDescriptor[]
permissions
protected static String
POWER_USERS_GROUP
protected boolean
readAllColumns
protected static String
READONLY_ENTRY_FLAG
protected Class<? extends Reference>
referenceClass
protected String
schemaName
protected BaseDirectoryDescriptor.SubstringMatchType
substringMatchType
protected static String
TENANT_ID_FIELD
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseSession(Directory directory, Class<? extends Reference> referenceClass)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected QueryBuilder
addTenantId(QueryBuilder queryBuilder)
Adds the tenant id to the query if needed.<T> List<T>
applyQueryLimits(List<T> list, int limit, int offset)
Applies offset and limit to a List.DocumentModelList
applyQueryLimits(DocumentModelList results, int limit, int offset)
Applies offset and limit to a DocumentModelListprotected boolean
canDeleteMultiTenantEntry(String entryId)
void
checkDeleteConstraints(String entryId)
Checks that there are no constraints for deleting the given entry id.void
checkPermission(String permission)
Checks the current user rights for the given permission against the read-only flag and the permission descriptor.static String
computeMultiTenantDirectoryId(String tenantId, String id)
Compute a multi tenant directory id based on the giventenantId
.DocumentModel
createEntry(Map<String,Object> fieldMap)
Creates an entry in a directory.DocumentModel
createEntry(DocumentModel documentModel)
Creates an entry in a directory.static DocumentModel
createEntryModel(String schema)
Returns a bare document model suitable for directory implementations.static DocumentModel
createEntryModel(String sessionId, String schema, String id, Map<String,Object> values)
Deprecated.since 11.1, sessionId is unusedstatic DocumentModel
createEntryModel(String sessionId, String schema, String id, Map<String,Object> values, boolean readOnly)
Deprecated.since 11.1, sessionId is unusedstatic DocumentModel
createEntryModel(String schema, String id, Map<String,Object> values)
Returns a bare document model suitable for directory implementations.static DocumentModel
createEntryModel(String schema, String id, Map<String,Object> values, boolean readOnly)
Returns a bare document model suitable for directory implementations.protected abstract DocumentModel
createEntryWithoutReferences(Map<String,Object> fieldMap)
To be implemented for specific creation.void
deleteEntry(String id)
Deletes a directory entry by id.void
deleteEntry(String id, Map<String,String> map)
Deprecated.void
deleteEntry(DocumentModel docModel)
Deletes a directory entry.protected abstract void
deleteEntryWithoutReferences(String id)
To be implemented for specific deletion.protected String
getCurrentTenantId()
Returns the tenant id of the logged user if any,null
otherwise.abstract Directory
getDirectory()
To be implemented with a more specific return type.DocumentModelList
getEntries()
Retrieves all the entries in the directory.DocumentModel
getEntry(String id)
Retrieves a directory entry using its id.DocumentModel
getEntry(String id, boolean fetchReferences)
Retrieves a directory entry using its id.DocumentModel
getEntryFromSource(String id, boolean fetchReferences)
String
getIdField()
The Id field is the name of the field that is used a primary key: unique and not null value in the whole directory.String
getPasswordField()
List<String>
getProjection(Map<String,Serializable> filter, String columnName)
Executes a query using filter and return only the column columnName.List<String>
getProjection(Map<String,Serializable> filter, Set<String> fulltext, String columnName)
boolean
hasPermission(String permission)
Checks the current user rights for the given permission against the read-only flag and the permission descriptor.protected boolean
hasPermission(String permission, String username, List<String> groups)
boolean
isAuthenticating()
Tells whether the directory implementation can be used as an authenticating backend for the UserManager (based on login / password check).protected boolean
isMultiTenant()
Returnstrue
if this directory supports multi tenancy,false
otherwise.boolean
isReadOnly()
static boolean
isReadOnlyEntry(DocumentModel entry)
Test whether entry comes from a read-only back-end directory.DocumentModelList
query(Map<String,Serializable> filter)
Executes a simple query.DocumentModelList
query(Map<String,Serializable> filter, Set<String> fulltext)
Executes a simple query.DocumentModelList
query(Map<String,Serializable> filter, Set<String> fulltext, Map<String,String> orderBy)
Executes a simple query.DocumentModelList
query(Map<String,Serializable> filter, Set<String> fulltext, Map<String,String> orderBy, boolean fetchReferences)
Executes a query with the possibility to fetch referencesvoid
setReadAllColumns(boolean readAllColumns)
For test framework.static void
setReadOnlyEntry(DocumentModel entry)
Set the read-only flag of a directory entry.static void
setReadWriteEntry(DocumentModel entry)
Unset the read-only flag of a directory entry.static List<String>
toStringList(Object value)
void
updateEntry(DocumentModel docModel)
Updates a directory entry.protected abstract List<String>
updateEntryWithoutReferences(DocumentModel docModel)
To be implemented for specific update.
-
-
-
Field Detail
-
POWER_USERS_GROUP
protected static final String POWER_USERS_GROUP
- See Also:
- Constant Field Values
-
READONLY_ENTRY_FLAG
protected static final String READONLY_ENTRY_FLAG
- See Also:
- Constant Field Values
-
MULTI_TENANT_ID_FORMAT
protected static final String MULTI_TENANT_ID_FORMAT
- See Also:
- Constant Field Values
-
TENANT_ID_FIELD
protected static final String TENANT_ID_FIELD
- See Also:
- Constant Field Values
-
directory
protected final Directory directory
-
permissions
protected PermissionDescriptor[] permissions
-
readAllColumns
protected boolean readAllColumns
-
schemaName
protected String schemaName
-
directoryName
protected String directoryName
-
substringMatchType
protected BaseDirectoryDescriptor.SubstringMatchType substringMatchType
-
passwordHashAlgorithm
protected String passwordHashAlgorithm
-
autoincrementId
protected boolean autoincrementId
-
computeMultiTenantId
protected boolean computeMultiTenantId
-
-
Method Detail
-
getDirectory
public abstract Directory getDirectory()
To be implemented with a more specific return type.
-
setReadAllColumns
public void setReadAllColumns(boolean readAllColumns)
Description copied from interface:Session
For test framework. Changes the read/query methods to return all of the entries, including the password field.- Specified by:
setReadAllColumns
in interfaceSession
- Parameters:
readAllColumns
- whether to read all columns
-
getIdField
public String getIdField()
Description copied from interface:Session
The Id field is the name of the field that is used a primary key: unique and not null value in the whole directory. This field is also used as login field if the directory is authenticating.- Specified by:
getIdField
in interfaceSession
- Returns:
- the name of the id field
-
getPasswordField
public String getPasswordField()
- Specified by:
getPasswordField
in interfaceSession
- Returns:
- the name of the field to store the password if the directory is authenticating (can be null)
-
isAuthenticating
public boolean isAuthenticating()
Description copied from interface:Session
Tells whether the directory implementation can be used as an authenticating backend for the UserManager (based on login / password check).- Specified by:
isAuthenticating
in interfaceSession
- Returns:
- true is the directory is authentication aware
-
isReadOnly
public boolean isReadOnly()
- Specified by:
isReadOnly
in interfaceSession
-
checkPermission
public void checkPermission(String permission)
Checks the current user rights for the given permission against the read-only flag and the permission descriptor.Throws
DirectorySecurityException
if the user does not have adequate privileges.- Throws:
DirectorySecurityException
- if access is denied- Since:
- 8.3
-
checkDeleteConstraints
public void checkDeleteConstraints(String entryId)
Checks that there are no constraints for deleting the given entry id.- Since:
- 8.4
-
hasPermission
public boolean hasPermission(String permission)
Checks the current user rights for the given permission against the read-only flag and the permission descriptor.Returns
false
if the user does not have adequate privileges.- Returns:
false
if access is denied- Since:
- 8.3
-
hasPermission
protected boolean hasPermission(String permission, String username, List<String> groups)
-
createEntryModel
@Deprecated public static DocumentModel createEntryModel(String sessionId, String schema, String id, Map<String,Object> values) throws PropertyException
Deprecated.since 11.1, sessionId is unusedReturns a bare document model suitable for directory implementations.Can be used for creation screen.
- Throws:
PropertyException
- Since:
- 5.2M4
-
createEntryModel
public static DocumentModel createEntryModel(String schema)
Returns a bare document model suitable for directory implementations.- Parameters:
schema
- the directory schema- Returns:
- the directory entry
- Since:
- 11.1
-
createEntryModel
public static DocumentModel createEntryModel(String schema, String id, Map<String,Object> values)
Returns a bare document model suitable for directory implementations.- Parameters:
schema
- the directory schemaid
- the entry idvalues
- the entry values, ornull
- Returns:
- the directory entry
- Since:
- 11.1
-
createEntryModel
@Deprecated public static DocumentModel createEntryModel(String sessionId, String schema, String id, Map<String,Object> values, boolean readOnly) throws PropertyException
Deprecated.since 11.1, sessionId is unusedReturns a bare document model suitable for directory implementations.Allow setting the readonly entry flag to
Boolean.TRUE
. SeeSession#isReadOnlyEntry(DocumentModel)
- Throws:
PropertyException
- Since:
- 5.3.1
-
createEntryModel
public static DocumentModel createEntryModel(String schema, String id, Map<String,Object> values, boolean readOnly)
Returns a bare document model suitable for directory implementations.Allow setting the readonly entry flag to
Boolean.TRUE
. SeeSession#isReadOnlyEntry(DocumentModel)
- Parameters:
schema
- the directory schemaid
- the entry idvalues
- the entry values, ornull
readOnly
- the readonly flag- Returns:
- the directory entry
- Since:
- 11.1
-
isReadOnlyEntry
public static boolean isReadOnlyEntry(DocumentModel entry)
Test whether entry comes from a read-only back-end directory.- Since:
- 5.3.1
-
setReadOnlyEntry
public static void setReadOnlyEntry(DocumentModel entry)
Set the read-only flag of a directory entry. To be used by EntryAdaptor implementations for instance.- Since:
- 5.3.2
-
setReadWriteEntry
public static void setReadWriteEntry(DocumentModel entry)
Unset the read-only flag of a directory entry. To be used by EntryAdaptor implementations for instance.- Since:
- 5.3.2
-
computeMultiTenantDirectoryId
public static String computeMultiTenantDirectoryId(String tenantId, String id)
Compute a multi tenant directory id based on the giventenantId
.- Returns:
- the computed directory id
- Since:
- 5.6
-
getEntry
public DocumentModel getEntry(String id)
Description copied from interface:Session
Retrieves a directory entry using its id.TODO what happens when the entry is not found? return null if not found?
-
getEntry
public DocumentModel getEntry(String id, boolean fetchReferences)
Description copied from interface:Session
Retrieves a directory entry using its id.
-
getEntries
public DocumentModelList getEntries()
Description copied from interface:Session
Retrieves all the entries in the directory. If the remote server issues a size limit exceeded error while sending partial results up to that limit, the methodDocumentModelList#totalsize
on the returned list will return -2 as a special marker for truncated results.- Specified by:
getEntries
in interfaceSession
- Returns:
- a collection with all the entries in the directory
-
getEntryFromSource
public DocumentModel getEntryFromSource(String id, boolean fetchReferences)
- Specified by:
getEntryFromSource
in interfaceEntrySource
-
createEntry
public DocumentModel createEntry(DocumentModel documentModel)
Description copied from interface:Session
Creates an entry in a directory.- Specified by:
createEntry
in interfaceSession
- Parameters:
documentModel
- the document model representing the entry to create- Returns:
- The new entry created in the directory
-
createEntry
public DocumentModel createEntry(Map<String,Object> fieldMap)
Description copied from interface:Session
Creates an entry in a directory.- Specified by:
createEntry
in interfaceSession
- Parameters:
fieldMap
- A map with keys and values that should be stored in a directoryNote: The values in the map should be of type String
- Returns:
- The new entry created in the directory
-
updateEntry
public void updateEntry(DocumentModel docModel)
Description copied from interface:Session
Updates a directory entry.- Specified by:
updateEntry
in interfaceSession
- Parameters:
docModel
- The entry to update
-
deleteEntry
public void deleteEntry(DocumentModel docModel)
Description copied from interface:Session
Deletes a directory entry.- Specified by:
deleteEntry
in interfaceSession
- Parameters:
docModel
- The entry to delete
-
deleteEntry
@Deprecated public void deleteEntry(String id, Map<String,String> map)
Deprecated.Description copied from interface:Session
Deletes a directory entry by id and secondary ids.This is used for hierarchical vocabularies, where the actual unique key is the couple (parent, id).
- Specified by:
deleteEntry
in interfaceSession
- Parameters:
id
- the id of the entry to delete.map
- a map of secondary key values.
-
deleteEntry
public void deleteEntry(String id)
Description copied from interface:Session
Deletes a directory entry by id.- Specified by:
deleteEntry
in interfaceSession
- Parameters:
id
- the id of the entry to delete
-
canDeleteMultiTenantEntry
protected boolean canDeleteMultiTenantEntry(String entryId)
-
applyQueryLimits
public DocumentModelList applyQueryLimits(DocumentModelList results, int limit, int offset)
Applies offset and limit to a DocumentModelList- Parameters:
results
- the query results without limit and offetlimit
- maximum number of results ignored if less than 1offset
- number of rows skipped before starting, will be 0 if less than 0.- Returns:
- the result with applied limit and offset
- Since:
- 10.1
- See Also:
Session.query(Map, Set, Map, boolean, int, int)
-
applyQueryLimits
public <T> List<T> applyQueryLimits(List<T> list, int limit, int offset)
Applies offset and limit to a List.- Parameters:
list
- the original listlimit
- maximum number of results, ignored if less than 1offset
- number of rows skipped before starting, will be 0 if less than 0- Returns:
- the result with applied limit and offset
- Since:
- 10.3
-
query
public DocumentModelList query(Map<String,Serializable> filter)
Description copied from interface:Session
Executes a simple query. The conditions will be 'AND'-ed. Search is done with exact match.Does not fetch reference fields.
If the remote server issues a size limit exceeded error while sending partial results up to that limit, the methodDocumentModelList#totalsize
on the returned list will return -2 as a special marker for truncated results.
-
query
public DocumentModelList query(Map<String,Serializable> filter, Set<String> fulltext)
Description copied from interface:Session
Executes a simple query. The conditions will be 'AND'-ed.fieldNames present in the fulltext set are treated as a fulltext match. Does not fetch reference fields.
If the remote server issues a size limit exceeded error while sending partial results up to that limit, the methodDocumentModelList#totalsize
on the returned list will return -2 as a special marker for truncated results.
-
query
public DocumentModelList query(Map<String,Serializable> filter, Set<String> fulltext, Map<String,String> orderBy)
Description copied from interface:Session
Executes a simple query. The conditions will be 'AND'-ed and the result will be sorted by the orderBy criteria list.fieldNames present in the fulltext set are treated as a fulltext match. Does not fetch reference fields.
If the remote server issues a size limit exceeded error while sending partial results up to that limit, the methodDocumentModelList#totalsize
on the returned list will return -2 as a special marker for truncated results.- Specified by:
query
in interfaceSession
- Parameters:
filter
- a filter to apply to entries in directoryfulltext
- a set of field that should be treated as a fulltext searchorderBy
- a LinkedHashMap with the 'order by' criterias.The key of an entry of this map represents the column name and the value of the same entry represent the column order,which may be 'asc' or 'desc'.- Returns:
- a list of document models containing the entries matched by the query
-
query
public DocumentModelList query(Map<String,Serializable> filter, Set<String> fulltext, Map<String,String> orderBy, boolean fetchReferences)
Description copied from interface:Session
Executes a query with the possibility to fetch references- Specified by:
query
in interfaceSession
- See Also:
Session.query(Map, Set, Map)
-
getProjection
public List<String> getProjection(Map<String,Serializable> filter, String columnName)
Description copied from interface:Session
Executes a query using filter and return only the column columnName.- Specified by:
getProjection
in interfaceSession
- Parameters:
filter
- the filter for the querycolumnName
- the column whose content should be returned- Returns:
- the list with the values of columnName for the entries matching filter
-
getProjection
public List<String> getProjection(Map<String,Serializable> filter, Set<String> fulltext, String columnName)
- Specified by:
getProjection
in interfaceSession
-
isMultiTenant
protected boolean isMultiTenant()
Returnstrue
if this directory supports multi tenancy,false
otherwise.
-
addTenantId
protected QueryBuilder addTenantId(QueryBuilder queryBuilder)
Adds the tenant id to the query if needed.- Since:
- 10.3
-
getCurrentTenantId
protected String getCurrentTenantId()
Returns the tenant id of the logged user if any,null
otherwise.
-
createEntryWithoutReferences
protected abstract DocumentModel createEntryWithoutReferences(Map<String,Object> fieldMap)
To be implemented for specific creation.
-
updateEntryWithoutReferences
protected abstract List<String> updateEntryWithoutReferences(DocumentModel docModel)
To be implemented for specific update.
-
deleteEntryWithoutReferences
protected abstract void deleteEntryWithoutReferences(String id)
To be implemented for specific deletion.
-
-