Skip to content

Commit

Permalink
[Utils, GovWayCore, GovWayConsole]
Browse files Browse the repository at this point in the history
La funzionalità di "Verifica Connettori" è stata estesa con la possibilità di effettuare il download dei certificati ritornati dal server, in caso di endpoint https.
Risolto inoltre problema di esportazione delle erogazioni e fruizione, senza opzione 'Includi Elementi Riferiti': non venivano esportate i componenti di porta applicativa o delegata associati.
  • Loading branch information
andreapoli committed Mar 30, 2020
1 parent 082df23 commit 2782c4b
Show file tree
Hide file tree
Showing 25 changed files with 699 additions and 36 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2019-03-30 Andrea Poli <[email protected]>

* [Utils, GovWayCore, GovWayConsole]
Aggiunta funzionalità OP-968
La funzionalità di "Verifica Connettori" è stata estesa con la possibilità di effettuare il download dei certificati ritornati dal server, in caso di endpoint https.

2019-03-26 Andrea Poli <[email protected]>

* [GovWayCore, ProtocolloSPCoop]
Expand Down
106 changes: 105 additions & 1 deletion core/src/org/openspcoop2/pdd/core/connettori/ConnettoreCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ private static void putAll(Properties config, Map<String, String> mapProperties)
}
}
}

private static void _checkHTTP(TipiConnettore tipoConnettore, Connettore connettore) throws Exception {

ConnettoreHTTPSProperties sslContextProperties = null;
Expand Down Expand Up @@ -465,4 +465,108 @@ else if(CostantiConnettori.CONNETTORE_HTTP_PROXY_TYPE_VALUE_HTTPS.equals(tipo)){
}
}







public static String getCertificati(long idConnettore, boolean registro) throws ConnettoreException{
if(registro) {
Enumeration<IDriverRegistroServiziGet> drivers = RegistroServiziReader.getDriverRegistroServizi().elements();
while (drivers.hasMoreElements()) {
IDriverRegistroServiziGet iDriverRegistroServiziGet = (IDriverRegistroServiziGet) drivers.nextElement();
if(iDriverRegistroServiziGet instanceof DriverRegistroServiziDB) {
try {
org.openspcoop2.core.registry.Connettore connettore = ((DriverRegistroServiziDB)iDriverRegistroServiziGet).getConnettore(idConnettore);
return getCertificati(connettore);
}catch(Throwable e) {
throw new ConnettoreException(e.getMessage(),e);
}
}
}
}
else {
IDriverConfigurazioneGet iDriverConfigurazioneGet = ConfigurazionePdDReader.getDriverConfigurazionePdD();
if(iDriverConfigurazioneGet instanceof DriverConfigurazioneDB) {
try {
Connettore connettore = ((DriverConfigurazioneDB)iDriverConfigurazioneGet).getConnettore(idConnettore);
return getCertificati(connettore);
}catch(Throwable e) {
throw new ConnettoreException(e.getMessage(),e);
}
}
}
throw new ConnettoreException("Connettore con id '"+idConnettore+"' non trovato");
}
public static String getCertificati(String nomeConnettore, boolean registro) throws ConnettoreException{
if(registro) {
Enumeration<IDriverRegistroServiziGet> drivers = RegistroServiziReader.getDriverRegistroServizi().elements();
while (drivers.hasMoreElements()) {
IDriverRegistroServiziGet iDriverRegistroServiziGet = (IDriverRegistroServiziGet) drivers.nextElement();
if(iDriverRegistroServiziGet instanceof DriverRegistroServiziDB) {
try {
org.openspcoop2.core.registry.Connettore connettore = ((DriverRegistroServiziDB)iDriverRegistroServiziGet).getConnettore(nomeConnettore);
return getCertificati(connettore);
}catch(Throwable e) {
throw new ConnettoreException(e.getMessage(),e);
}
}
}
}
else {
IDriverConfigurazioneGet iDriverConfigurazioneGet = ConfigurazionePdDReader.getDriverConfigurazionePdD();
if(iDriverConfigurazioneGet instanceof DriverConfigurazioneDB) {
try {
Connettore connettore = ((DriverConfigurazioneDB)iDriverConfigurazioneGet).getConnettore(nomeConnettore);
return getCertificati(connettore);
}catch(Throwable e) {
throw new ConnettoreException(e.getMessage(),e);
}
}
}

throw new ConnettoreException("Connettore con nome '"+nomeConnettore+"' non trovato");
}

