package fr.ccomptes.xemelios.credentials;
-import fr.gouv.finances.dgfip.xemelios.batch.Batch;
-import fr.gouv.finances.dgfip.xemelios.data.impl.pool.PoolManager;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Hashtable;
-import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.TreeSet;
+
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.Attribute;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
+
import org.apache.log4j.Logger;
+import fr.gouv.finances.dgfip.xemelios.batch.Batch;
+import fr.gouv.finances.dgfip.xemelios.data.impl.pool.PoolManager;
+
/**
* This class defines credentials
+ *
* @author cmarchand
*/
public class CredentialSetter extends Batch {
- public static final String INPUT = "input";
- public static final String OUTPUT = "output";
- public static final String INPUT_ENCODING = "input.encoding";
- public static final String INPUT_SEPARATOR = "input.separator";
- public static final String DATE_FORMAT = "dd/MM/yyyy";
- public static final String TARGET = "target";
- public static final String LDAP_CONFIG_FILE = "ldap.config.file";
- public static final String TOUS = "Tous";
- private File inputDir, outputDir;
- private String encoding;
- private String separator;
- private TARGETS target;
- private Properties ldapProperties;
- private static enum TARGETS { SPL, ETAT };
-
- @Override
- protected void doProcess() throws Exception {
- run();
- }
-
- @Override
- public String getResumeTraitement() {
- return null;
- }
-
- @Override
- public String typeTraitementRefCode() {
- return "Gestion Droits";
- }
-
- @Override
- public String getInformations() {
- return null;
- }
-
- @Override
- protected String getBatchVersion() {
- return "1.0";
- }
- /**
- * Acknowledgement status
- */
- public enum ACK_STATUS { OK, KO };
- private static final Logger logger = Logger.getLogger(CredentialSetter.class);
-// private Initializer initer = null;
- private SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
-
- /**
- * Creates a new process
- * @param initializer
- */
- public CredentialSetter(String[] args) {
- super(args);
-// this.initer = initializer;
-// initialize();
- }
-
- @Override
- protected void initialize() {
- inputDir = new File(getProps().getProperty(INPUT));
- outputDir = new File(getProps().getProperty(OUTPUT));
- outputDir.mkdirs();
- separator = getProps().getProperty(INPUT_SEPARATOR);
- encoding = getProps().getProperty(INPUT_ENCODING);
- String t = getProps().getProperty(TARGET);
- this.target = t.equals("SPL") ? TARGETS.SPL : TARGETS.ETAT;
- File fLdapConfig = new File(getProps().getProperty(LDAP_CONFIG_FILE));
- if(fLdapConfig.exists()) {
- try {
- ldapProperties = new Properties();
- FileInputStream fis = new FileInputStream(fLdapConfig);
- ldapProperties.load(fis);
- fis.close();
- } catch(Exception ex) {
- logger.error("while parsing "+fLdapConfig.getAbsolutePath());
- }
- }
- if(ldapProperties==null) throw new RuntimeException("Property "+LDAP_CONFIG_FILE+" not set !");
- }
-
- /**
- * Creates or removes credentials
- * @throws RuntimeException
- */
- public void run() throws RuntimeException {
- FileFilter ff = new FileFilter() {
- @Override
- public boolean accept(File pathname) {
- return !pathname.isDirectory();
- }
- };
- File[] inputFiles = inputDir.listFiles(ff);
- while(inputFiles.length>0) {
- try {
- String fileName = inputFiles[0].getName();
- BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFiles[0]),encoding));
- String line = br.readLine();
- int numLine = 0;
- while(line!=null) {
- parseLine(line, numLine, fileName);
- line = br.readLine();
- numLine++;
- }
-// inputFiles[0].renameTo(new File(new File(inputFiles[0].getParentFile(),"done"),inputFiles[0].getName()));
- if(!inputFiles[0].delete()) {
- logger.error("impossible de supprimer "+inputFiles[0].getAbsolutePath());
- }
- } catch(Exception ex) {
- ex.printStackTrace();
- }
- inputFiles = inputDir.listFiles(ff);
- }
- }
- protected void parseLine(String line, int numLigne, String fileName) {
- String[] rec = line.split(separator, -1);
- if(rec.length!=6) {
- writeAck(fileName, numLigne, ACK_STATUS.KO, rec.length+" fields found, 6 expected", line);
- logger.error("parseLine:", new ParsingException(fileName+" - row "+numLigne+" : incorrect number of fields :"+rec.length+" founds, 6 were expected"));
- return;
- }
- String checkMsg = checkLineFormat(rec);
- if(checkMsg!=null) {
- writeAck(fileName, numLigne, ACK_STATUS.KO, checkMsg, line);
- logger.error("parseLine:",new ParsingException(fileName+" - row "+numLigne+" "+checkMsg));
- return;
- }
- UsersToSet users = rec[2]!=null ? new UsersToSet(rec[2]) : null;
- CollectivitesToSet collectivites = rec[3]!=null ? new CollectivitesToSet(rec[3]) : null;
- DocumentsToSet documents = rec[4]!=null ? new DocumentsToSet(rec[4]) : null;
- doGrants(users, collectivites, documents, rec[5], rec[1]);
- writeAck(fileName, numLigne, ACK_STATUS.OK, null, line);
- }
- /**
- * Checks {@literal line} format.
- * @param the splitted line
- * @return {@literal null} if format is correct and all fields values are acceptable, or error message
- */
- public String checkLineFormat(String[] rec) {
- // is this a date ?
- try {
- sdf.parse(rec[0]);
- } catch(ParseException pEx) {
- return rec[0] +" n'est pas une date valide au format "+DATE_FORMAT;
- }
- if(!"O".equals(rec[1]) && !"F".equals(rec[1]))
- return rec[1]+" n'est pas pas une action valide : attendu [O|F]";
- // no control on users
- // no control on collectivite
- // no control on document-type (we do not have the information here)
- // we check if profil exists
- Connection con = null;
- PreparedStatement ps = null;
- if(rec[5]!=null && rec[5].length()>0) {
- try {
- con = PoolManager.getInstance().getConnection();
- ps = con.prepareStatement("SELECT PRF_CODE FROM AUTH_PROFIL WHERE PRF_CODE=?");
- ps.setString(1, rec[5]);
- ResultSet rs = ps.executeQuery();
- boolean found = rs.next();
- rs.close();
- if(!found) {
- return rec[5]+" is not a known profil";
- }
- } catch(SQLException sqlEx) {
- logger.error("checking if PROFIL exsists:",sqlEx);
- } finally {
- if(ps!=null) {
- try {
- ps.close();
- } catch(SQLException ignoreIt) {}
- }
- if(con!=null) {
- PoolManager.getInstance().releaseConnection(con);
- con = null;
- }
- }
- }
- return null;
- }
- /**
- * Writed acknowledgment file
- * @param originalFileName The input file name
- * @param numLigne The input file line number
- * @param status {@link #ACK_STATUS}
- * @param message
- * @param originalLine
- * @throws RuntimeException if message contains a separator char
- */
- protected void writeAck(String originalFileName, int numLigne, ACK_STATUS status, String message, String originalLine) throws RuntimeException {
- int lastDot = originalFileName.lastIndexOf(".");
- String baseFileName = null;
- String extension = null;
- if(lastDot>=0) {
- baseFileName = originalFileName.substring(0, lastDot);
- extension = originalFileName.substring(lastDot);
- } else {
- baseFileName = originalFileName;
- extension = "";
- }
- String newName = baseFileName+"-"+numLigne+extension;
- File targetFile = new File(outputDir,newName);
- try {
- FileOutputStream fos = new FileOutputStream(targetFile);
- OutputStreamWriter fw = new OutputStreamWriter(fos, encoding);
- fw.write(status==ACK_STATUS.KO?"KO":"OK");
- fw.write(";");
- if(message!=null) fw.write(message);
- fw.write(";");
- fw.write(originalLine);
- fw.flush();
- fw.close();
- } catch(IOException ioEx) {
- logger.error("writeAck:",ioEx);
- }
- }
-
- /**
- * Query the LDAP directory to retrieve users that belongs to this CRC
- * @param crcCode
- * @return
- */
- protected List<Long> getUsersFromCRC(String crcCode) {
- TreeSet<String> ret = new TreeSet<String>();
- Hashtable<String,String> ldapEnv = new Hashtable<String, String>();
- ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
- ldapEnv.put(Context.PROVIDER_URL, "ldap://" + ldapProperties.getProperty("server") + ":" + ldapProperties.getProperty("port"));
- ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
- ldapEnv.put(Context.SECURITY_PRINCIPAL, ldapProperties.getProperty("principal"));
- ldapEnv.put(Context.SECURITY_CREDENTIALS, ldapProperties.getProperty("credentials"));
-
- try {
- String searchFilter = ldapProperties.getProperty("filter");
- // cela peut aussi ĂȘtre Assistants ou Conseillers
- String searchBase = ldapProperties.getProperty("search.base").replaceAll("<GROUP>", crcCode);
- String[] roles = ldapProperties.getProperty("roles").split(",",0);
- for(String role:roles) {
- LdapContext ctx = new InitialLdapContext(ldapEnv,null);
- SearchControls searchCtls = new SearchControls();
- searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
- String localBase = searchBase.replaceAll("<ROLE>", role);
-//logger.debug("searching localBase="+localBase+", searchFilter="+searchFilter);
- NamingEnumeration<SearchResult> answer = ctx.search(localBase, searchFilter, searchCtls);
- String returnedAtts[] = {"members"};
- searchCtls.setReturningAttributes(returnedAtts);
- while(answer.hasMore()) {
-// found++;
- SearchResult sr = (SearchResult) answer.next();
- Attributes attrs = sr.getAttributes();
- if (attrs != null) {
- Attribute at = attrs.get(ldapProperties.getProperty("attribute.for.login"));
- ret.add(at.getAll().next().toString());
- }
- }
- ctx.close();
- }
- } catch(Exception ex) {
- ex.printStackTrace();
- }
- ArrayList<Long> lst = new ArrayList<Long>();
- for(Iterator<String> it=ret.iterator();it.hasNext();) {
- lst.add(getUserIdFromLogin(it.next()));
- }
- return lst;
-
- }
- /**
- * Query various dictionnaries to get the collectivites attached to the specified CRC
- * @param crcCode
- * @return
- */
- protected List<String> getCollectivitesFromCRC(String crcCode) {
- ArrayList<String> ret = new ArrayList<String>();
- switch(target) {
- case ETAT: {
- // in ETAT, we always get the codic, and never the CRC or room num...
- ret.add(crcCode);
- }
- default: {
- Connection con = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- try {
- con = PoolManager.getInstance().getConnection();
- ps = con.prepareStatement("SELECT DISTINCT DEPT_CODE FROM CRC_REFERENTIEL WHERE CRC_MAIL=?");
- ps.setString(1,crcCode);
- rs = ps.executeQuery();
- ArrayList<String> depts = new ArrayList<String>();
- while(rs.next()) {
- depts.add(rs.getString(1));
- }
- rs.close(); rs = null;
- ps.close(); ps = null;
- StringBuilder sb = new StringBuilder();
- for(String dept:depts) sb.append("CODIC LIKE '").append(dept).append("%' OR ");
- for(int i=0;i<4;i++) sb.deleteCharAt(sb.length()-1);
- ps = con.prepareStatement("SELECT DISTINCT IDCOLL FROM REF_COLL_SPL_COLLECTIVITESSPL_COLL_IX WHERE "+sb.toString());
- rs = ps.executeQuery();
- while(rs.next())
- ret.add(rs.getString(1));
- } catch(SQLException sqlEx) {
- logger.error("getCollectivitesFromCRC:",sqlEx);
- } finally {
- if(rs!=null) { try { rs.close(); } catch(SQLException sqlEx) {} }
- if(ps!=null) { try { ps.close(); } catch(SQLException sqlEx) {} }
- if(con!=null) { PoolManager.getInstance().releaseConnection(con); }
- }
- }
- }
- return ret;
- }
- private void doGrants(UsersToSet users, CollectivitesToSet collectivites, DocumentsToSet documents, String profil, String action) {
- if(users.all) {
- Connection con = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- try {
- con = PoolManager.getInstance().getConnection();
- ps = con.prepareStatement("SELECT UTI_ID FROM AUTH_UTILISATEUR");
- rs = ps.executeQuery();
- while(rs.next()) {
- grantsUser(rs.getLong(1), collectivites, documents, profil, action);
- }
- } catch(SQLException sqlEx) {
- logger.error("doGrants:",sqlEx);
- } finally {
- if(rs!=null) try { rs.close(); rs = null; } catch(SQLException sqlEx) {}
- if(ps!=null) try { ps.close(); ps = null; } catch(SQLException sqlEx) {}
- if(con!=null) {
- PoolManager.getInstance().releaseConnection(con);
- con = null;
- }
- }
- } else {
- for(Long user: users.users) {
- grantsUser(user, collectivites, documents, profil, action);
- }
- }
- }
- private void grantsUser(Long user, CollectivitesToSet collectivites, DocumentsToSet documents, String profil, String action) {
- Connection con = null;
- PreparedStatement ps = null;
- PreparedStatement ps2 = null;
- ResultSet rs = null;
- try {
- con = PoolManager.getInstance().getConnection();
- if("F".equals(action)) {
- if(collectivites!=null) {
- if(collectivites.all) {
- ps = con.prepareStatement("DELETE FROM AUTH_HAB_COL WHERE UTI_ID=?");
- ps.setLong(1, user);
- ps.executeUpdate();
- ps.close();
- ps = con.prepareStatement("UPDATE AUTH_UTILISATEUR SET UTI_ALL_COL=0 WHERE UTI_ID=?");
- ps.setLong(1,user);
- ps.executeUpdate();
- ps.close();
- ps = null;
-// logger.debug("removing all collectivites from "+user);
- } else {
- ps = con.prepareStatement("DELETE FROM AUTH_HAB_COL WHERE UTI_ID=? AND COL_CLEF=?");
- ps.setLong(1, user);
- for(String coll:collectivites.collectivites) {
- ps.setString(2,coll);
- ps.executeUpdate();
-// logger.debug("removing coll="+coll+" from "+user);
- }
- ps.close();
- ps = null;
- }
- }
- if(profil!=null) {
- ps = con.prepareStatement("DELETE FROM AUTH_UTI_PRF WHERE UTI_ID=? AND PRF_CODE=?");
- ps.setLong(1, user);
- ps.setString(2, profil);
- ps.executeUpdate();
- ps.close(); ps = null;
-// logger.debug("removing prf="+profil+" from "+user);
- }
- if(documents!=null) {
- if(documents.all) {
- ps = con.prepareStatement("DELETE FROM AUTH_HAB_DOC WHERE UTI_ID=?");
- ps.setLong(1, user);
- ps.executeUpdate();
- ps.close();
- ps = con.prepareStatement("UPDATE AUTH_UTILISATEUR SET UTI_ALL_DOC=0 WHERE UTI_ID=?");
- ps.setLong(1, user);
- ps.executeUpdate();
- ps.close(); ps = null;
-// logger.debug("removing all docs from "+user);
- } else {
- ps = con.prepareStatement("DELETE FROM AUTH_HAB_DOC WHERE UTI_ID=? AND DOC_CODE=?");
- ps.setLong(1, user);
- for(String docId: documents.documents) {
- ps.setString(2,docId);
- ps.executeUpdate();
-// logger.debug("removing doc="+docId+" from "+user);
- }
- ps.close();
- ps = null;
- }
- }
- } else {
- // open rights
- if(collectivites.all) {
- ps = con.prepareStatement("UPDATE AUTH_UTILISATEUR SET UTI_ALL_COL=1 WHERE UTI_ID=?");
- ps.setLong(1,user);
- ps.executeUpdate();
- ps.close();
- ps = null;
-// logger.debug("granting all coll to "+user);
- } else {
- ps2 = con.prepareStatement("SELECT 1 FROM AUTH_HAB_COL WHERE UTI_ID=? AND COL_CLEF=?");
- ps = con.prepareStatement("INSERT INTO AUTH_HAB_COL (UTI_ID, TID_CODE, COL_CLEF) VALUES (?,?,?)");
- ps2.setLong(1, user);
- ps.setLong(1, user);
- ps.setString(2, target==TARGETS.ETAT?"CODIC":"SIRET");
- for(String coll:collectivites.collectivites) {
- ps2.setString(2,coll);
- rs = ps2.executeQuery();
- if(rs.next()) {
- // nothing to do
-// logger.debug("user "+user+" is already granted on coll="+coll);
- } else {
- ps.setString(3,coll);
- ps.executeUpdate();
-// logger.debug("granting "+user+" on coll="+coll);
- }
- rs.close();
- rs = null;
- }
- ps2.close(); ps2 = null;
- ps.close(); ps = null;
- }
- // profils
- ps = con.prepareStatement("SELECT UTI_ALL_FONC FROM AUTH_UTILISATEUR WHERE UTI_ID=?");
- ps.setLong(1,user);
- rs = ps.executeQuery();
- if(rs.next()) {
- if(rs.getInt(1)==0) {
- rs.close(); rs = null;
- ps.close(); ps = null;
- ps = con.prepareStatement("SELECT 1 FROM AUTH_UTI_PRF WHERE UTI_ID=? AND PRF_CODE=?");
- ps.setLong(1,user);
- ps.setString(2,profil);
- rs = ps.executeQuery();
- if(!rs.next()) {
- rs.close(); rs = null;
- ps.close(); ps = null;
- ps = con.prepareStatement("INSERT INTO AUTH_UTI_PRF (UTI_ID, PRF_CODE) VALUES (?,?)");
- ps.setLong(1,user);
- ps.setString(2,profil);
- ps.executeUpdate();
-// logger.debug("granting prf="+profil+" to "+user);
-// ps.close(); ps =null;
- } else {
- rs.close(); rs = null;
- }
- }
- } else {
- // it should never happen, we have ensured that user exists
- rs.close(); rs = null;
- }
- ps.close(); ps = null;
- // documents
- if(documents.all) {
- ps = con.prepareStatement("UPDATE AUTH_UTILISATEUR SET UTI_ALL_DOC=1 WHERE UTI_ID=?");
- ps.setLong(1,user);
- ps.executeUpdate();
- ps.close();
- ps = null;
-// logger.debug("granting all docs to "+user);
- } else {
- ps2 = con.prepareStatement("SELECT 1 FROM AUTH_HAB_DOC WHERE UTI_ID=? AND DOC_CODE=?");
- ps = con.prepareStatement("INSERT INTO AUTH_HAB_DOC (UTI_ID, DOC_CODE) VALUES (?,?)");
- ps2.setLong(1, user);
- ps.setLong(1, user);
- for(String docId:documents.documents) {
- ps2.setString(2,docId);
- rs = ps2.executeQuery();
- if(rs.next()) {
- // nothing to do
-// logger.debug(user+" is already granted to doc="+docId);
- } else {
- ps.setString(2,docId);
- ps.executeUpdate();
-// logger.debug("granting doc="+docId+" to "+user);
- }
- rs.close();
- rs = null;
- }
- ps2.close(); ps2 = null;
- ps.close(); ps = null;
- }
- }
- } catch(SQLException sqlEx) {
- logger.error("grantsUser:",sqlEx);
- } finally {
- if(rs!=null) try { rs.close(); rs = null; } catch(SQLException sqlEx) {}
- if(ps2!=null) try { ps2.close(); ps2 = null; } catch(SQLException sqlEx) {}
- if(ps!=null) try { ps.close(); ps = null; } catch(SQLException sqlEx) {}
- if(con!=null) { PoolManager.getInstance().releaseConnection(con); con = null; }
- }
- }
- private Long getUserIdFromLogin(String login) {
- Connection con = null;
- PreparedStatement ps = null;
- ResultSet rs = null;
- try {
- con = PoolManager.getInstance().getConnection();
- ps = con.prepareStatement("SELECT UTI_ID FROM AUTH_UTILISATEUR WHERE UTI_LOGIN=?");
- ps.setString(1,login);
- rs = ps.executeQuery();
- if(rs.next()) {
- return rs.getLong(1);
- } else {
- // we must create it
- rs.close();
- ps.close();
- ps = con.prepareStatement("INSERT INTO AUTH_UTILISATEUR (UTI_LOGIN, UTI_ACTIF, UTI_ALL_FONC, UTI_ALL_DOC, UTI_ALL_COL) VALUES (?,1,0,0,0)");
- ps.setString(1,login);
- ps.executeUpdate();
- ps.close();
- ps = con.prepareStatement("SELECT MAX(UTI_ID) FROM AUTH_UTILISATEUR WHERE UTI_LOGIN=?");
- ps.setString(1,login);
- rs = ps.executeQuery();
- long userId = 0L;
- if(rs.next())
- userId = rs.getLong(1);
- rs.close();
- ps = con.prepareStatement("INSERT INTO AUTH_UTI_PRF (UTI_ID,PRF_CODE) VALUES (?,'CONNECT')");
- ps.setLong(1,userId);
- ps.executeUpdate();
- ps.close();
- return userId;
- }
- } catch(SQLException sqlEx) {
- logger.error("grantsUser:",sqlEx);
- } finally {
- if(rs!=null) try { rs.close(); rs = null; } catch(SQLException sqlEx) {}
- if(ps!=null) try { ps.close(); ps = null; } catch(SQLException sqlEx) {}
- if(con!=null) { PoolManager.getInstance().releaseConnection(con); con = null; }
- }
- return 0L;
- }
- private class UsersToSet {
- boolean all = false;
- ArrayList<Long> users = null;
- public UsersToSet(String spec) {
- super();
- users = new ArrayList<Long>();
- String[] items = spec.split(",");
- for(String item:items) {
- if(TOUS.equals(item)) {
- all = true;
- users.clear();
- return;
- } else if(item.startsWith("@")) {
- // on supprime le '@'
- users.addAll(getUsersFromCRC(item.substring(1)));
- } else {
- // we need to query LDAP for users in that CRC
- users.add(getUserIdFromLogin(item));
- }
- }
- }
- }
- private class CollectivitesToSet {
- private boolean all;
- private ArrayList<String> collectivites;
- public CollectivitesToSet(String spec) {
- super();
- collectivites = new ArrayList<String>();
- String[] items = spec.split(",");
- for(String item: items) {
- if(TOUS.equals(item)) {
- all = true;
- collectivites.clear();
- return;
- } else if(item.indexOf('@')==0) {
- // it's a CRC
- collectivites.addAll(getCollectivitesFromCRC(item.substring(1)));
- } else {
- collectivites.add(item);
- }
- }
- }
- }
- private class DocumentsToSet {
- private boolean all = false;
- private TreeSet<String> documents = null;
- public DocumentsToSet(String spec) {
- super();
- documents = new TreeSet<String>();
- String[] items = spec.split(",");
- for(String item:items) {
- if(TOUS.equals(item)) {
- all = true;
- documents.clear();
- return;
- } else {
- if("compteGestion".equals(item)) {
- documents.add("compteGestion");
- documents.add("cg-colloc");
- } else if("documentPaye".equals(item)) {
- documents.add("documentPaye");
- documents.add("cfg-paye");
- } else if("compteGestionEtat".equals(item)) {
- documents.add("compteGestionEtat");
- documents.add("cg-etat");
- } else if("DocumentRapport".equals(item)) {
- documents.add("DocumentRapport");
- documents.add("rapport");
- } else if("PES_Aller".equals(item)) {
- documents.add("PES_Aller");
- documents.add("pes-aller");
- } else {
- documents.add(item);
- }
- }
- }
- }
- }
+ public static final String INPUT = "input";
+ public static final String OUTPUT = "output";
+ public static final String INPUT_ENCODING = "input.encoding";
+ public static final String INPUT_SEPARATOR = "input.separator";
+ public static final String DATE_FORMAT = "dd/MM/yyyy";
+ public static final String TARGET = "target";
+ public static final String LDAP_CONFIG_FILE = "ldap.config.file";
+ public static final String TOUS = "Tous";
+ private File inputDir, outputDir;
+ private String encoding;
+ private String separator;
+ private TARGETS target;
+ private Properties ldapProperties;
+
+ private static enum TARGETS {
+ SPL, ETAT
+ };
+
+ @Override
+ protected void doProcess() throws Exception {
+ this.run();
+ }
+
+ @Override
+ public String getResumeTraitement() {
+ return null;
+ }
+
+ @Override
+ public String typeTraitementRefCode() {
+ return "Gestion Droits";
+ }
+
+ @Override
+ public String getInformations() {
+ return null;
+ }
+
+ @Override
+ protected String getBatchVersion() {
+ return "1.0";
+ }
+
+ /**
+ * Acknowledgement status
+ */
+ public enum ACK_STATUS {
+ OK, KO
+ };
+
+ private static final Logger logger = Logger.getLogger(CredentialSetter.class);
+ // private Initializer initer = null;
+ private final SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
+
+ /**
+ * Creates a new process
+ *
+ * @param initializer
+ */
+ public CredentialSetter(final String[] args) {
+ super(args);
+ // this.initer = initializer;
+ // initialize();
+ }
+
+ @Override
+ protected void initialize() {
+ this.inputDir = new File(this.getProps().getProperty(INPUT));
+ this.outputDir = new File(this.getProps().getProperty(OUTPUT));
+ this.outputDir.mkdirs();
+ this.separator = this.getProps().getProperty(INPUT_SEPARATOR);
+ this.encoding = this.getProps().getProperty(INPUT_ENCODING);
+ final String t = this.getProps().getProperty(TARGET);
+ this.target = t.equals("SPL") ? TARGETS.SPL : TARGETS.ETAT;
+ final File fLdapConfig = new File(this.getProps().getProperty(LDAP_CONFIG_FILE));
+ if (fLdapConfig.exists()) {
+ try {
+ this.ldapProperties = new Properties();
+ final FileInputStream fis = new FileInputStream(fLdapConfig);
+ this.ldapProperties.load(fis);
+ fis.close();
+ } catch (final Exception ex) {
+ logger.error("while parsing " + fLdapConfig.getAbsolutePath());
+ }
+ }
+ if (this.ldapProperties == null) {
+ throw new RuntimeException("Property " + LDAP_CONFIG_FILE + " not set !");
+ }
+ }
+
+ /**
+ * Creates or removes credentials
+ *
+ * @throws RuntimeException
+ */
+ public void run() throws RuntimeException {
+ final FileFilter ff = new FileFilter() {
+ @Override
+ public boolean accept(final File pathname) {
+ return !pathname.isDirectory();
+ }
+ };
+ File[] inputFiles = this.inputDir.listFiles(ff);
+ while (inputFiles.length > 0) {
+ try {
+ final String fileName = inputFiles[0].getName();
+ final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFiles[0]), this.encoding));
+ String line = br.readLine();
+ int numLine = 0;
+ while (line != null) {
+ this.parseLine(line, numLine, fileName);
+ line = br.readLine();
+ numLine++;
+ }
+ // inputFiles[0].renameTo(new File(new File(inputFiles[0].getParentFile(),"done"),inputFiles[0].getName()));
+ if (!inputFiles[0].delete()) {
+ logger.error("impossible de supprimer " + inputFiles[0].getAbsolutePath());
+ }
+ } catch (final Exception ex) {
+ ex.printStackTrace();
+ }
+ inputFiles = this.inputDir.listFiles(ff);
+ }
+ }
+
+ protected void parseLine(final String line, final int numLigne, final String fileName) {
+ final String[] rec = line.split(this.separator, -1);
+ if (rec.length != 6) {
+ this.writeAck(fileName, numLigne, ACK_STATUS.KO, rec.length + " fields found, 6 expected", line);
+ logger.error("parseLine:", new ParsingException(fileName + " - row " + numLigne + " : incorrect number of fields :" + rec.length + " founds, 6 were expected"));
+ return;
+ }
+ final String checkMsg = this.checkLineFormat(rec);
+ if (checkMsg != null) {
+ this.writeAck(fileName, numLigne, ACK_STATUS.KO, checkMsg, line);
+ logger.error("parseLine:", new ParsingException(fileName + " - row " + numLigne + " " + checkMsg));
+ return;
+ }
+ final UsersToSet users = rec[2] != null ? new UsersToSet(rec[2]) : null;
+ final CollectivitesToSet collectivites = rec[3] != null ? new CollectivitesToSet(rec[3]) : null;
+ final DocumentsToSet documents = rec[4] != null ? new DocumentsToSet(rec[4]) : null;
+ this.doGrants(users, collectivites, documents, rec[5], rec[1]);
+ this.writeAck(fileName, numLigne, ACK_STATUS.OK, null, line);
+ }
+
+ /**
+ * Checks {@literal line} format.
+ *
+ * @param the
+ * splitted line
+ * @return {@literal null} if format is correct and all fields values are acceptable, or error message
+ */
+ public String checkLineFormat(final String[] rec) {
+ // is this a date ?
+ try {
+ this.sdf.parse(rec[0]);
+ } catch (final ParseException pEx) {
+ return rec[0] + " n'est pas une date valide au format " + DATE_FORMAT;
+ }
+ if (!"O".equals(rec[1]) && !"F".equals(rec[1])) {
+ return rec[1] + " n'est pas pas une action valide : attendu [O|F]";
+ }
+ // no control on users
+ // no control on collectivite
+ // no control on document-type (we do not have the information here)
+ // we check if profil exists
+ Connection con = null;
+ PreparedStatement ps = null;
+ if (rec[5] != null && rec[5].length() > 0) {
+ try {
+ con = PoolManager.getInstance().getConnection();
+ ps = con.prepareStatement("SELECT PRF_CODE FROM AUTH_PROFIL WHERE PRF_CODE=?");
+ ps.setString(1, rec[5]);
+ final ResultSet rs = ps.executeQuery();
+ final boolean found = rs.next();
+ rs.close();
+ if (!found) {
+ return rec[5] + " is not a known profil";
+ }
+ } catch (final SQLException sqlEx) {
+ logger.error("checking if PROFIL exsists:", sqlEx);
+ } finally {
+ if (ps != null) {
+ try {
+ ps.close();
+ } catch (final SQLException ignoreIt) {
+ }
+ }
+ if (con != null) {
+ PoolManager.getInstance().releaseConnection(con);
+ con = null;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Writed acknowledgment file
+ *
+ * @param originalFileName
+ * The input file name
+ * @param numLigne
+ * The input file line number
+ * @param status
+ * {@link #ACK_STATUS}
+ * @param message
+ * @param originalLine
+ * @throws RuntimeException
+ * if message contains a separator char
+ */
+ protected void writeAck(final String originalFileName, final int numLigne, final ACK_STATUS status, final String message, final String originalLine) throws RuntimeException {
+ final int lastDot = originalFileName.lastIndexOf(".");
+ String baseFileName = null;
+ String extension = null;
+ if (lastDot >= 0) {
+ baseFileName = originalFileName.substring(0, lastDot);
+ extension = originalFileName.substring(lastDot);
+ } else {
+ baseFileName = originalFileName;
+ extension = "";
+ }
+ final String newName = baseFileName + "-" + numLigne + extension;
+ final File targetFile = new File(this.outputDir, newName);
+ try {
+ final FileOutputStream fos = new FileOutputStream(targetFile);
+ final OutputStreamWriter fw = new OutputStreamWriter(fos, this.encoding);
+ fw.write(status == ACK_STATUS.KO ? "KO" : "OK");
+ fw.write(";");
+ if (message != null) {
+ fw.write(message);
+ }
+ fw.write(";");
+ fw.write(originalLine);
+ fw.flush();
+ fw.close();
+ } catch (final IOException ioEx) {
+ logger.error("writeAck:", ioEx);
+ }
+ }
+
+ /**
+ * Query the LDAP directory to retrieve users that belongs to this CRC
+ *
+ * @param crcCode
+ * @return
+ */
+ protected List<Long> getUsersFromCRC(final String crcCode) {
+ final TreeSet<String> ret = new TreeSet<String>();
+ final Hashtable<String, String> ldapEnv = new Hashtable<String, String>();
+ ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
+ ldapEnv.put(Context.PROVIDER_URL, "ldap://" + this.ldapProperties.getProperty("server") + ":" + this.ldapProperties.getProperty("port"));
+ ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
+ ldapEnv.put(Context.SECURITY_PRINCIPAL, this.ldapProperties.getProperty("principal"));
+ ldapEnv.put(Context.SECURITY_CREDENTIALS, this.ldapProperties.getProperty("credentials"));
+
+ try {
+ final String searchFilter = this.ldapProperties.getProperty("filter");
+ // cela peut aussi ĂȘtre Assistants ou Conseillers
+ final String searchBase = this.ldapProperties.getProperty("search.base").replaceAll("<GROUP>", crcCode);
+ final String[] roles = this.ldapProperties.getProperty("roles").split(",", 0);
+ for (final String role : roles) {
+ final LdapContext ctx = new InitialLdapContext(ldapEnv, null);
+ final SearchControls searchCtls = new SearchControls();
+ searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
+ final String localBase = searchBase.replaceAll("<ROLE>", role);
+ // logger.debug("searching localBase="+localBase+", searchFilter="+searchFilter);
+ final NamingEnumeration<SearchResult> answer = ctx.search(localBase, searchFilter, searchCtls);
+ final String returnedAtts[] = { "members" };
+ searchCtls.setReturningAttributes(returnedAtts);
+ while (answer.hasMore()) {
+ // found++;
+ final SearchResult sr = answer.next();
+ final Attributes attrs = sr.getAttributes();
+ if (attrs != null) {
+ final Attribute at = attrs.get(this.ldapProperties.getProperty("attribute.for.login"));
+ ret.add(at.getAll().next().toString());
+ }
+ }
+ ctx.close();
+ }
+ } catch (final Exception ex) {
+ ex.printStackTrace();
+ }
+ final ArrayList<Long> lst = new ArrayList<Long>();
+ for (final String string : ret) {
+ lst.add(this.getUserIdFromLogin(string));
+ }
+ return lst;
+
+ }
+
+ /**
+ * Query various dictionnaries to get the collectivites attached to the specified CRC
+ *
+ * @param crcCode
+ * @return
+ */
+ protected List<String> getCollectivitesFromCRC(final String crcCode) {
+ final ArrayList<String> ret = new ArrayList<String>();
+ switch (this.target) {
+ case ETAT: {
+ // in ETAT, we always get the codic, and never the CRC or room num...
+ ret.add(crcCode);
+ }
+ default: {
+ Connection con = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ try {
+ con = PoolManager.getInstance().getConnection();
+ ps = con.prepareStatement("SELECT DISTINCT DEPT_CODE FROM CRC_REFERENTIEL WHERE CRC_MAIL=?");
+ ps.setString(1, crcCode);
+ rs = ps.executeQuery();
+ final ArrayList<String> depts = new ArrayList<String>();
+ while (rs.next()) {
+ depts.add(rs.getString(1));
+ }
+ rs.close();
+ rs = null;
+ ps.close();
+ ps = null;
+ final StringBuilder sb = new StringBuilder();
+ for (final String dept : depts) {
+ sb.append("CODIC LIKE '").append(dept).append("%' OR ");
+ }
+ for (int i = 0; i < 4; i++) {
+ sb.deleteCharAt(sb.length() - 1);
+ }
+ ps = con.prepareStatement("SELECT DISTINCT IDCOLL FROM REF_COLL_SPL_COLLECTIVITESSPL_COLL_IX WHERE " + sb.toString());
+ rs = ps.executeQuery();
+ while (rs.next()) {
+ ret.add(rs.getString(1));
+ }
+ } catch (final SQLException sqlEx) {
+ logger.error("getCollectivitesFromCRC:", sqlEx);
+ } finally {
+ if (rs != null) {
+ try {
+ rs.close();
+ } catch (final SQLException sqlEx) {
+ }
+ }
+ if (ps != null) {
+ try {
+ ps.close();
+ } catch (final SQLException sqlEx) {
+ }
+ }
+ if (con != null) {
+ PoolManager.getInstance().releaseConnection(con);
+ }
+ }
+ }
+ }
+ return ret;
+ }
+
+ private void doGrants(final UsersToSet users, final CollectivitesToSet collectivites, final DocumentsToSet documents, final String profil, final String action) {
+ if (users.all) {
+ Connection con = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ try {
+ con = PoolManager.getInstance().getConnection();
+ ps = con.prepareStatement("SELECT UTI_ID FROM AUTH_UTILISATEUR");
+ rs = ps.executeQuery();
+ while (rs.next()) {
+ this.grantsUser(rs.getLong(1), collectivites, documents, profil, action);
+ }
+ } catch (final SQLException sqlEx) {
+ logger.error("doGrants:", sqlEx);
+ } finally {
+ if (rs != null) {
+ try {
+ rs.close();
+ rs = null;
+ } catch (final SQLException sqlEx) {
+ }
+ }
+ if (ps != null) {
+ try {
+ ps.close();
+ ps = null;
+ } catch (final SQLException sqlEx) {
+ }
+ }
+ if (con != null) {
+ PoolManager.getInstance().releaseConnection(con);
+ con = null;
+ }
+ }
+ } else {
+ for (final Long user : users.users) {
+ this.grantsUser(user, collectivites, documents, profil, action);
+ }
+ }
+ }
+
+ private void grantsUser(final Long user, final CollectivitesToSet collectivites, final DocumentsToSet documents, final String profil, final String action) {
+ Connection con = null;
+ PreparedStatement ps = null;
+ PreparedStatement ps2 = null;
+ ResultSet rs = null;
+ try {
+ con = PoolManager.getInstance().getConnection();
+ if ("F".equals(action)) {
+ if (collectivites != null) {
+ if (collectivites.all) {
+ ps = con.prepareStatement("DELETE FROM AUTH_HAB_COL WHERE UTI_ID=?");
+ ps.setLong(1, user);
+ ps.executeUpdate();
+ ps.close();
+ ps = con.prepareStatement("UPDATE AUTH_UTILISATEUR SET UTI_ALL_COL=0 WHERE UTI_ID=?");
+ ps.setLong(1, user);
+ ps.executeUpdate();
+ ps.close();
+ ps = null;
+ // logger.debug("removing all collectivites from "+user);
+ } else {
+ ps = con.prepareStatement("DELETE FROM AUTH_HAB_COL WHERE UTI_ID=? AND COL_CLEF=?");
+ ps.setLong(1, user);
+ for (final String coll : collectivites.collectivites) {
+ ps.setString(2, coll);
+ ps.executeUpdate();
+ // logger.debug("removing coll="+coll+" from "+user);
+ }
+ ps.close();
+ ps = null;
+ }
+ }
+ if (profil != null) {
+ ps = con.prepareStatement("DELETE FROM AUTH_UTI_PRF WHERE UTI_ID=? AND PRF_CODE=?");
+ ps.setLong(1, user);
+ ps.setString(2, profil);
+ ps.executeUpdate();
+ ps.close();
+ ps = null;
+ // logger.debug("removing prf="+profil+" from "+user);
+ }
+ if (documents != null) {
+ if (documents.all) {
+ ps = con.prepareStatement("DELETE FROM AUTH_HAB_DOC WHERE UTI_ID=?");
+ ps.setLong(1, user);
+ ps.executeUpdate();
+ ps.close();
+ ps = con.prepareStatement("UPDATE AUTH_UTILISATEUR SET UTI_ALL_DOC=0 WHERE UTI_ID=?");
+ ps.setLong(1, user);
+ ps.executeUpdate();
+ ps.close();
+ ps = null;
+ // logger.debug("removing all docs from "+user);
+ } else {
+ ps = con.prepareStatement("DELETE FROM AUTH_HAB_DOC WHERE UTI_ID=? AND DOC_CODE=?");
+ ps.setLong(1, user);
+ for (final String docId : documents.documents) {
+ ps.setString(2, docId);
+ ps.executeUpdate();
+ // logger.debug("removing doc="+docId+" from "+user);
+ }
+ ps.close();
+ ps = null;
+ }
+ }
+ } else {
+ // open rights
+ if (collectivites.all) {
+ ps = con.prepareStatement("UPDATE AUTH_UTILISATEUR SET UTI_ALL_COL=1 WHERE UTI_ID=?");
+ ps.setLong(1, user);
+ ps.executeUpdate();
+ ps.close();
+ ps = null;
+ // logger.debug("granting all coll to "+user);
+ } else {
+ ps2 = con.prepareStatement("SELECT 1 FROM AUTH_HAB_COL WHERE UTI_ID=? AND COL_CLEF=?");
+ ps = con.prepareStatement("INSERT INTO AUTH_HAB_COL (UTI_ID, TID_CODE, COL_CLEF) VALUES (?,?,?)");
+ ps2.setLong(1, user);
+ ps.setLong(1, user);
+ ps.setString(2, this.target == TARGETS.ETAT ? "CODIC" : "SIRET");
+ for (final String coll : collectivites.collectivites) {
+ ps2.setString(2, coll);
+ rs = ps2.executeQuery();
+ if (rs.next()) {
+ // nothing to do
+ // logger.debug("user "+user+" is already granted on coll="+coll);
+ } else {
+ ps.setString(3, coll);
+ ps.executeUpdate();
+ // logger.debug("granting "+user+" on coll="+coll);
+ }
+ rs.close();
+ rs = null;
+ }
+ ps2.close();
+ ps2 = null;
+ ps.close();
+ ps = null;
+ }
+ // profils
+ ps = con.prepareStatement("SELECT UTI_ALL_FONC FROM AUTH_UTILISATEUR WHERE UTI_ID=?");
+ ps.setLong(1, user);
+ rs = ps.executeQuery();
+ if (rs.next()) {
+ if (rs.getInt(1) == 0) {
+ rs.close();
+ rs = null;
+ ps.close();
+ ps = null;
+ ps = con.prepareStatement("SELECT 1 FROM AUTH_UTI_PRF WHERE UTI_ID=? AND PRF_CODE=?");
+ ps.setLong(1, user);
+ ps.setString(2, profil);
+ rs = ps.executeQuery();
+ if (!rs.next()) {
+ rs.close();
+ rs = null;
+ ps.close();
+ ps = null;
+ ps = con.prepareStatement("INSERT INTO AUTH_UTI_PRF (UTI_ID, PRF_CODE) VALUES (?,?)");
+ ps.setLong(1, user);
+ ps.setString(2, profil);
+ ps.executeUpdate();
+ // logger.debug("granting prf="+profil+" to "+user);
+ // ps.close(); ps =null;
+ } else {
+ rs.close();
+ rs = null;
+ }
+ }
+ } else {
+ // it should never happen, we have ensured that user exists
+ rs.close();
+ rs = null;
+ }
+ ps.close();
+ ps = null;
+ // documents
+ if (documents.all) {
+ ps = con.prepareStatement("UPDATE AUTH_UTILISATEUR SET UTI_ALL_DOC=1 WHERE UTI_ID=?");
+ ps.setLong(1, user);
+ ps.executeUpdate();
+ ps.close();
+ ps = null;
+ // logger.debug("granting all docs to "+user);
+ } else {
+ ps2 = con.prepareStatement("SELECT 1 FROM AUTH_HAB_DOC WHERE UTI_ID=? AND DOC_CODE=?");
+ ps = con.prepareStatement("INSERT INTO AUTH_HAB_DOC (UTI_ID, DOC_CODE) VALUES (?,?)");
+ ps2.setLong(1, user);
+ ps.setLong(1, user);
+ for (final String docId : documents.documents) {
+ ps2.setString(2, docId);
+ rs = ps2.executeQuery();
+ if (rs.next()) {
+ // nothing to do
+ // logger.debug(user+" is already granted to doc="+docId);
+ } else {
+ ps.setString(2, docId);
+ ps.executeUpdate();
+ // logger.debug("granting doc="+docId+" to "+user);
+ }
+ rs.close();
+ rs = null;
+ }
+ ps2.close();
+ ps2 = null;
+ ps.close();
+ ps = null;
+ }
+ }
+ } catch (final SQLException sqlEx) {
+ logger.error("grantsUser:", sqlEx);
+ } finally {
+ if (rs != null) {
+ try {
+ rs.close();
+ rs = null;
+ } catch (final SQLException sqlEx) {
+ }
+ }
+ if (ps2 != null) {
+ try {
+ ps2.close();
+ ps2 = null;
+ } catch (final SQLException sqlEx) {
+ }
+ }
+ if (ps != null) {
+ try {
+ ps.close();
+ ps = null;
+ } catch (final SQLException sqlEx) {
+ }
+ }
+ if (con != null) {
+ PoolManager.getInstance().releaseConnection(con);
+ con = null;
+ }
+ }
+ }
+
+ private Long getUserIdFromLogin(final String login) {
+ Connection con = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ try {
+ con = PoolManager.getInstance().getConnection();
+ ps = con.prepareStatement("SELECT UTI_ID FROM AUTH_UTILISATEUR WHERE UTI_LOGIN=?");
+ ps.setString(1, login);
+ rs = ps.executeQuery();
+ if (rs.next()) {
+ return rs.getLong(1);
+ } else {
+ // we must create it
+ rs.close();
+ ps.close();
+ ps = con.prepareStatement("INSERT INTO AUTH_UTILISATEUR (UTI_LOGIN, UTI_ACTIF, UTI_ALL_FONC, UTI_ALL_DOC, UTI_ALL_COL) VALUES (?,1,0,0,0)");
+ ps.setString(1, login);
+ ps.executeUpdate();
+ ps.close();
+ ps = con.prepareStatement("SELECT MAX(UTI_ID) FROM AUTH_UTILISATEUR WHERE UTI_LOGIN=?");
+ ps.setString(1, login);
+ rs = ps.executeQuery();
+ long userId = 0L;
+ if (rs.next()) {
+ userId = rs.getLong(1);
+ }
+ rs.close();
+ ps = con.prepareStatement("INSERT INTO AUTH_UTI_PRF (UTI_ID,PRF_CODE) VALUES (?,'CONNECT')");
+ ps.setLong(1, userId);
+ ps.executeUpdate();
+ ps.close();
+ return userId;
+ }
+ } catch (final SQLException sqlEx) {
+ logger.error("grantsUser:", sqlEx);
+ } finally {
+ if (rs != null) {
+ try {
+ rs.close();
+ rs = null;
+ } catch (final SQLException sqlEx) {
+ }
+ }
+ if (ps != null) {
+ try {
+ ps.close();
+ ps = null;
+ } catch (final SQLException sqlEx) {
+ }
+ }
+ if (con != null) {
+ PoolManager.getInstance().releaseConnection(con);
+ con = null;
+ }
+ }
+ return 0L;
+ }
+
+ private class UsersToSet {
+ boolean all = false;
+ ArrayList<Long> users = null;
+
+ public UsersToSet(final String spec) {
+ super();
+ this.users = new ArrayList<Long>();
+ final String[] items = spec.split(",");
+ for (final String item : items) {
+ if (TOUS.equals(item)) {
+ this.all = true;
+ this.users.clear();
+ return;
+ } else if (item.startsWith("@")) {
+ // on supprime le '@'
+ this.users.addAll(CredentialSetter.this.getUsersFromCRC(item.substring(1)));
+ } else {
+ // we need to query LDAP for users in that CRC
+ this.users.add(CredentialSetter.this.getUserIdFromLogin(item));
+ }
+ }
+ }
+ }
+
+ private class CollectivitesToSet {
+ private boolean all;
+ private ArrayList<String> collectivites;
+
+ public CollectivitesToSet(final String spec) {
+ super();
+ this.collectivites = new ArrayList<String>();
+ final String[] items = spec.split(",");
+ for (final String item : items) {
+ if (TOUS.equals(item)) {
+ this.all = true;
+ this.collectivites.clear();
+ return;
+ } else if (item.indexOf('@') == 0) {
+ // it's a CRC
+ this.collectivites.addAll(CredentialSetter.this.getCollectivitesFromCRC(item.substring(1)));
+ } else {
+ this.collectivites.add(item);
+ }
+ }
+ }
+ }
+
+ private class DocumentsToSet {
+ private boolean all = false;
+ private TreeSet<String> documents = null;
+
+ public DocumentsToSet(final String spec) {
+ super();
+ this.documents = new TreeSet<String>();
+ final String[] items = spec.split(",");
+ for (final String item : items) {
+ if (TOUS.equals(item)) {
+ this.all = true;
+ this.documents.clear();
+ return;
+ } else {
+ if ("compteGestion".equals(item)) {
+ this.documents.add("compteGestion");
+ this.documents.add("cg-colloc");
+ } else if ("documentPaye".equals(item)) {
+ this.documents.add("documentPaye");
+ this.documents.add("cfg-paye");
+ } else if ("compteGestionEtat".equals(item)) {
+ this.documents.add("compteGestionEtat");
+ this.documents.add("cg-etat");
+ } else if ("DocumentRapport".equals(item)) {
+ this.documents.add("DocumentRapport");
+ this.documents.add("rapport");
+ } else if ("PES_Aller".equals(item)) {
+ this.documents.add("PES_Aller");
+ this.documents.add("pes-aller");
+ } else {
+ this.documents.add(item);
+ }
+ }
+ }
+ }
+ }
}