Nuxeo ECM Projects 5.4.3-SNAPSHOT

org.nuxeo.ecm.directory.ldap
Class LDAPSession

java.lang.Object
  extended by org.nuxeo.ecm.directory.BaseSession
      extended by org.nuxeo.ecm.directory.ldap.LDAPSession
All Implemented Interfaces:
EntrySource, Session

public class LDAPSession
extends BaseSession
implements EntrySource

This class represents a session against an LDAPDirectory.

Author:
Olivier Grisel

Constructor Summary
LDAPSession(LDAPDirectory directory, DirContext dirContext)
           
 
Method Summary
 boolean authenticate(String username, String password)
          Checks that the credentials provided by the UserManager match those registered in the directory.
 void close()
          Closes the session and all open result sets obtained from this session.
 void commit()
           
 DocumentModel createEntry(DocumentModel entry)
          Creates an entry in a directory.
 DocumentModel createEntry(Map<String,Object> fieldMap)
          Creates an entry in a directory.
 void deleteEntry(DocumentModel dm)
          Deletes a directory entry.
 void deleteEntry(String id)
          Deletes a directory entry by id.
 void deleteEntry(String id, Map<String,String> map)
          Deletes a directory entry by id and secondary ids.
 DirContext getContext()
           
 Directory getDirectory()
           
 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, Set<String> fulltext, String columnName)
           
 List<String> getProjection(Map<String,Serializable> filter, String columnName)
          Executes a query using filter and return only the column columnName.
 boolean hasEntry(String id)
          Returns true if session has an entry with given id.
 boolean isAuthenticating()
          Tells whether the directory implementation can be used as an authenticating backend for the UserManager (based on login / password check).
 boolean isReadOnly()
           
 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, boolean fetchReferences, Map<String,String> orderBy)
           
 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 references
 boolean rdnMatchesIdField()
           
 void rollback()
           
 void setSubStringMatchType(String type)
           
 String toString()
           
 void updateEntry(DocumentModel docModel)
          Updates a directory entry.
 
Methods inherited from class org.nuxeo.ecm.directory.BaseSession
createEntryModel, createEntryModel, isReadOnlyEntry, setReadOnlyEntry, setReadWriteEntry
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LDAPSession

public LDAPSession(LDAPDirectory directory,
                   DirContext dirContext)
Method Detail

setSubStringMatchType

public void setSubStringMatchType(String type)

getDirectory

public Directory getDirectory()

getContext

public DirContext getContext()

createEntry

public DocumentModel createEntry(Map<String,Object> fieldMap)
                          throws DirectoryException
Description copied from interface: Session
Creates an entry in a directory.

Specified by:
createEntry in interface Session
Parameters:
fieldMap - A map with 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
Throws:
DirectoryException - if a communication exception occurs or if an entry with the same id already exists.

getEntry

public DocumentModel getEntry(String id)
                       throws DirectoryException
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?

Specified by:
getEntry in interface Session
Parameters:
id - the entry id
Returns:
a DocumentModel representing the entry
Throws:
DirectoryException

getEntry

public DocumentModel getEntry(String id,
                              boolean fetchReferences)
                       throws DirectoryException
Description copied from interface: Session
Retrieves a directory entry using its id.

Specified by:
getEntry in interface Session
Parameters:
id - the entry id
fetchReferences - boolean stating if references have to be fetched
Returns:
a DocumentModel representing the entry
Throws:
DirectoryException

getEntryFromSource

public DocumentModel getEntryFromSource(String id,
                                        boolean fetchReferences)
                                 throws DirectoryException
Specified by:
getEntryFromSource in interface EntrySource
Throws:
DirectoryException

hasEntry

public boolean hasEntry(String id)
                 throws DirectoryException
Description copied from interface: Session
Returns true if session has an entry with given id.

Specified by:
hasEntry in interface Session
Throws:
DirectoryException

getEntries

public DocumentModelList getEntries()
                             throws DirectoryException
Description copied from interface: Session
Retrieves all the entries in the directory.

Specified by:
getEntries in interface Session
Returns:
a collection with all the entries in the directory
Throws:
DirectoryException
SizeLimitExceededException - if the number of results is larger than the limit configured for the directory

updateEntry

public void updateEntry(DocumentModel docModel)
                 throws DirectoryException
