MAJ Simplicité : Outdated deprecated method

Tags: #<Tag:0x00007f2f341661f0>

Bonjour

Suite à une mise à jour nous avons cette erreur qui apparaît à chaque connexion :

2020-09-02 12:27:45,669 ERROR [com.simplicite.util.ScriptedGrantHooks] SIMPLICITE|http://frparvm36114048:10100||ERROR|system|com.simplicite.util.ScriptedGrantHooks|parseAuth with String argument||Evénement: Outdated deprecated method, please use parseAuth with SessionInfo argument, call stack: com.simplicite.util.AppLog.deprecation[629]
com.simplicite.util.ScriptedGrantHooks.parseAuth[368]
com.simplicite.webapp.servlets.OAuth2Servlet.callback[329]
com.simplicite.webapp.servlets.OAuth2Servlet.doGet[866]
com.simplicite.webapp.filters.RewriteFilter.doFilter[77]
com.simplicite.webapp.filters.AbstractFilter.doFilter[37]
com.simplicite.tomcat.valves.APISessionValve.invoke[-1]

Je ne rencontrais pas ce problème avec la version suivante :

[Platform]
Status=OK
Version=4.0.P24
BuiltOn=2020-04-07 12:34 (revision 330741432510089d558279afae9a5705767882a3)
Encoding=UTF-8
EndpointIP=10.24.218.148
EndpointURL=https://frparvm36114048:200443
TimeZone=Europe/Paris
SystemDate=2020-09-02 12:34:05

[Application]
ApplicationVersion=SIORG_0.0.9.7
ContextPath=
ContextURL=http://frparvm36114048:20000
ActiveSessions=2
TotalUsers=92
EnabledUsers=80
LastLoginDate=

[Server]
ServerInfo=Apache Tomcat/9.0.35
ServerType=WEB
User=lille

[OS]
Name=Linux
Architecture=amd64
Version=3.10.0-957.27.2.el7.x86_64
SystemEncoding=UTF-8

[Disk]
DiskFree=3308
DiskUsable=1482
DiskTotal=42052

[JavaVM]
Version=1.8.0_222
Vendor=Oracle Corporation
VMName=OpenJDK 64-Bit Server VM
VMVersion=25.222-b10
ScriptEngine=rhino
ScriptEngineVersion=Rhino 1.7.11 2019 05 30
HeapFree=204416
HeapSize=584704
HeapMaxSize=1864192
TotalFreeSize=1483904

[Cache]
GrantCache=72
GrantCacheMax=0
GrantCacheRatio=0
ObjectCache=16
ObjectCacheMax=10000
ObjectCacheRatio=0
ProcessCache=0
ProcessCacheMax=10000
ProcessCacheRatio=0

[Database]
Vendor=3
ProductName=PostgreSQL
ProductVersion=11.3
DriverName=PostgreSQL JDBC Driver
DriverVersion=42.2.12
DBDate=2020-09-02 12:34:05
DBDateOffset=0
DBPatchLevel=P24;330741432510089d558279afae9a5705767882a3
UsingBLOBs=true

[Healthcheck]
Date=2020-09-02 12:34:05
ElapsedTime=785

Voici la version actuelle :

[Platform]
Status=OK
Version=4.0.P24
BuiltOn=2020-08-21 14:18 (revision 04e9f93a252dda1763a85f8c9bd81522b7dea211)
Encoding=UTF-8
EndpointIP=10.24.218.148
EndpointURL=http://frparvm36114048:8080
TimeZone=Europe/Paris
SystemDate=2020-09-02 12:35:36

[Application]
ApplicationVersion=SIORG_0.1.0.0
ContextPath=
ContextURL=http://frparvm36114048:8080
ActiveSessions=2
TotalUsers=92
EnabledUsers=80
LastLoginDate=

[Server]
ServerInfo=Apache Tomcat/9.0.22
ServerType=WEB
User=simplicite

[OS]
Name=Linux
Architecture=amd64
Version=3.10.0-957.27.2.el7.x86_64
SystemEncoding=UTF-8

[Disk]
DiskFree=3308
DiskUsable=1482
DiskTotal=42052

