--- /dev/null
+/*****************************************************************************
+ * Copyright Igor Barma, Eric Brun, Alexandre Desoubeaux, Christian Martel,
+ * (2 décembre 2008)
+ *
+ * Ce logiciel est un programme informatique servant à l'évaluation des
+ * compétences.
+ *
+ * Ce logiciel est régi par la licence CeCILL soumise au droit français et
+ * respectant les principes de diffusion des logiciels libres. Vous pouvez
+ * utiliser, modifier et/ou redistribuer ce programme sous les conditions
+ * de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
+ * sur le site "http://www.cecill.info".
+ *
+ * En contrepartie de l'accessibilité au code source et des droits de copie,
+ * de modification et de redistribution accordés par cette licence, il n'est
+ * offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
+ * seule une responsabilité restreinte pèse sur l'auteur du programme, le
+ * titulaire des droits patrimoniaux et les concédants successifs.
+ *
+ * A cet égard l'attention de l'utilisateur est attirée sur les risques
+ * associés au chargement, à l'utilisation, à la modification et/ou au
+ * développement et à la reproduction du logiciel par l'utilisateur étant
+ * donné sa spécificité de logiciel libre, qui peut le rendre complexe à
+ * manipuler et qui le réserve donc à des développeurs et des professionnels
+ * avertis possédant des connaissances informatiques approfondies. Les
+ * utilisateurs sont donc invités à charger et tester l'adéquation du
+ * logiciel à leurs besoins dans des conditions permettant d'assurer la
+ * sécurité de leurs systèmes et ou de leurs données et, plus généralement,
+ * à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
+ *
+ * Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
+ * pris connaissance de la licence CeCILL, et que vous en avez accepté les
+ * termes.
+ *******************************************************************************/
+
+package com.pentila.evalcomp.ldap;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.springframework.ldap.core.DirContextAdapter;
+import org.springframework.ldap.core.DistinguishedName;
+import org.springframework.ldap.core.LdapTemplate;
+import org.springframework.ldap.filter.Filter;
+
+import com.pentila.evalcomp.domain.Entity;
+import com.pentila.evalcomp.domain.Group;
+import com.pentila.evalcomp.domain.User;
+import com.pentila.evalcomp.synchronization.model.Identifier;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Interface ILdapTools.
+ */
+public interface ILdapTools {
+ // **************************** Entity manipulation
+ // **********************************************************
+ /**
+ * Add entity to ldap.
+ *
+ * @param entity
+ * the object to be added
+ */
+ public void add(Entity entity);
+
+ /**
+ * Builds the dn necessary to obtain an entity from ldap. The dn is build
+ * using the uid of the entity object. The dn has the ldap conventions
+ * format.
+ *
+ * @param entity
+ * the entity
+ *
+ * @return the distinguished name
+ */
+ public DistinguishedName buildDn(Entity entity);
+
+ /**
+ * The dn is build using the uid. The dn has the ldap conventions format.
+ *
+ * @param uid
+ * the uid
+ * @param isGroup
+ * the is group
+ *
+ * @return the distinguished name
+ */
+ public DistinguishedName buildDn(String uid, boolean isGroup);
+
+ // **************************** General usage
+ // methods*********************************************************
+
+ /**
+ * Delete an entity from ldap.
+ *
+ * @param entity
+ * the object to be deleted
+ */
+ public void delete(Entity entity);
+
+ /**
+ * Modify an entity in ldap.
+ *
+ * @param entity
+ * the object to be modified
+ *
+ * @return the modified entity
+ */
+ public Entity edit(Entity entity);
+
+ /**
+ * db -> ldap group user filters.
+ *
+ * @param dbGroup the db group
+ * @param ldGroup the ld group
+ * @param filters the filters
+ * @param comparators the comparators
+ * @return the dbGroup with all params taken from ldGrop and the parsed list
+ * of users set after
+ */
+ public Group filterGroupUsersAdd(Group dbGroup, Group ldGroup,
+ Set<com.pentila.evalcomp.synchronization.model.Filter> filters,
+ Set<Identifier> comparators);
+
+ /**
+ * Filter group users delete.
+ *
+ * @param dbGroup
+ * the db group
+ * @param ldGroup
+ * the ld group
+ * @param filters
+ * the filters
+ * @param comparators
+ * the comparators
+ *
+ * @return the group
+ */
+ public Group filterGroupUsersDelete(Group dbGroup, Group ldGroup,
+ Set<com.pentila.evalcomp.synchronization.model.Filter> filters,
+ Set<Identifier> comparators);
+
+ /**
+ * Gets the all group names.
+ *
+ * @return the all group names
+ */
+ public List<String> getAllGroupNames();
+
+ // **************************** Group data
+ // ******************************************************************
+ /**
+ * Gets all groups.
+ *
+ * @return a list of Group objects
+ */
+ public List<Group> getAllGroups();
+
+ /**
+ * Gets the all user names.
+ *
+ * @return the all user names
+ */
+ public List<String> getAllUserNames();
+
+ /**
+ * Gets all users.
+ *
+ * @return a list of User objects
+ */
+ public List<User> getAllUsers();
+
+ /**
+ * Get the Group object that has the given uid.
+ *
+ * @param uid
+ * the given uid
+ *
+ * @return the group matching the uid
+ */
+ public Group getGroup(String uid);
+
+ /**
+ * The method puts together all the filter object with "AND" in between
+ * them, then it returns a Set of the values specified by the column
+ * parameter. For example, if column = "uid" it will give the set of uid's
+ * found with the filter rules.
+ *
+ * @param filters
+ * the set of rules
+ * @param columns
+ * the columns
+ *
+ * @return a set of attributes matching the previous rules
+ */
+ public List<Map<String, String>> getGroupAttributes(
+ Set<com.pentila.evalcomp.synchronization.model.Filter> filters,
+ final String[] columns);
+
+ /**
+ * Gets the groups using a filter.
+ *
+ * @param filter
+ * is a spring Filter object containing the filtering rules
+ *
+ * @return the list of groups
+ */
+ public List<Group> getGroups(Filter filter);
+
+ /**
+ * Gets the groups matching the filters ( the filters are put together with
+ * an "&" in between) and excludes the groups found in bypassList.
+ *
+ * @param filters
+ * the filter rules
+ * @param bypassList
+ * groups that must be excluded if found in this list
+ *
+ * @return a set of groups matching the previous rules
+ */
+ public Set<Group> getGroups(
+ Set<com.pentila.evalcomp.synchronization.model.Filter> filters,
+ List<Group> bypassList);
+
+ /**
+ * Builds a list of groups from ldap. It searches in ldap for the groups
+ * that are in the given set and that respect the comparation rules.
+ *
+ * @param comparators
+ * the list of comparations. Example: c.getLdap() =
+ * value(c.getDb()) . Here, the left part is the attribute name,
+ * and the right part is the content of the other attribute.
+ * @param groups
+ * the groups searched
+ *
+ * @return a set of groups that match the previous rules
+ */
+ public Set<Group> getGroups(Set<Identifier> comparators, Set<Group> groups);
+
+ // **************************** User data
+ // ******************************************************************
+
+ /**
+ * Gets the groups using a String object filter.
+ *
+ * @param filter
+ * the String filter object containing the filtering rules
+ *
+ * @return a list of groups
+ */
+ public List<Group> getGroups(String filter);
+
+ /**
+ * Gets the modify timestamp of an entity. The ldap attribute is
+ * modifyTimestamp.
+ *
+ * @param entity
+ * the entity object which will be searched
+ *
+ * @return the modifyTimestamp read from ldap
+ */
+ public String getModifyTimestamp(Entity entity);
+
+ /**
+ * Gets the user.
+ *
+ * @param uid
+ * the uid
+ *
+ * @return the user
+ */
+ public User getUser(String uid);
+
+ /**
+ * The method puts together all the filter object with "AND" in between
+ * them, then it returns a Set of the values specified by the column
+ * parameter. For example, if column = "uid" it will give the set of uid's
+ * found with the filter rules.
+ *
+ * @param filters
+ * the set of rules
+ * @param columns
+ * the columns
+ *
+ * @return a set of attributes matching the previous rules
+ */
+ public List<Map<String, String>> getUserAttributes(
+ Set<com.pentila.evalcomp.synchronization.model.Filter> filters,
+ final String[] columns);
+
+ /**
+ * Gets the user groups.
+ *
+ * @param uid
+ * the uid
+ *
+ * @return the user groups
+ */
+ public List<Group> getUserGroups(String uid);
+
+ /**
+ * Gets the users using a spring Filter object.
+ *
+ * @param filter
+ * the filter object containing the filtering rules
+ *
+ * @return a list of users
+ */
+ public List<User> getUsers(Filter filter);
+
+ /**
+ * Used to obtain the users from ldap using some filter rules. A filter
+ * object has a string value representing a normal ldap query. The queries
+ * are put together with an "&" in between.
+ *
+ * @param filters
+ * the filters set
+ *
+ * @return the users matching the previous rules
+ */
+ public Set<User> getUsers(
+ Set<com.pentila.evalcomp.synchronization.model.Filter> filters);
+
+ /**
+ * Builds a list of users from ldap. It searches in ldap for the users that
+ * are in the given set and that respect the comparation rules.
+ *
+ * @param comparators
+ * the list of comparations. Example: c.getLdap() =
+ * value(c.getDb()) . Here, the left part is the attribute name,
+ * and the right part is the content of the other attribute.
+ * @param users
+ * the users searched
+ *
+ * @return a set of users that match the previous rules
+ */
+ public Set<User> getUsers(Set<Identifier> comparators, Set<User> users);
+
+ /**
+ * Gets the users using a String filter.
+ *
+ * @param filter
+ * the filter containing the filtering rules
+ *
+ * @return a list of users
+ */
+ public List<User> getUsers(String filter);
+
+ /**
+ * Gets the users from.
+ *
+ * @param group
+ * the group
+ *
+ * @return the users from
+ */
+ public Set<User> getUsersFrom(Group group);
+
+ /**
+ * Gets the users matching the filters ( the filters are put together with
+ * an "&" in between) and matching the userList.
+ *
+ * @param filters
+ * the filter rules
+ * @param userList
+ * the user list
+ *
+ * @return a set of users matching the previous rules
+ */
+ public Set<User> getUsersFrom(
+ Set<com.pentila.evalcomp.synchronization.model.Filter> filters,
+ Set<User> userList);
+
+ /**
+ * Gets the users from group with the uid = uidGroup.
+ *
+ * @param uidGroup
+ * the uid of group
+ *
+ * @return the users list of the group
+ */
+ public Set<User> getUsersFrom(String uidGroup);
+
+ /**
+ * Used to obtain an array of uid's of the users of the group with the uid
+ * groupID.
+ *
+ * @param groupID
+ * the group identifier
+ * @param style
+ * the style
+ *
+ * @return the array of user uid's
+ */
+ public String[] getUsersUidFromGroup(String groupID, String style);
+
+ /**
+ * Gets the users matching the filters ( the filters are put together with
+ * an "&" in between) and excludes the users found in bypassList.
+ *
+ * @param filters
+ * the filter rules
+ * @param bypassList
+ * users that must be excluded if found in this list
+ *
+ * @return a set of users matching the previous rules
+ */
+ public Set<User> getUsersWithout(
+ Set<com.pentila.evalcomp.synchronization.model.Filter> filters,
+ Set<User> bypassList);
+
+ /**
+ * Method used to map to a DirContextAdapter spring object an entity object.
+ * Basically what it does is to define and set attributes for this context
+ * object.
+ *
+ * @param entity
+ * the entity
+ * @param context
+ * the context
+ * @param isNew
+ * the is new
+ */
+ public void mapToContext(Entity entity, DirContextAdapter context,
+ boolean isNew);
+
+ /**
+ * Sets the ldap template. This is set in the spring bean file
+ * configuration. See more about ldap template in spring ldap api.
+ *
+ * @param ldapTemplate
+ * the new ldap template
+ */
+ public void setLdapTemplate(LdapTemplate ldapTemplate);
+
+ /**
+ * Gets the encoded password.
+ *
+ * @param cleartext the cleartext
+ * @return the encoded password
+ */
+ public String getEncodedPassword(String cleartext);
+}