Description copied from interface: Session
Updates a directory entry.

Specified by:
updateEntry in interface Session
Parameters:
docModel - The entry to update
Throws:
DirectoryException - if a communication error occurs

deleteEntry

public void deleteEntry(DocumentModel dm)
                 throws DirectoryException
Description copied from interface: Session
Deletes a directory entry.

Specified by:
deleteEntry in interface Session
Parameters:
dm - The entry to delete
Throws:
DirectoryException - if a communication error occurs

deleteEntry

public void deleteEntry(String id)
                 throws DirectoryException
Description copied from interface: Session
Deletes a directory entry by id.

Specified by:
deleteEntry in interface Session
Parameters:
id - the id of the entry to delete
Throws:
DirectoryException - if a communication error occurs

deleteEntry

public void deleteEntry(String id,
                        Map<String,String> map)
                 throws DirectoryException
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 interface Session
Parameters:
id - the id of the entry to delete.
map - a map of seconday key values.
Throws:
DirectoryException - if a communication error occurs.

query

public DocumentModelList query(Map<String,Serializable> filter,
                               Set<String> fulltext,
                               boolean fetchReferences,
                               Map<String,String> orderBy)
                        throws DirectoryException
Throws:
DirectoryException

query

public DocumentModelList query(Map<String,Serializable> filter)
                        throws DirectoryException
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.

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
Throws:
DirectoryException - if a communication error occurs
SizeLimitExceededException - if the number of results is larger than the limit configured for the directory

query

public DocumentModelList query(Map<String,Serializable> filter,
                               Set<String> fulltext,
                               Map<String,String> orderBy)
                        throws DirectoryException
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.

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
Throws:
DirectoryException - if a communication error occurs
SizeLimitExceededException - if the number of results is larger than the limit configured for the directory

query

public DocumentModelList query(Map<String,Serializable> filter,
                               Set<String> fulltext,
                               Map<String,String> orderBy,
                               boolean fetchReferences)
                        throws DirectoryException
Description copied from interface: Session
Executes a query with the possibility to fetch references

Specified by:
query in interface Session
Throws:
DirectoryException
See Also:
Session.query(Map, Set, Map)

query

public DocumentModelList query(Map<String,Serializable> filter,
                               Set<String> fulltext)
                        throws DirectoryException
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.

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
Throws:
DirectoryException - if a communication error occurs
SizeLimitExceededException - if the number of results is larger than the limit configured for the directory

commit

public void commit()
Specified by:
commit in interface Session

rollback

public void rollback()
Specified by:
rollback in interface Session

close

public void close()
           throws DirectoryException
Description copied from interface: Session
Closes the session and all open result sets obtained from this session.

Releases this Connection object's resources immediately instead of waiting for them to be automatically released.

TODO: should this operation auto-commit pending changes?

Specified by:
close in interface Session
Throws:
DirectoryException - if a communication error occurs

getProjection

public List<String> getProjection(Map<String,Serializable> filter,
                                  String columnName)
                           throws DirectoryException
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
Throws:
DirectoryException
SizeLimitExceededException - if the number of results is larger than the limit configured for the directory

getProjection

public List<String> getProjection(Map<String,Serializable> filter,
                                  Set<String> fulltext,
                                  String columnName)
                           throws DirectoryException
Specified by:
getProjection in interface Session
Throws:
DirectoryException

authenticate

public boolean authenticate(String username,
                            String password)
                     throws DirectoryException
Description copied from interface: Session
Checks that the credentials provided by the UserManager match those registered in the directory. If username is not in the directory, this should return false instead of throrwing an exception.

Specified by:
authenticate in interface Session
Returns:
true is the credentials match those stored in the directory
Throws:
DirectoryException

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

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()
                         throws DirectoryException
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
Throws:
DirectoryException

isReadOnly

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

rdnMatchesIdField

public boolean rdnMatchesIdField()

toString

public String toString()
Overrides:
toString in class Object

createEntry

public DocumentModel createEntry(DocumentModel entry)
                          throws ClientException
Description copied from interface: Session
Creates an entry in a directory.

Specified by:
createEntry in interface Session
Parameters:
entry - the document model representing the entry to create
Returns:
The new entry created in the directory
Throws:
ClientException - if a communication exception occurs or if an entry with the same id already exists.

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.