[JavaVM]
Version=1.8.0_222
Vendor=Oracle Corporation
VMName=OpenJDK 64-Bit Server VM
VMVersion=25.222-b10
ScriptEngine=rhino
ScriptEngineVersion=Rhino 1.7.11 2019 05 30
HeapFree=321610
HeapSize=840192
HeapMaxSize=1864192
TotalFreeSize=1345610

[Cache]
GrantCache=32
GrantCacheMax=0
GrantCacheRatio=0
ObjectCache=388
ObjectCacheMax=10000
ObjectCacheRatio=3
ProcessCache=0
ProcessCacheMax=10000
ProcessCacheRatio=0

[Database]
Vendor=3
ProductName=PostgreSQL
ProductVersion=11.3
DriverName=PostgreSQL JDBC Driver
DriverVersion=42.2.6
DBDate=2020-09-02 12:35:36
DBDateOffset=0
DBPatchLevel=P24;74d87c9141d2710476cdbdcd6d490d44
UsingBLOBs=true

[Healthcheck]
Date=2020-09-02 12:35:36
ElapsedTime=88

Le parseAuth a changé de signature, l’ancien est toujours appelé pour compatibilité mais avec cette erreur de déprecation justement pour inciter au refactoring

Avez vous un GrantHooks implémenté ? Si oui, le parseAuth est il implémenté ?

On a bien un GrantHooks mais le parseAuth n’est pas implémenté
Le code du GrantHooks :

package com.simplicite.commons.SIOrgCommun;

import java.util.List;
import java.util.ArrayList;
import com.simplicite.util.Grant;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.simplicite.util.AppLog;
import com.simplicite.util.ObjectDB;

//SAML
import com.simplicite.util.SessionInfo;
import com.simplicite.util.tools.BusinessObjectTool;
import com.simplicite.util.ObjectField;
import com.simplicite.util.Tool;
import com.simplicite.util.Globals;
import com.simplicite.util.exceptions.AuthenticationException;
import com.simplicite.objects.System.View;


import java.util.Arrays;

/**
 * Grant Hooks
 */
public class GrantHooks extends com.simplicite.util.GrantHooksInterface {
	
