Skip to content

Commit

Permalink
[GovWayCore]
Browse files Browse the repository at this point in the history
Aggunta possibilità di commentare le regole di autorizzazione per contenuto e per token claims.
Viene inoltre adesso mantenuto l'ordine di configurazione.
  • Loading branch information
andreapoli committed Jan 22, 2023
1 parent 7e07c7d commit b0b46da
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 59 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

* Rilasciata versione 3.3.10

2023-01-22 Andrea Poli <[email protected]>

* [GovWayCore]
Aggunta possibilità di commentare le regole di autorizzazione per contenuto e per token claims.
Viene inoltre adesso mantenuto l'ordine di configurazione.

2023-01-21 Andrea Poli <[email protected]>

* [Utils]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public void process(OpenSPCoop2Message msg, AbstractDatiInvocazione datiInvocazi
}
risorsa=risorsa.trim();

if(risorsa.startsWith("#")) {
// commento
continue;
}

if(expectedValue==null) {
throw new Exception("Trovata una regola di autorizzazione senza valore atteso");
}
Expand Down
85 changes: 85 additions & 0 deletions core/src/org/openspcoop2/pdd/core/dynamic/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public static void test() throws Exception{
TransportUtils.addHeader(connettoreMsg.getPropertiesTrasporto(),"Header2", "Valore2");
TransportUtils.addHeader(connettoreMsg.getPropertiesTrasporto(),"Header3.1", "Valore3.1");
TransportUtils.addHeader(connettoreMsg.getPropertiesTrasporto(),"Header3.(2)", "Valore3.(2)");
TransportUtils.addHeader(connettoreMsg.getPropertiesTrasporto(),"Header3.[\"3\"4\"]", "Valore3.[\"3\"4\"]");

connettoreMsg.setPropertiesUrlBased(new HashMap<String, List<String>>());
TransportUtils.addParameter(connettoreMsg.getPropertiesUrlBased(),"P1", "Valore1URL");
Expand Down Expand Up @@ -334,6 +335,16 @@ public static void test() throws Exception{
throw new Exception("Expected value '"+expected+"', found '"+value+"'");
}

String pattern = ".*gg([\\w\\t-_\"][\\w\\t-_\"][\\w\\t-_\"]).*";
expr = prefixOptional + "{securityToken:channel.certificate.subject.CN(\""+pattern+"\")}";
DynamicUtils.validate("testSecurityTokenVirgoletteInMezzo", expr, addPrefixError);
value = DynamicUtils.convertDynamicPropertyValue("testSecurityTokenVirgoletteInMezzo", expr, dynamicMap, pddContext);
System.out.println("testSecurityToken: "+value+"\n\n");
expected = "ett";
if(!expected.equals(value)) {
throw new Exception("Expected value '"+expected+"', found '"+value+"'");
}


expr = prefix + "{keywordNotExists:id}";
DynamicUtils.validate("testKeywordNotExists:id", expr, addPrefixError);
Expand Down Expand Up @@ -553,6 +564,16 @@ public static void test() throws Exception{
}


expr = prefix + "{context:[TEST2.1.a.2.3].headerFirstValue(Header3.[\"3\"4\"])}";
DynamicUtils.validate("testContextHeaderParametroConPuntoMethodParentesiValue2", expr, addPrefixError);
value = DynamicUtils.convertDynamicPropertyValue("testContextHeaderParametroConPuntoMethodParentesiValue2", expr, dynamicMap, pddContext);
System.out.println("testContextHeaderParametroConPuntoMethodParentesiValue2: "+value+"\n\n");
expected = "Valore3.[\"3\"4\"]";
if(!expected.equals(value)) {
throw new Exception("Expected value '"+expected+"', found '"+value+"'");
}



expr = prefix + "{header:Header1}";
DynamicUtils.validate("testHeader", expr, addPrefixError);
Expand Down Expand Up @@ -633,6 +654,68 @@ public static void test() throws Exception{



expr = prefix + "{header:[Header3.(2)]}";
DynamicUtils.validate("testHeaderParametroConPunto2", expr, addPrefixError);
value = DynamicUtils.convertDynamicPropertyValue("testHeaderParametroConPunto2", expr, dynamicMap, pddContext);
System.out.println("testHeaderParametroConPunto2: "+value+"\n\n");
expected = "Valore3.(2)";
if(!expected.equals(value)) {
throw new Exception("Expected value '"+expected+"', found '"+value+"'");
}

expr = prefix + "{transportContext:headerFirstValue(Header3.(2))}";
DynamicUtils.validate("testHeaderParametroConPuntoMethod2", expr, addPrefixError);
value = DynamicUtils.convertDynamicPropertyValue("testHeaderParametroConPuntoMethod2", expr, dynamicMap, pddContext);
System.out.println("testHeaderParametroConPuntoMethod2: "+value+"\n\n");
expected = "Valore3.(2)";
if(!expected.equals(value)) {
throw new Exception("Expected value '"+expected+"', found '"+value+"'");
}

expr = prefix + "{transportContext:headerValues(Header3.(2))[0]}";
DynamicUtils.validate("testHeaderParametroConPuntoEArray2", expr, addPrefixError);
value = DynamicUtils.convertDynamicPropertyValue("testHeaderParametroConPuntoEArray2", expr, dynamicMap, pddContext);
System.out.println("testHeaderParametroConPuntoEArray2: "+value+"\n\n");
expected = "Valore3.(2)";
if(!expected.equals(value)) {
throw new Exception("Expected value '"+expected+"', found '"+value+"'");
}




expr = prefix + "{header:[Header3.[\"3\"4\"]]}";
DynamicUtils.validate("testHeaderParametroConPunto3", expr, addPrefixError);
value = DynamicUtils.convertDynamicPropertyValue("testHeaderParametroConPunto3", expr, dynamicMap, pddContext);
System.out.println("testHeaderParametroConPunto3: "+value+"\n\n");
expected = "Valore3.[\"3\"4\"]";
if(!expected.equals(value)) {
throw new Exception("Expected value '"+expected+"', found '"+value+"'");
}

expr = prefix + "{transportContext:headerFirstValue(Header3.[\"3\"4\"])}";
DynamicUtils.validate("testHeaderParametroConPuntoMethod3", expr, addPrefixError);
value = DynamicUtils.convertDynamicPropertyValue("testHeaderParametroConPuntoMethod3", expr, dynamicMap, pddContext);
System.out.println("testHeaderParametroConPuntoMethod3: "+value+"\n\n");
expected = "Valore3.[\"3\"4\"]";
if(!expected.equals(value)) {
throw new Exception("Expected value '"+expected+"', found '"+value+"'");
}

// TODO: gestire anche questo caso complicato
// expr = prefix + "{transportContext:headerValues(\"Header3.[\"3\"4\"]\")[0]}";
// DynamicUtils.validate("testHeaderParametroConPuntoEArray3", expr, addPrefixError);
// value = DynamicUtils.convertDynamicPropertyValue("testHeaderParametroConPuntoEArray3", expr, dynamicMap, pddContext);
// System.out.println("testHeaderParametroConPuntoEArray3: "+value+"\n\n");
// expected = "Valore3.[\"3\"4\"]";
// if(!expected.equals(value)) {
// throw new Exception("Expected value '"+expected+"', found '"+value+"'");
// }





expr = prefix + "{query:P1}";
DynamicUtils.validate("testUrl", expr, addPrefixError);
value = DynamicUtils.convertDynamicPropertyValue("testUrl", expr, dynamicMap, pddContext);
Expand Down Expand Up @@ -1839,6 +1922,8 @@ public static void test() throws Exception{
fTmpOp2Properties.delete();
}
}

System.out.println("Testsuite terminata");
}

}
Expand Down
Binary file not shown.
82 changes: 74 additions & 8 deletions tools/utils/src/org/openspcoop2/utils/DynamicStringReplace.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,33 @@ else if(object instanceof Calendar){
// Devo convertire i punti dentro le quadre che potrebbero far parte delle chiavi
StringBuilder sbFormat = new StringBuilder();
boolean start = false;
int doppieVirgoletteIndex = -1;
boolean startDoppieVirgolette = false;
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
if((!start) && (c == '[')) {
start = true;
if((i+1 < value.length())) {
char cc = value.charAt(i+1);
if((cc == '"')) {
startDoppieVirgolette=true;
doppieVirgoletteIndex=i+1;
}
}
}
if((start) && (c == ']')) {
start = false;
if(!startDoppieVirgolette) {
start = false;
}
}
if((startDoppieVirgolette) && (c == '"') && doppieVirgoletteIndex!=i) {
if((i+1 < value.length())) {
char cc = value.charAt(i+1);
if((cc == ']')) {
startDoppieVirgolette = false;
doppieVirgoletteIndex=i;
}
}
}
if(start && c == '.') {
sbFormat.append('_');
Expand All @@ -374,13 +394,33 @@ else if(object instanceof Calendar){
// Devo convertire i punti dentro le tonde che potrebbero far parte delle chiavi
sbFormat = new StringBuilder();
start = false;
doppieVirgoletteIndex = -1;
startDoppieVirgolette = false;
for (int i = 0; i < internalNewValue.length(); i++) {
char c = internalNewValue.charAt(i);
if((!start) && (c == '(')) {
start = true;
if((i+1 < internalNewValue.length())) {
char cc = internalNewValue.charAt(i+1);
if((cc == '"')) {
startDoppieVirgolette=true;
doppieVirgoletteIndex=i+1;
}
}
}
if((start) && (c == ')')) {
start = false;
if(!startDoppieVirgolette) {
start = false;
}
}
if((startDoppieVirgolette) && (c == '"') && doppieVirgoletteIndex!=i) {
if((i+1 < internalNewValue.length())) {
char cc = internalNewValue.charAt(i+1);
if((cc == ')')) {
startDoppieVirgolette = false;
doppieVirgoletteIndex=i;
}
}
}
if(start && c == '.') {
sbFormat.append('_');
Expand Down Expand Up @@ -538,13 +578,33 @@ private static String readValueInObject(String key, Object o,String name, boolea
// Devo convertire i punti dentro le quadre che potrebbero far parte delle chiavi
StringBuilder sbFormat = new StringBuilder();
boolean start = false;
int doppieVirgoletteIndex = -1;
boolean startDoppieVirgolette = false;
for (int i = 0; i < name.length(); i++) {
char c = name.charAt(i);
if((!start) && (c == '[')) {
start = true;
if((i+1 < name.length())) {
char cc = name.charAt(i+1);
if((cc == '"')) {
startDoppieVirgolette=true;
doppieVirgoletteIndex=i+1;
}
}
}
if((start) && (c == ']')) {
start = false;
if(!startDoppieVirgolette) {
start = false;
}
}
if((startDoppieVirgolette) && (c == '"') && doppieVirgoletteIndex!=i) {
if((i+1 < name.length())) {
char cc = name.charAt(i+1);
if((cc == ']')) {
startDoppieVirgolette = false;
doppieVirgoletteIndex=i;
}
}
}
if(start && c == '.') {
sbFormat.append('_');
Expand All @@ -558,8 +618,8 @@ private static String readValueInObject(String key, Object o,String name, boolea
// Devo convertire i punti dentro le tonde che potrebbero far parte delle chiavi
sbFormat = new StringBuilder();
start = false;
int doppieVirgoletteIndex = -1;
boolean startDoppieVirgolette = false;
doppieVirgoletteIndex = -1;
startDoppieVirgolette = false;
for (int i = 0; i < newName.length(); i++) {
char c = newName.charAt(i);
if((!start) && (c == '(')) {
Expand All @@ -578,8 +638,13 @@ private static String readValueInObject(String key, Object o,String name, boolea
}
}
if((startDoppieVirgolette) && (c == '"') && doppieVirgoletteIndex!=i) {
startDoppieVirgolette = false;
doppieVirgoletteIndex=i;
if((i+1 < newName.length())) {
char cc = newName.charAt(i+1);
if((cc == ')')) {
startDoppieVirgolette = false;
doppieVirgoletteIndex=i;
}
}
}
if(start && c == '.') {
sbFormat.append('_');
Expand All @@ -599,13 +664,14 @@ private static String readValueInObject(String key, Object o,String name, boolea
//System.out.println("fieldName ["+fieldName+"]");
}
String methodName = new String(fieldName);
//System.out.println("fieldName ["+fieldName+"]");
if(fieldName.endsWith("]") && fieldName.contains("[")){
try{
// fix [][]
//position = fieldName.substring(fieldName.indexOf("[")+1,fieldName.length()-1);
String tmp = new String(fieldName);
//System.out.println("DEBUG ["+tmp+"]");
while(tmp.endsWith("]") && tmp.contains("[")){
while(tmp.endsWith("]") && tmp.contains("[")){
int firstOpen = tmp.indexOf("[")+1;
int lastOpen = tmp.indexOf("]", firstOpen);
String position = tmp.substring(firstOpen, lastOpen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.Scanner;

import org.openspcoop2.utils.Costanti;
import org.openspcoop2.utils.SortedMap;
import org.openspcoop2.utils.UtilsException;
import org.slf4j.Logger;


Expand Down Expand Up @@ -335,4 +337,43 @@ public static Properties convertTextToProperties(String text) {
}
return properties;
}

public static String EMPTY_COMMENT_VALUE = " "; // non uso "" senno su oracle non viene serializzato essendo null
public static SortedMap<String> convertTextToSortedMap(String text) throws UtilsException {
return convertTextToSortedMap(text, false);
}
public static SortedMap<String> convertTextToSortedMap(String text, boolean addCommentAsEntry) throws UtilsException {
Scanner scanner = new Scanner(text);
SortedMap<String> properties = new SortedMap<String>();
try {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if(line==null || line.trim().equals("")) {
continue;
}
line = line.trim();
if(line!=null && line.startsWith("#")) {
if(addCommentAsEntry) {
properties.add(line, EMPTY_COMMENT_VALUE);
}else {
continue;
}
}
if(line.contains("=")) {
String key = line.split("=")[0];
key = key.trim();
int valueIndex = line.indexOf("=");
String value = "";
if(valueIndex<line.length()) {
value = line.substring(valueIndex+1);
value = value.trim();
}
properties.add(key, value);
}
}
}finally {
scanner.close();
}
return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6994,6 +6994,10 @@ public boolean controlloAccessiCheck(TipoOperazione tipoOperazione,
if(line==null || line.trim().equals("")) {
continue;
}
line = line.trim();
if(line!=null && line.startsWith("#")) {
continue;
}
if(line.contains("=")==false) {
this.pd.setMessage(CostantiControlStation.MESSAGGIO_ERRORE_AUTORIZZAZIONE_TOKEN);
return false;
Expand Down Expand Up @@ -7944,6 +7948,10 @@ else if(pa.getAutorizzazioneToken()!=null && pa.getAutorizzazioneToken().getServ
if(line==null || line.trim().equals("")) {
continue;
}
line = line.trim();
if(line!=null && line.startsWith("#")) {
continue;
}
if(line.contains("=")==false) {
this.pd.setMessage(CostantiControlStation.MESSAGGIO_ERRORE_AUTORIZZAZIONE_CONTENUTO_TOKEN_NON_VALIDI);
return false;
Expand Down
Loading

0 comments on commit b0b46da

Please sign in to comment.