public static String getCertificati(org.openspcoop2.core.registry.Connettore connettore) throws ConnettoreException{
return _getCertificati(connettore.mappingIntoConnettoreConfigurazione());
}
public static String getCertificati(Connettore connettore) throws ConnettoreException{
return _getCertificati(connettore);
}
private static String _getCertificati(Connettore connettore) throws ConnettoreException {

try {

Map<String,String> properties = connettore.getProperties();
String location = properties!=null ? properties.get(CostantiConnettori.CONNETTORE_LOCATION) : null;
if(location==null || "".equals(location)) {
throw new Exception("Il connettore non possiede un endpoint");
}
URL url = new URL( location );
String host = url.getHost();
if(host==null || "".equals(host)) {
throw new Exception("L'endpoint '"+host+"' non contiene un host");
}
int port = url.getPort();
if(port<=0) {
if("https".equalsIgnoreCase(url.getProtocol())) {
port = 443;
}
else if("http".equalsIgnoreCase(url.getProtocol())) {
port = 80;
}
else {
throw new Exception("L'endpoint '"+host+"' contiene un protocollo '"+url.getProtocol()+"' non supportato");
}
}

return SSLUtilities.readPeerCertificates(host, port);

}catch(Throwable e) {
throw new ConnettoreException(e.getMessage(),e);
}

}
}
71 changes: 71 additions & 0 deletions core/src/org/openspcoop2/pdd/core/jmx/AccessoRegistroServizi.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public class AccessoRegistroServizi extends NotificationBroadcasterSupport imple
/** Nomi metodi' */
public final static String CHECK_CONNETTORE_BY_ID = "checkConnettoreById";
public final static String CHECK_CONNETTORE_BY_NOME = "checkConnettoreByNome";
public final static String GET_CERTIFICATI_CONNETTORE_BY_ID = "getCertificatiConnettoreById";
public final static String GET_CERTIFICATI_CONNETTORE_BY_NOME = "getCertificatiConnettoreByNome";

/** Attributi */
private boolean cacheAbilitata = false;
Expand Down Expand Up @@ -280,6 +282,37 @@ public Object invoke(String actionName, Object[]params, String[]signature) throw
return this.checkConnettoreByNome(param1);
}

if(actionName.equals(GET_CERTIFICATI_CONNETTORE_BY_ID)){
if(params.length != 1)
throw new MBeanException(new Exception("["+GET_CERTIFICATI_CONNETTORE_BY_ID+"] Lunghezza parametri non corretta: "+params.length));

Long param1 = null;
if(params[0]!=null && !"".equals(params[0])){
if(params[0] instanceof Long) {
param1 = (Long)params[0];
}
else {
param1 = Long.valueOf(params[0].toString());
}

if(param1<0){
param1 = null;
}
}
return this.getCertificatiConnettoreById(param1);
}

if(actionName.equals(GET_CERTIFICATI_CONNETTORE_BY_NOME)){
if(params.length != 1)
throw new MBeanException(new Exception("["+GET_CERTIFICATI_CONNETTORE_BY_NOME+"] Lunghezza parametri non corretta: "+params.length));

String param1 = null;
if(params[0]!=null && !"".equals(params[0])){
param1 = (String)params[0];
}
return this.getCertificatiConnettoreByNome(param1);
}

throw new UnsupportedOperationException("Operazione "+actionName+" sconosciuta");
}

Expand Down Expand Up @@ -342,6 +375,24 @@ public MBeanInfo getMBeanInfo(){
String.class.getName(),
MBeanOperationInfo.ACTION);

// MetaData per l'operazione getCertificatiConnettoreById
MBeanOperationInfo getCertificatiConnettoreById
= new MBeanOperationInfo(GET_CERTIFICATI_CONNETTORE_BY_ID,"Recupera i certificati server del connettore con id fornito come parametro",
new MBeanParameterInfo[]{
new MBeanParameterInfo("idConnettore",long.class.getName(),"Identificativo del connettore"),
},
String.class.getName(),
MBeanOperationInfo.ACTION);

// MetaData per l'operazione getCertificatiConnettoreByNome
MBeanOperationInfo getCertificatiConnettoreByNome
= new MBeanOperationInfo(GET_CERTIFICATI_CONNETTORE_BY_NOME,"Recupera i certificati server del connettore con nome fornito come parametro",
new MBeanParameterInfo[]{
new MBeanParameterInfo("nomeConnettore",String.class.getName(),"Nome del connettore"),
},
String.class.getName(),
MBeanOperationInfo.ACTION);

// Mbean costruttore
MBeanConstructorInfo defaultConstructor = new MBeanConstructorInfo("Default Constructor","Crea e inizializza una nuova istanza del MBean",null);

Expand All @@ -365,6 +416,8 @@ public MBeanInfo getMBeanInfo(){
listOperation.add(removeObjectCacheOP);
listOperation.add(checkConnettoreById);
listOperation.add(checkConnettoreByNome);
listOperation.add(getCertificatiConnettoreById);
listOperation.add(getCertificatiConnettoreByNome);
MBeanOperationInfo[] operations = listOperation.toArray(new MBeanOperationInfo[1]);

return new MBeanInfo(className,description,attributes,constructors,operations,null);
Expand Down Expand Up @@ -530,4 +583,22 @@ public String checkConnettoreByNome(String nomeConnettore) {
return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
}
}

