Skip to content

Commit

Permalink
Closes: #69
Browse files Browse the repository at this point in the history
[GovWayCore]
Sia nella funzionalità di negoziazione dei token che durante la verifica tramite servizio di introspection e userInfo, viene adesso utilizzata la modalità http 'content-length' al posto della precedente modalità 'transfer-encoding-chunked'.
Nella negoziazione del token è stato inoltre corretto il body della richiesta 'application/x-www-form-urlencoded' eliminando il primo carattere '&' aggiunto erroneamente (es. &grant_type=client_credentials).
  • Loading branch information
andreapoli committed Oct 14, 2020
1 parent 9dc4f5d commit 38bce51
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
@@ -1,3 +1,12 @@
2020-10-13 Andrea Poli <apoli@link.it>

* [GovWayCore]
Risolto Bug OP-1075
(https://github.com/link-it/govway/issues/69)
Sia nella funzionalità di negoziazione dei token che durante la verifica tramite servizio di introspection e userInfo,
viene adesso utilizzata la modalità http 'content-length' al posto della precedente modalità 'transfer-encoding-chunked'.
Nella negoziazione del token è stato inoltre corretto il body della richiesta 'application/x-www-form-urlencoded' eliminando il primo carattere '&' aggiunto erroneamente (es. &grant_type=client_credentials).

2020-10-13 Andrea Poli <apoli@link.it>

* [GovWayConsole, GovWayMonitor]
Expand Down
4 changes: 4 additions & 0 deletions core/deploy/properties/govway.properties
Expand Up @@ -2783,6 +2783,10 @@ org.openspcoop2.pdd.cachingResponse.header.cacheKey=GovWay-CacheKey

#---------- Gestione Token --------------

# Debug utilizzato nel connettore http, in fase di introspection o userInfo del token
org.openspcoop2.pdd.gestioneToken.introspection.debug=true
org.openspcoop2.pdd.gestioneToken.userInfo.debug=true

# Il cliam 'iat' puo' essere usato per reject token che sono stati istituiti molto indietro nel tempo.
# La seguente proprietà, nel caso sia presente un 'iat' claim, verifica che la data indicata non sia più vecchia dei minuti indicati.
# Se la proprietà non è impostata non viene attuato alcun controllo.
Expand Down
52 changes: 52 additions & 0 deletions core/src/org/openspcoop2/pdd/config/OpenSPCoop2Properties.java
Expand Up @@ -1728,6 +1728,8 @@ else if( CostantiConfigurazione.CONFIGURAZIONE_DB.equalsIgnoreCase(getTipoConfig
this.getCachingResponseHeaderCacheKey();

// Gestione Token
this.isGestioneToken_introspection_debug();
this.isGestioneToken_userInfo_debug();
this.getGestioneToken_iatTimeCheck_milliseconds();
this.isGestioneToken_saveSourceTokenInfo();
this.getGestioneTokenFormatDate();
Expand Down Expand Up @@ -16784,6 +16786,56 @@ public String getCachingResponseHeaderCacheKey(){

/* ------------- Gestione Token ---------------------*/

private static Boolean isGestioneToken_introspection_debug = null;
public boolean isGestioneToken_introspection_debug(){

String pName = "org.openspcoop2.pdd.gestioneToken.introspection.debug";
if(OpenSPCoop2Properties.isGestioneToken_introspection_debug==null){
try{
String value = this.reader.getValue_convertEnvProperties(pName);

if (value != null){
value = value.trim();
OpenSPCoop2Properties.isGestioneToken_introspection_debug = Boolean.parseBoolean(value);
}else{
this.log.warn("Proprieta' di openspcoop '"+pName+"' non impostata, viene utilizzato il default=false");
OpenSPCoop2Properties.isGestioneToken_introspection_debug = false;
}

}catch(java.lang.Exception e) {
this.log.warn("Proprieta' di openspcoop '"+pName+"' non impostata, viene utilizzato il default=false, errore:"+e.getMessage(),e);
OpenSPCoop2Properties.isGestioneToken_introspection_debug = false;
}
}

return OpenSPCoop2Properties.isGestioneToken_introspection_debug;
}

private static Boolean isGestioneToken_userInfo_debug = null;
public boolean isGestioneToken_userInfo_debug(){

String pName = "org.openspcoop2.pdd.gestioneToken.userInfo.debug";
if(OpenSPCoop2Properties.isGestioneToken_userInfo_debug==null){
try{
String value = this.reader.getValue_convertEnvProperties(pName);

if (value != null){
value = value.trim();
OpenSPCoop2Properties.isGestioneToken_userInfo_debug = Boolean.parseBoolean(value);
}else{
this.log.warn("Proprieta' di openspcoop '"+pName+"' non impostata, viene utilizzato il default=false");
OpenSPCoop2Properties.isGestioneToken_userInfo_debug = false;
}

}catch(java.lang.Exception e) {
this.log.warn("Proprieta' di openspcoop '"+pName+"' non impostata, viene utilizzato il default=false, errore:"+e.getMessage(),e);
OpenSPCoop2Properties.isGestioneToken_userInfo_debug = false;
}
}

return OpenSPCoop2Properties.isGestioneToken_userInfo_debug;
}

private static Boolean getGestioneToken_iatTimeCheck_milliseconds_read = null;
private static Integer getGestioneToken_iatTimeCheck_milliseconds = null;
public Integer getGestioneToken_iatTimeCheck_milliseconds() throws Exception{
Expand Down
17 changes: 17 additions & 0 deletions core/src/org/openspcoop2/pdd/core/token/GestoreToken.java
Expand Up @@ -39,6 +39,7 @@
import org.openspcoop2.core.config.constants.StatoFunzionalita;
import org.openspcoop2.core.constants.CostantiConnettori;
import org.openspcoop2.core.constants.TipiConnettore;
import org.openspcoop2.core.constants.TransferLengthModes;
import org.openspcoop2.core.mvc.properties.provider.ProviderException;
import org.openspcoop2.core.mvc.properties.provider.ProviderValidationException;
import org.openspcoop2.message.OpenSPCoop2Message;
Expand Down Expand Up @@ -2154,6 +2155,18 @@ private static HttpResponse http(Logger log, PolicyGestioneToken policyGestioneT

connettoreMsg.setConnectorProperties(new java.util.Hashtable<String,String>());
connettoreMsg.getConnectorProperties().put(CostantiConnettori.CONNETTORE_LOCATION, endpoint);
boolean debug = false;
OpenSPCoop2Properties properties = OpenSPCoop2Properties.getInstance();
if(introspection) {
debug = properties.isGestioneToken_introspection_debug();
}
else {
debug = properties.isGestioneToken_userInfo_debug();
}
if(debug) {
connettoreMsg.getConnectorProperties().put(CostantiConnettori.CONNETTORE_DEBUG, true+"");
}
connettoreMsg.getConnectorProperties().put(CostantiConnettori.CONNETTORE_HTTP_DATA_TRANSFER_MODE, TransferLengthModes.CONTENT_LENGTH.getNome());
addProperties(connettoreMsg, endpointConfig);
if(https) {
addProperties(connettoreMsg, sslConfig);
Expand Down Expand Up @@ -2577,6 +2590,7 @@ public static HttpResponse http(boolean debug, Logger log, PolicyNegoziazioneTok
if(debug) {
connettoreMsg.getConnectorProperties().put(CostantiConnettori.CONNETTORE_DEBUG, true+"");
}
connettoreMsg.getConnectorProperties().put(CostantiConnettori.CONNETTORE_HTTP_DATA_TRANSFER_MODE, TransferLengthModes.CONTENT_LENGTH.getNome());
addProperties(connettoreMsg, endpointConfig);
if(https) {
addProperties(connettoreMsg, sslConfig);
Expand Down Expand Up @@ -2635,6 +2649,9 @@ else if(policyNegoziazioneToken.isUsernamePasswordGrant()) {
String prefixUrl = "PREFIX?";
String contentString = TransportUtils.buildLocationWithURLBasedParameter(pContent, prefixUrl , log);
contentString = contentString.substring(prefixUrl.length());
if(contentString.startsWith("&") && contentString.length()>1) {
contentString = contentString.substring(1);
}
content = contentString.getBytes();

OpenSPCoop2MessageParseResult pr = OpenSPCoop2MessageFactory.getDefaultMessageFactory().createMessage(MessageType.BINARY, transportRequestContext, content);
Expand Down

0 comments on commit 38bce51

Please sign in to comment.