	/**
	 * Regles de validation du mot de passe
	 */
	public static List<String> validatePassword(Grant g, String pwd) {
		List<String> errs = new ArrayList<>();
		
		// TODO: regles à implémenter
		//if (pwd==null || pwd.length()<9)
	   // 	errs.add("ERR_PWD_SIZE");

      String pattern = "(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).{9,}";
      if (!pwd.matches(pattern))
    	errs.add("SIO_ERR_PWD");

		return errs;
	}
	
	
	// Récupération des données du perimetre en variable system pour la session utilsateur
	public static void postLoadGrant(Grant g) {
	
	AppLog.info(GrantHooks.class, "responsa", "list : " + g.getRespList(), g);

	//Suppresion des userfilters de l'utilisateur à l'ouverture de session (sauf rdd)
	if (!g.getLogin().equals("rdd"))
		g.update("update m_user_filters SET uft_start_dt=null,uft_end_dt=null,uft_espace_fk=null where uft_user_id=" + g.getUserId());

		
		
		List<String[]> perimetre;
		List<String[]> espace;
		List<String[]> sse;
		List<String[]> groupe_origine;
		List<String[]> origine;
		List<String[]> cfdf;
		List<String[]> df;
		List<String[]> cf;

		String listPerimetre = "";
		String listEspace = "";
		String listEspace_lecture_seule = "";
		String listEspace_ecriture = "";
		String listSSE = "";
		String listSSERW = "";
		String listGroupeOrigine = "";
		String listOrigine = "";
		String listCFDF = "";
		String listDF = "";
		String listCF = "";
		String listOrigineSql="";
		String listGroupeOrigineSql="";
		String listSSECote="";
		String listDFSql="";		
		String listSSESql="";
		
		
		String sse_protege = "0";
		g.setParameter("PERIMETRE_ID", 0);
		g.setParameter("PERIMETRE_ESPACE", "vide");
		g.setParameter("PERIMETRE_ESPACE_RW","");
		g.setParameter("PERIMETRE_ESPACE_W","");
		g.setParameter("PERIMETRE_GROUPE_ORIGINE", "vide");
		g.setParameter("PERIMETRE_GROUPE_ORIGINE_CONTAINS", "vide");
		g.setParameter("PERIMETRE_GROUPE_ORIGINE_SQL", "vide");		
		g.setParameter("PERIMETRE_ORIGINE", "vide");
		g.setParameter("PERIMETRE_ORIGINE_CONTAINS", "vide");
		g.setParameter("PERIMETRE_ORIGINE_SQL", "vide");		
		g.setParameter("PERIMETRE_SSE", "vide");
		g.setParameter("PERIMETRE_SSE_CONTAINS", "vide");
		g.setParameter("PERIMETRE_SSE_SQL", "vide");		
		g.setParameter("PERIMETRE_SSE_PROTEGES_CONTAINS", "vide");
		g.setParameter("PERIMETRE_SSE_PROTEGES_SQL", "vide");		
		g.setParameter("PERIMETRE_SSE_PROTEGES", "vide");		
		g.setParameter("PERIMETRE_SSE_PROTEGE", 0);
		g.setParameter("PERIMETRE_SSE_RW", "vide");
		g.setParameter("SSE_LECTURE_SEULE","1");
		g.setParameter("PERIMETRE_DF", "vide");
		g.setParameter("PERIMETRE_DF_CONTAINS", "vide");
		g.setParameter("PERIMETRE_DF_SQL", "vide");			
		g.setParameter("PERIMETRE_CF", "vide");
		g.setParameter("PERIMETRE_CF_CONTAINS", "vide");
		g.setParameter("PERIMETRE_CFDF", "vide");
		g.setParameter("RDD_IN_USE", "false");
		
		
	
		// Récupération des ids des perimetre utilisateur
		perimetre = g.query("select p.row_id, p.perimetre_sseprotege from sio_userperimetre us inner join sio_perimetre p on us.SIOUSERPERIMETRE_SIOPERIMETRE_FK = p.row_id where SIOUSERPERIMETRE_USER_FK = "+ g.getUserId());
		
		if(perimetre.size()==0){
			g.setParameter("sansPerimetre", "true");
		}else{
			for(String[] s : perimetre){
				listPerimetre += s[0] + ",";
				sse_protege = s[1];
			}
			if (listPerimetre!="")
				g.setParameter("PERIMETRE_ID", listPerimetre.substring(0, listPerimetre.length()-1)) ;
			g.setParameter("PERIMETRE_SSE_PROTEGE", sse_protege) ;
			
			//Récupération des espace de Description
			espace = g.query("select SIOPERIMETREESPACE_SIOESPACE_FK, perimetreespace_lecture_seule from sio_perimetreespace where SIOPERIMETREESPACE_SIOPERIMETRE_FK in ("+g.getParameter("PERIMETRE_ID")+")");
			String row = "";
			for(String[] s : espace){
				listEspace += s[0] + ",";
				if(s[1].equals("1")){
					listEspace_lecture_seule += s[0] + "," ;
				}else{
					listEspace_ecriture += s[0] + "," ;
				}
				// row = String.join("-", s);
				// listEspace_lecture_seule += row + "," ;
			}
			
			if (listEspace!="")
				g.setParameter("PERIMETRE_ESPACE", listEspace.substring(0, listEspace.length()-1));
			if (listEspace_lecture_seule!="")
				g.setParameter("PERIMETRE_ESPACE_RW", listEspace_lecture_seule.substring(0, listEspace_lecture_seule.length()-1));
			if (listEspace_ecriture!="")
				g.setParameter("PERIMETRE_ESPACE_W", listEspace_ecriture.substring(0, listEspace_ecriture.length()-1));
			
			//Récupération des espace de sse
			// si on a le droit de voir les SSE protegés alors on voit aussi ceux qui ne le sont pas
			//if (sse_protege.equals("1"))
				sse_protege = "";
			// else 
			// 	sse_protege = "and sse.SSE_PROTEGEE = '0'";
			String requete_sse = "select psse.SIOPERIMETRESOUSENSEMBLE_SIOSOUSENSEMBLE_FK, psse.perimetresse_lecture_seule from sio_perimetresousensemble psse inner join sio_sousensemble sse on sse.row_id = psse.SIOPERIMETRESOUSENSEMBLE_SIOSOUSENSEMBLE_FK where psse.sioperimetresousensemble_sioperimetre_fk  in ("+g.getParameter("PERIMETRE_ID")+") "+sse_protege;
			sse = g.query(requete_sse);
			
			String ligne = "";
			for(String[] s : sse){
				ligne = String.join("-", s);
				listSSERW += ligne + ",";
				listSSE+=s[0]+",";
				listSSESql+="'"+s[0]+"',";				
				listSSECote+="'" + s[0] + "',";
			}
			if (listSSE!=""){
				g.setParameter("PERIMETRE_SSE", listSSE.substring(0, listSSE.length()-1));
				g.setParameter("PERIMETRE_SSE_COTE", listSSECote.substring(0, listSSECote.length()-1));
				g.setParameter("PERIMETRE_SSE_CONTAINS", listSSE.substring(0, listSSE.length()));
				g.setParameter("PERIMETRE_SSE_SQL", listSSESql.substring(0, listSSESql.length()-1));				
			}
			if (listSSERW!="")
				g.setParameter("PERIMETRE_SSE_RW", listSSERW.substring(0, listSSERW.length()-1));
	
	
			//Récupération des Groupes Origine
			groupe_origine = g.query("select SIO_PERIMETREGROUPEORIGINE_SIOGROUPEORIGINE_FK  from sio_perimetregroupeorigine where SIO_PERIMETREGROUPEORIGINE_SIOPERIMETRE_FK in ("+g.getParameter("PERIMETRE_ID")+")");
			for(String[] s : groupe_origine){
				listGroupeOrigine += s[0] + ",";
				listGroupeOrigineSql+="'"+s[0]+"',";	
			
			}
			if (listGroupeOrigine!=""){
				g.setParameter("PERIMETRE_GROUPE_ORIGINE", listGroupeOrigine.substring(0, listGroupeOrigine.length()-1));
				g.setParameter("PERIMETRE_GROUPE_ORIGINE_CONTAINS", "," + listGroupeOrigine.substring(0, listGroupeOrigine.length())); 
				g.setParameter("PERIMETRE_GROUPE_ORIGINE_SQL",listGroupeOrigineSql.substring(0, listGroupeOrigineSql.length()-1)); 
			}
			
			//Récupération des Origines
			origine = g.query("select SIOPERIMETREORIGINE_SIOORIGINE_FK from sio_perimetreorigine where SIOPERIMETREORIGINE_SIOPERIMETRE_FK in ("+g.getParameter("PERIMETRE_ID")+")");
			for(String[] s : origine){
				listOrigine += s[0] + ",";
				listOrigineSql+="'"+s[0]+"',";
			}
			if (listOrigine!=""){
				g.setParameter("PERIMETRE_ORIGINE", listOrigine.substring(0, listOrigine.length()-1));
				g.setParameter("PERIMETRE_ORIGINE_CONTAINS", "," + listOrigine.substring(0, listOrigine.length())); 
				g.setParameter("PERIMETRE_ORIGINE_SQL",  listOrigineSql.substring(0, listOrigineSql.length()-1)); 
			}
			
			//Récupération des CF
			cf = g.query("select perimetecf_cf_fk  from sio_perimetre_cf where perimetrecf_perimetre_fk in ("+g.getParameter("PERIMETRE_ID")+")");
			for(String[] s : cf){
				listCF += s[0] + ",";
			}		
			if (listCF!=""){
	
				g.setParameter("PERIMETRE_CF", listCF.substring(0, listCF.length()-1));
				g.setParameter("PERIMETRE_CF_CONTAINS", "," + listCF.substring(0, listCF.length())); 
				
			}	
			
			
			//Récupération des DF && CF/DF
			df = g.query("select perimetredf_df_fk from sio_perimetre_df where perimetredf_perimetre_fk in ("+g.getParameter("PERIMETRE_ID")+")");
			for(String[] s : df){
				listDF += s[0] + ",";
				listDFSql+="'"+s[0]+"',";				
				cfdf = g.query("select row_id, cfdf_centrefinancier_fk from sio_cfdf where cfdf_domainefonctionnel_fk='"+ s[0] +"'");
				for(String[] c : cfdf){
					if(g.getParameter("PERIMETRE_CF_CONTAINS").contains(c[1])){
						listCFDF += c[0] + ",";
					}
				}
			}		
			if (listDF!=""){
				g.setParameter("PERIMETRE_DF", listDF.substring(0, listDF.length()-1));
				g.setParameter("PERIMETRE_DF_CONTAINS", "," + listDF.substring(0, listDF.length())); 
				g.setParameter("PERIMETRE_DF_SQL",  listDFSql.substring(0, listDFSql.length()-1)); 				
			}
			if (listCFDF!=""){
				g.setParameter("PERIMETRE_CFDF", listCFDF.substring(0, listCFDF.length()-1)); 
				g.setParameter("PERIMETRE_CFDF_CONTAINS", "," + listCFDF.substring(0, listCFDF.length()-1)); 
			}
		}

	}

/*	public static void preLoadGrant(Grant g) {
			//appLog.info(GrantHooks.class, "initUpdate", "test grand hook2 " , g);
			//appLog.info(GrantHooks.class, "initUpdate", "id de utilisateur2 " + g, g);
		//String userId = Integer.toString(g.getUserId());
	//	String userId = String.valueOf(g.getUserId());	
		if(intervaleCadragePoste(g)==true) {
			g.addResponsibility("userId", "SIOPoste-CRUD", "", "", true, "ApplicationUsers");
		} 
	
	}
	*/
	
