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
  • Field Details

  • Constructor Details

  • Method Details

    • 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 interface Session
      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 interface Session
      Returns:
      the name of the id field
    • getPrefixedIdField

      protected String getPrefixedIdField()
    • getPasswordField

      public String getPasswordField()
      Specified by:
      getPasswordField in interface Session
      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 interface Session
      Returns:
      true is the directory is authentication aware
    • isReadOnly

      public boolean isReadOnly()
      Specified by:
      isReadOnly in interface Session
    • getPrefixedFieldName

      protected String getPrefixedFieldName(String fieldName)
      Get the prefixed version of the given fieldName.
      Since:
      2025.9
    • 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 unused
      Returns a bare document model suitable for directory implementations.

      Can be used for creation screen.

      Throws:
      PropertyException
      Since:
      5.2M4
    • createEntryModel

      @Deprecated(since="2025.9", forRemoval=true) public static DocumentModel createEntryModel(String schema)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 2025.9, use Directory.createBareDocumentModel() instead
      Returns a bare document model suitable for directory implementations.
      Parameters:
      schema - the directory schema
      Returns:
      the directory entry
      Since:
      11.1
    • createEntryModel

      @Deprecated(since="2025.9", forRemoval=true) public static DocumentModel createEntryModel(String schema, String id, Map<String,Object> values)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns a bare document model suitable for directory implementations.
      Parameters:
      schema - the directory schema
      id - the entry id
      values - the entry values, or null
      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 unused
      Returns a bare document model suitable for directory implementations.

      Allow setting the readonly entry flag to Boolean.TRUE. See Session#isReadOnlyEntry(DocumentModel)

      Throws:
      PropertyException
      Since:
      5.3.1
    • createEntryModel

      @Deprecated(since="2025.9", forRemoval=true) public static DocumentModel createEntryModel(String schema, String id, Map<String,Object> values, boolean readOnly)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns a bare document model suitable for directory implementations.

      Allow setting the readonly entry flag to Boolean.TRUE. See Session#isReadOnlyEntry(DocumentModel)

      Parameters:
      schema - the directory schema
      id - the entry id
      values - the entry values, or null
      readOnly - the readonly flag
      Returns:
      the directory entry
      Since:
      11.1
    • createEntryModel

      public DocumentModel createEntryModel(@Nullable String id, @Nullable Map<String,Object> values)
      Description copied from interface: Session
      Returns a bare document model suitable for directory implementations.
      Specified by:
      createEntryModel in interface Session
      Parameters:
      id - the entry id, or null
      values - the entry values, or null
      Returns:
      the directory entry
    • 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 given tenantId.
      Returns:
      the computed directory id
      Since:
      5.6
    • getEntry

      public DocumentModel getEntry(@Nullable String idOrSysId, boolean fetchReferences)
      Description copied from interface: Session
      Retrieves a directory entry using its id.
      Specified by:
      getEntry in interface Session
      Parameters:
      idOrSysId - the entry id
      fetchReferences - boolean stating if references have to be fetched
      Returns:
      a DocumentModel representing the entry
    • getEntryFromSource

      public DocumentModel getEntryFromSource(@Nullable String idOrSysId, boolean fetchReferences)
      Specified by:
      getEntryFromSource in interface EntrySource
    • hasEntry

      public boolean hasEntry(String idOrSysId)
      Description copied from interface: Session
      Returns true if session has an entry with given id.
      Specified by:
      hasEntry in interface Session
    • createEntry

      public DocumentModel createEntry(DocumentModel documentModel)
      Description copied from interface: Session
      Creates an entry in a directory.
      Specified by:
      createEntry in interface Session
      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 interface Session
      Parameters:
      fieldMap - A map with (prefixed) keys and values that should be stored in a directory

      Note: The values in the map should be of type String

      Returns:
      The new entry created in the directory
    • createEntryWithoutReferences

      protected DocumentModel createEntryWithoutReferences(Map<String,Object> fieldMap)
      Creates an entry to the directory without creating its references.
      Since:
      2025.9
      Implementation Note:
      it was abstract before 2025.9
    • updateEntry

      public void updateEntry(DocumentModel docModel)
      Description copied from interface: Session
      Updates a directory entry.
      Specified by:
      updateEntry in interface Session
      Parameters:
      docModel - The entry to update
    • updateEntryWithoutReferences

      protected List<String> updateEntryWithoutReferences(DocumentModel docModel)
      Updates an entry to the directory without updating its references.
      Since:
      2025.9
      Implementation Note:
      it was abstract before 2025.9
    • toStringList

      public static List<String> toStringList(Object value)
    • deleteEntry

      public void deleteEntry(DocumentModel docModel)
      Description copied from interface: Session
      Deletes a directory entry.
      Specified by:
      deleteEntry in interface Session
      Parameters:
      docModel - The entry to delete
    • deleteEntry

      public void deleteEntry(String idOrSysId)
      Description copied from interface: Session
      Deletes a directory entry by id.
      Specified by:
      deleteEntry in interface Session
      Parameters:
      idOrSysId - the id of the entry to delete
    • deleteEntryWithoutReferences

      protected void deleteEntryWithoutReferences(String entryId)
      Deletes an entry from the directory without deleting its references.
      Since:
      2025.9
      Implementation Note:
      it was abstract before 2025.9
    • canDeleteMultiTenantEntry

      @Deprecated(since="2025.9", forRemoval=true) protected boolean canDeleteMultiTenantEntry(String entryId)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 2025.9, unused
    • canDeleteMultiTenantEntry

      protected boolean canDeleteMultiTenantEntry(DocumentModel entry)
      Since:
      2025.9
    • 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 offet
      limit - maximum number of results ignored if less than 1
      offset - 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:
    • applyQueryLimits

      public <T> List<T> applyQueryLimits(List<T> list, int limit, int offset)
      Applies offset and limit to a List.
      Parameters:
      list - the original list
      limit - maximum number of results, ignored if less than 1
      offset - 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 method DocumentModelList#totalsize on the returned list will return -2 as a special marker for truncated results.
      Specified by:
      query in interface Session
      Parameters:
      filter - a filter to apply to entries in directory
      Returns:
      a list of document models containing the entries matched by the query
    • 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 method DocumentModelList#totalsize on the returned list will return -2 as a special marker for truncated results.
      Specified by:
      query in interface Session
      Parameters:
      filter - a filter to apply to entries in directory
      fulltext - a set of field that should be treated as a fulltext search
      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)
      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 method DocumentModelList#totalsize on the returned list will return -2 as a special marker for truncated results.
      Specified by:
      query in interface Session
      Parameters:
      filter - a filter to apply to entries in directory
      fulltext - a set of field that should be treated as a fulltext search
      orderBy - 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 interface Session
      See Also:
    • query

      public DocumentModelList query(QueryBuilder queryBuilder, boolean fetchReferences)
      Description copied from interface: Session
      Executes a query with the possibility to fetch a subset of the results.
      Specified by:
      query in interface Session
      Parameters:
      queryBuilder - the query to use, including limit, offset, ordering and countTotal
      fetchReferences - boolean stating if references have to be fetched
      Returns:
      the list of documents, where the total size may be present if countTotal was true
    • query

      @Deprecated(since="2021.x") public DocumentModelList query(QueryBuilder queryBuilder)
      Deprecated.
      since 2021.x, BaseSession is providing a generic implementation, you should implement doQuery(DirectoryQueryBuilder) instead
      Description copied from interface: Session
      Executes a query with the possibility to fetch a subset of the results.

      You can use this API with DirectoryQueryBuilder to fetch references.

      Specified by:
      query in interface Session
      Parameters:
      queryBuilder - the query to use, including limit, offset, ordering and countTotal
      Returns:
      the list of documents, where the total size may be present if countTotal was true
      Since:
      2025.9
      See Also:
      Implementation Note:
      on deprecation removal, remove the annotations and deprecated javadoc
    • queryIds

      @Deprecated(since="2021.x") public List<String> queryIds(QueryBuilder queryBuilder)
      Deprecated.
      since 2021.x, BaseSession is providing a generic implementation, you should implement doQueryIds(DirectoryQueryBuilder) instead
      Description copied from interface: Session
      Executes a query with the possibility to fetch a subset of the results. Returns the matching ids.
      Specified by:
      queryIds in interface Session
      Parameters:
      queryBuilder - the query to use, including limit, offset and ordering
      Returns:
      the list of document ids
      Since:
      2025.9
      See Also:
      Implementation Note:
      on deprecation removal, remove the annotations and deprecated javadoc
    • createQueryBuilderForIds

      protected DirectoryQueryBuilder createQueryBuilderForIds(@Nullable String id, @Nullable String... ids)
      Creates a DirectoryQueryBuilder that filter in entry having given id or ids as directory entry id of any kind.
      Since:
      2025.9
    • createQueryBuilderWithConfiguredFiltering

      protected DirectoryQueryBuilder createQueryBuilderWithConfiguredFiltering(QueryBuilder queryBuilder)
      Turns the given QueryBuilder to a DirectoryQueryBuilder to ease some access to directories specificities, such as DirectoryQueryBuilder.fetchReferences().

      Also, adds additional filters based on directory setup, such as tenantId.

      Since:
      2025.9
    • createQueryBuilderWithConfiguredFiltering

      protected DirectoryQueryBuilder createQueryBuilderWithConfiguredFiltering(QueryBuilder queryBuilder, boolean includeNoTenant)
      Turns the given QueryBuilder to a DirectoryQueryBuilder to ease some access to directories specificities, such as DirectoryQueryBuilder.fetchReferences().

      Also, adds additional filters based on directory setup, such as tenantId.

      Parameters:
      includeNoTenant - whether the entry without tenant should be included in response
      Since:
      2025.9
    • 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 interface Session
      Parameters:
      filter - the filter for the query
      columnName - 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 interface Session
    • isMultiTenant

      protected boolean isMultiTenant()
      Returns true if this directory supports multi tenancy, false otherwise.
    • addTenantId

      @Deprecated(since="2025.9", forRemoval=true) protected QueryBuilder addTenantId(QueryBuilder queryBuilder)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 2025.9, not useful anymore since introduction of createQueryBuilderWithConfiguredFiltering(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.
    • doCreateEntryWithoutReferences

      @Deprecated(since="2021.x") protected DocumentModel doCreateEntryWithoutReferences(Map<String,Object> fieldMap)
      Deprecated.
      since 2021.x, the method remains for use, but it will be turned abstract
      To be implemented for specific creation.
    • doUpdateEntryWithoutReferences

      @Deprecated(since="2021.x") protected List<String> doUpdateEntryWithoutReferences(DocumentModel docModel)
      Deprecated.
      since 2021.x, the method remains for use, but it will be turned abstract
      To be implemented for specific update.
    • doDeleteEntryWithoutReferences

      @Deprecated(since="2021.x") protected void doDeleteEntryWithoutReferences(String entryId)
      Deprecated.
      since 2021.x, the method remains for use, but it will be turned abstract
      To be implemented for specific deletion.
    • doQuery

      @Deprecated(since="2021.x") protected DocumentModelList doQuery(DirectoryQueryBuilder queryBuilder)
      Deprecated.
      since 2021.x, the method will remain on deprecation cleanup
      To be implemented for specific querying.
      See Also:
      Implementation Note:
      on deprecation removal, turn this method abstract, remove the annotations and the deprecated javadoc
    • doQueryIds

      @Deprecated(since="2021.x") protected List<String> doQueryIds(DirectoryQueryBuilder queryBuilder)
      Deprecated.
      since 2021.x, the method remains for use, but it will be turned abstract
      To be implemented for specific querying.
      See Also:
      Implementation Note:
      on deprecation removal, turn this method abstract, remove the annotations and the deprecated javadoc