public String getCertificatiConnettoreById(long idConnettore) {
try{
return ConnettoreCheck.getCertificati(idConnettore, true);
}catch(Throwable e){
this.log.error(e.getMessage(),e);
return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
}
}

public String getCertificatiConnettoreByNome(String nomeConnettore) {
try{
return ConnettoreCheck.getCertificati(nomeConnettore, true);
}catch(Throwable e){
this.log.error(e.getMessage(),e);
return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
}
}
}
70 changes: 70 additions & 0 deletions core/src/org/openspcoop2/pdd/core/jmx/ConfigurazionePdD.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class ConfigurazionePdD extends NotificationBroadcasterSupport implements
/** Nomi metodi' */
public final static String CHECK_CONNETTORE_BY_ID = "checkConnettoreById";
public final static String CHECK_CONNETTORE_BY_NOME = "checkConnettoreByNome";
public final static String GET_CERTIFICATI_CONNETTORE_BY_ID = "getCertificatiConnettoreById";
public final static String GET_CERTIFICATI_CONNETTORE_BY_NOME = "getCertificatiConnettoreByNome";

/** Attributi */
private boolean cacheAbilitata = false;
Expand Down Expand Up @@ -355,6 +357,36 @@ public Object invoke(String actionName, Object[]params, String[]signature) throw
return this.checkConnettoreByNome(param1);
}

if(actionName.equals(GET_CERTIFICATI_CONNETTORE_BY_ID)){
if(params.length != 1)
throw new MBeanException(new Exception("["+GET_CERTIFICATI_CONNETTORE_BY_ID+"] Lunghezza parametri non corretta: "+params.length));

Long param1 = null;
if(params[0]!=null && !"".equals(params[0])){
if(params[0] instanceof Long) {
param1 = (Long)params[0];
}
else {
param1 = Long.valueOf(params[0].toString());
}
if(param1<0){
param1 = null;
}
}
return this.getCertificatiConnettoreById(param1);
}

if(actionName.equals(GET_CERTIFICATI_CONNETTORE_BY_NOME)){
if(params.length != 1)
throw new MBeanException(new Exception("["+GET_CERTIFICATI_CONNETTORE_BY_NOME+"] Lunghezza parametri non corretta: "+params.length));

String param1 = null;
if(params[0]!=null && !"".equals(params[0])){
param1 = (String)params[0];
}
return this.getCertificatiConnettoreByNome(param1);
}

throw new UnsupportedOperationException("Operazione "+actionName+" sconosciuta");
}

Expand Down Expand Up @@ -482,6 +514,24 @@ public MBeanInfo getMBeanInfo(){
},
String.class.getName(),
MBeanOperationInfo.ACTION);

// MetaData per l'operazione getCertificatiConnettoreById
MBeanOperationInfo getCertificatiConnettoreById
= new MBeanOperationInfo(GET_CERTIFICATI_CONNETTORE_BY_ID,"Recupera i certificati server del connettore con id fornito come parametro",
new MBeanParameterInfo[]{
new MBeanParameterInfo("idConnettore",long.class.getName(),"Identificativo del connettore"),
},
String.class.getName(),
MBeanOperationInfo.ACTION);

// MetaData per l'operazione getCertificatiConnettoreByNome
MBeanOperationInfo getCertificatiConnettoreByNome
= new MBeanOperationInfo(GET_CERTIFICATI_CONNETTORE_BY_NOME,"Recupera i certificati server del connettore con nome fornito come parametro",
new MBeanParameterInfo[]{
new MBeanParameterInfo("nomeConnettore",String.class.getName(),"Nome del connettore"),
},
String.class.getName(),
MBeanOperationInfo.ACTION);

// Mbean costruttore
MBeanConstructorInfo defaultConstructor = new MBeanConstructorInfo("Default Constructor","Crea e inizializza una nuova istanza del MBean",null);
Expand Down Expand Up @@ -511,6 +561,8 @@ public MBeanInfo getMBeanInfo(){
listOperation.add(removeObjectCacheOP);
listOperation.add(checkConnettoreById);
listOperation.add(checkConnettoreByNome);
listOperation.add(getCertificatiConnettoreById);
listOperation.add(getCertificatiConnettoreByNome);
MBeanOperationInfo[] operations = listOperation.toArray(new MBeanOperationInfo[1]);

return new MBeanInfo(className,description,attributes,constructors,operations,null);
Expand Down Expand Up @@ -763,4 +815,22 @@ public String checkConnettoreByNome(String nomeConnettore) {
return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
}
}

public String getCertificatiConnettoreById(long idConnettore) {
try{
return ConnettoreCheck.getCertificati(idConnettore, true);
}catch(Throwable e){
this.log.error(e.getMessage(),e);
return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
}
}

public String getCertificatiConnettoreByNome(String nomeConnettore) {
try{
return ConnettoreCheck.getCertificati(nomeConnettore, true);
}catch(Throwable e){
this.log.error(e.getMessage(),e);
return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
}
}
}
Loading

0 comments on commit 2782c4b

Please sign in to comment.