	public static boolean intervaleCadragePoste(Grant g) {
	
		ObjectDB cadragePoste = g.getTmpObject("SIODateDeCadrage");
		cadragePoste.resetFilters();
		////appLog.info(getClass(), "initUpdate", "getGrant(): " + g.getUserId(), g);
		
		//String userId =Integer.toString(g.getUserId());
		String userId = String.valueOf(g.getUserId());
		
		cadragePoste.getField("SIODateDeCadrage_User_fk").setFilter(userId);
	//	//appLog.info(GrantHooks.class, "initUpdate", "id de l'user " + g.getUserId(), g);
		
		for (String[] row : cadragePoste.search(false)) {
			cadragePoste.setValues(row,false);
		}
			
		DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		GregorianCalendar gc = new GregorianCalendar();
		
		// date du jour
		String today = "";
		Date dateDuJour = gc.getTime(); 
		today = sdf.format(dateDuJour);
		//appLog.info(GrantHooks.class, "initUpdate", "date du jour: " + today, g);
		
		// date debut cadrage du user
		String datedebut = "";
		Date cadrageDebut = cadragePoste.getField("DATE_CADRAGE_DEBUT").getDate();
		datedebut = sdf.format(cadrageDebut);
		//appLog.info(GrantHooks.class, "initUpdate", "date de début: " + datedebut, g);
		
		// date fin cadrage du user
		String dateFin = "";
		Date cadrageFin = cadragePoste.getField("DATE_CADRAGE_FIN").getDate();
		dateFin = sdf.format(cadrageFin);
		//appLog.info(GrantHooks.class, "initUpdate", "date de fin: " + dateFin, g);
			
		//appLog.info(GrantHooks.class, "initUpdate", "boolean intervalle : " + ((dateDuJour.after(cadrageDebut)) && (dateDuJour.before(cadrageFin))), g);
			
		if ((dateDuJour.after(cadrageDebut)) && (dateDuJour.before(cadrageFin))) {
		
			return true;
			
		} else {
			return false;
		}
	}
	
/*	
	private String getIdPerimetreByIdUser(){
		//appLog.info(getClass(), "getIdPerimetreByIdUser", "Récupération des habilitations de l'utilisateur d'Id : " + getGrant().getUserId(), getGrant());
		List<String> idPerimetre = new ArrayList<>();
		
		ObjectDB userPerimetre = (ObjectDB) getGrant().getTmpObject("SIOUserPerimetre");
		userPerimetre.resetFilters();
		userPerimetre.getField("SIOUserPerimetre_User_fk").setFilter(getGrant().getUserId());
		List<String[]> resultat = userPerimetre.search(false);

			for (String[] row : resultat) {
				userPerimetre.setValues(row,false);
			}
		return getFieldValue("SIOUserPerimetre_SIOPerimetre_fk");
	}
	
*/	

	public static boolean isMenuEnable(Grant g, String domain, String item) {
		if(g.getParameter("sansPerimetre")!=null && g.getParameter("sansPerimetre").equals("true")){
			return false;
		}
		return true;
	}

	public static void preLoadGrant(Grant g) {
		
		Grant sys = Grant.getSystemAdmin();

		if (g.isSAMLAuthMethod()) try { // only if SAML auth
			String login = g.getLogin();
			if (Tool.isEmpty(login))
				throw new AuthenticationException("Empty login");

			// Create user if needed
			if (!Grant.exists(login, false)) {
				ObjectDB usr = sys.getTmpObject("User");
				synchronized (usr) { // thread-safe
					usr.resetValues(true);
					usr.setRowId(ObjectField.DEFAULT_ROW_ID);
					usr.getField("usr_login").setValue(login);
					usr.setFieldValue("usr_lang", Globals.LANG_FRENCH);
					usr.setFieldValue("usr_home_id", View.getViewId(sys.getParameter("DEFAULT_USER_HOME", "SIOFirstVisite")));
					usr.setStatus(Grant.USER_ACTIVE);
					//appLog.info(GrantHooks.class, "preLoadGrant", "User to create " + usr.toJSONObject().toString(2), sys);
					new BusinessObjectTool(usr).validateAndCreate();

					String module = usr.getFieldValue("row_module_id.mdl_name");
					//appLog.info(GrantHooks.class, "preLoadGrant", "Created user " + login + " in module " + module, sys);

					String group = sys.getParameter("DEFAULT_USER_GROUP", "SIO_PROFIL_DEFAUT");
					if (isRFUser(login)){
		               	group = "SIO_PROFIL_RF";
		             }
					Grant.addResponsibility(usr.getRowId(), group, Tool.getCurrentDate(-1), "", true, module);
					//appLog.info(GrantHooks.class, "preLoadGrant", "Added " + group + " responsibility for user " + login, sys);
				}
			}
		} catch (Exception e) {
			AppLog.error(GrantHooks.class, "preLoadGrant", null, e, sys);
		}
	}
	
	public static boolean isRFUser(String inputStr) {
		 // Utilisateur responsable fonctionnel
		String[] items = {"e.renevier1", "a.pomart", "j.legrand15","c.vigneron", "s.payraudeau"};
    	return Arrays.stream(items).parallel().anyMatch(inputStr::contains);
	}
	
	public static List<String> getListeSSEProtege(Grant g){
		//appLog.info(GrantHooks.class, "getListeSSEProtege", "Debut", g);
			List<String> listSSEProtege = new ArrayList<>();
			List<String[]> listquerySSE = g.query("select row_id from sio_sousensemble where sse_protegee='1'");
				for(String[] sseQuery : listquerySSE){
					listSSEProtege.add(sseQuery[0]);
				}
			return listSSEProtege;
		}
		
	public static String mySSeProtege(List<String> listSSEProtege,Grant g){

			String mySSE="";
			String mySSESQL="";
			for(String sseProtege :listSSEProtege){
				if(g.getParameter("PERIMETRE_SSE_CONTAINS").contains(sseProtege)){
					mySSE+=sseProtege+",";
					mySSESQL+="'"+sseProtege+"',";
					
				}
					
			}
			if (!mySSESQL.isEmpty())
				g.setParameter("PERIMETRE_SSE_PROTEGES_SQL", mySSESQL.substring(0, mySSESQL.length()-1));
			return mySSE;
			
		}	
	
	
}

OK ajoute cette implémentation et le message devrait disparaître:

public static String parseAuth(Grant sys, com.simplicite.util.SessionInfo info) {
    return info.getLogin();
}

Nickel après un clear cache je ne vois plus le message.
Merci.

OK, ce message disparaîtra dans la version 5 de toute façon