From d5533e0b026c64f70d25a07eb5914650bbd83251 Mon Sep 17 00:00:00 2001 From: mariateresa Date: Wed, 29 May 2024 13:26:49 +0200 Subject: [PATCH] fixed problems for authentication-related fields --- .../service/InformationSystemService.java | 26 ++-- .../web/rest/InformationSystemResource.java | 63 ++++++++-- .../web/rest/TypePropertyUserPassword.java | 19 ++- .../facet-composer.component.html | 39 ++---- .../facet-composer.component.ts | 33 +----- .../facet-editor/facet-editor.component.html | 2 - .../facet-editor/facet-editor.component.ts | 111 +++++++++++++----- 7 files changed, 174 insertions(+), 119 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/service/InformationSystemService.java b/src/main/java/org/gcube/informationsystem/service/InformationSystemService.java index e3f63cc..763883d 100644 --- a/src/main/java/org/gcube/informationsystem/service/InformationSystemService.java +++ b/src/main/java/org/gcube/informationsystem/service/InformationSystemService.java @@ -39,7 +39,8 @@ import org.gcube.informationsystem.types.reference.properties.PropertyDefinition import org.gcube.informationsystem.utils.UUIDUtility; import org.gcube.informationsystem.web.rest.FacetDescription; import org.gcube.informationsystem.web.rest.ResourceDescription; -import org.gcube.informationsystem.web.rest.TypeProperty; +import org.gcube.informationsystem.web.rest.TypePropertyUserPassword; +import org.gcube.informationsystem.web.rest.TypedValue; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -475,14 +476,21 @@ public class InformationSystemService { } //modifica per tipo ValueSchema e campo authorization - if (facetName_i.equals("AccessPointFacet")&& propMap_i.keySet().contains("schema")&& propMap_i.keySet().contains("value")) { - TypeProperty vs = new TypeProperty(); - vs.setType("ValueSchema"); - vs.setSchema((String)targetMap_i.get("schema")); - vs.setValue((String)targetMap_i.get("value")); - targetMap_i.put("authorization", vs); - targetMap_i.remove("schema"); - targetMap_i.remove("value"); + + if (facetName_i.equals("AccessPointFacet")){ + if(propMap_i.keySet().contains("user") && propMap_i.keySet().contains("pwd")){ + TypePropertyUserPassword tp = new TypePropertyUserPassword(); + tp.setType("GCubeProperty"); + tp.setUser((String)targetMap_i.get("user")); + TypedValue ecriptedVal = new TypedValue(); + ecriptedVal.setTypeName("Encrypted"); + ecriptedVal.setValue((String)targetMap_i.get("pwd")); + tp.setPwd(ecriptedVal); + targetMap_i.put("authorization", tp); + targetMap_i.remove("pwd"); + targetMap_i.remove("user"); + } + } JSONArray extra_joProps_i = (JSONArray)extraProps.get(i); diff --git a/src/main/java/org/gcube/informationsystem/web/rest/InformationSystemResource.java b/src/main/java/org/gcube/informationsystem/web/rest/InformationSystemResource.java index 5590602..9df85d7 100644 --- a/src/main/java/org/gcube/informationsystem/web/rest/InformationSystemResource.java +++ b/src/main/java/org/gcube/informationsystem/web/rest/InformationSystemResource.java @@ -25,8 +25,11 @@ import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPu import org.gcube.informationsystem.serialization.ElementMapper; import org.gcube.informationsystem.service.InformationSystemService; import org.gcube.informationsystem.service.dto.ContextDTO; +import org.gcube.informationsystem.service.dto.EditFacetDTO; +import org.gcube.informationsystem.service.dto.EditFieldDTO; import org.gcube.informationsystem.service.dto.FacetSpecDTO; import org.gcube.informationsystem.service.dto.FacetTypeDTO; +import org.gcube.informationsystem.service.dto.FieldsPerFacetDTO; import org.gcube.informationsystem.service.dto.ResourceBuilderDTO; import org.gcube.informationsystem.service.dto.ResourceImplFieldsDTO; import org.gcube.informationsystem.service.dto.ResourceTypeDTO; @@ -192,49 +195,83 @@ public class InformationSystemResource{ @GetMapping("/facetfields") public ResponseEntity resourceInstanceMapped(@RequestParam @Nullable String currentContext, @RequestParam String resourceType, @RequestParam String uid) { log.debug("Request facets fields"); - ArrayList facetFields = new ArrayList(); + + ArrayList facetEditObjects = new ArrayList(); + ArrayList facetRelations = new ArrayList<>(); ArrayList facetNames = new ArrayList<>(); - ArrayList extraProps = new ArrayList(); try { String currentCtx = SecretManagerProvider.instance.get().getContext(); ResourceRegistryClient resourceRegistryClient= ResourceRegistryClientFactory.create(currentCtx); informationSystemService.setUma(createUmaToken(currentContext)); String rawJson = informationSystemService.getResource(resourceType, uid); - //TODO: qui spacchetta con Jsonpath - //String sc = rawJson; facetRelations = JsonPath.parse(rawJson).read("$..consistsOf.*.type"); facetNames = JsonPath.parse(rawJson).read("$..consistsOf.*.target.type"); - - // ArrayList mapKeys = new ArrayList(); for(int i=0; i targetObj = JsonPath.parse(rawJson).read("$.consistsOf.["+i+"].target"); String fName = facetNames.get(i); - ResourceImplFieldsDTO rif = new ResourceImplFieldsDTO(); - rif.setFrname(fName+"_"+facetRelations.get(i)); - Map facetProps = new HashMap<>(); String jsonFacetDesc = resourceRegistryClient.getType(fName, true); Type type = TypeMapper.deserializeTypeDefinitions(jsonFacetDesc).get(0); //only one result FacetType ft = (FacetType) type; if(ft.getProperties()!=null ) { for(PropertyDefinition pd:ft.getProperties() ) { try { + EditFieldDTO propObj = new EditFieldDTO(); String propName = pd.getName(); String propValue = ""; if(targetObj.get(propName)!=null) { propValue = targetObj.get(propName).toString(); } - facetProps.put(propName, propValue); + propObj.setFieldKey(propName); + propObj.setFieldValue(propValue); + if(editFacetObj.getFacetFields()==null) { + editFacetObj.setFacetFields(new ArrayList()); + } + editFacetObj.getFacetFields().add(propObj); }catch(Exception e) { e.printStackTrace(); } } } - rif.setProperties(facetProps); - facetFields.add(rif); + editFacetObj.setFacetName(fName); + editFacetObj.setFacetRelation(facetRelations.get(i)); + editFacetObj.setFacetCompleteName(fName+"_"+facetRelations.get(i)); + + facetEditObjects.add(editFacetObj); } + //accorpo: + + Map>> tmpMap = new HashMap>>(); + + for(EditFacetDTO obj: facetEditObjects) { + if(!tmpMap.containsKey(obj.getFacetCompleteName())) { + ArrayList> tmpArr2 = new ArrayList>(); + tmpArr2.add(obj.getFacetFields()); + tmpMap.put(obj.getFacetCompleteName(), tmpArr2); + }else { + ArrayList> tmpArr2 = tmpMap.get(obj.getFacetCompleteName()); + tmpArr2.add(obj.getFacetFields()); + tmpMap.put(obj.getFacetCompleteName(), tmpArr2); + } + } + /* + * public class FieldsPerFacetDTO { + + String facetCompleteName; + ArrayList> fieldsArrays; + */ + + ArrayList result = new ArrayList(); + for(String key:tmpMap.keySet()) { + FieldsPerFacetDTO fpf = new FieldsPerFacetDTO(); + fpf.setFacetCompleteName(key); + fpf.setFieldsArrays(tmpMap.get(key)); + result.add(fpf); + } + ObjectMapper om = new ObjectMapper(); - String json = om.writeValueAsString(facetFields); + String json = om.writeValueAsString(result); return ResponseEntity.ok().body(json); } catch (Exception e) { log.error("****ERROR*************"); diff --git a/src/main/java/org/gcube/informationsystem/web/rest/TypePropertyUserPassword.java b/src/main/java/org/gcube/informationsystem/web/rest/TypePropertyUserPassword.java index 4e35164..1baeccb 100644 --- a/src/main/java/org/gcube/informationsystem/web/rest/TypePropertyUserPassword.java +++ b/src/main/java/org/gcube/informationsystem/web/rest/TypePropertyUserPassword.java @@ -7,22 +7,17 @@ import lombok.NoArgsConstructor; @Data @AllArgsConstructor @NoArgsConstructor -public class TypeProperty { +public class TypePropertyUserPassword { String type; - String schema; - String value; + String user; + + TypedValue pwd; - /*@Override - public - String toString(){ - return this.type+"{\"schema:"+this.schema+",\"value:"+this.value+"}"; - - } - */ @Override public String toString() { // TODO Auto-generated method stub - return "\"TypeProperty [type "+ type + ", schema = " + schema + ", value = " + value + "]"; + //return "\"TypeProperty [type "+ type + ", pwd = " + pwd + ", uname = " + uname + "]"; + return "\"TypeProperty [type "+ type + ", pwd = " + pwd + ", user = " + user + "]"; } -} +} \ No newline at end of file diff --git a/src/main/webapp/app/facet-composer/facet-composer.component.html b/src/main/webapp/app/facet-composer/facet-composer.component.html index 0fee660..e99eae2 100644 --- a/src/main/webapp/app/facet-composer/facet-composer.component.html +++ b/src/main/webapp/app/facet-composer/facet-composer.component.html @@ -49,43 +49,26 @@

{{prop.label}}

- Choose: - + Choose: + {{opt}} -
- username - + + username + clientId + token + - password - + password + secret + secret + -
-
- - client-id - - - - secret - - -
-
- - token - - - - secret - - -
diff --git a/src/main/webapp/app/facet-composer/facet-composer.component.ts b/src/main/webapp/app/facet-composer/facet-composer.component.ts index 45a2ee1..c36d218 100644 --- a/src/main/webapp/app/facet-composer/facet-composer.component.ts +++ b/src/main/webapp/app/facet-composer/facet-composer.component.ts @@ -67,22 +67,7 @@ export class FacetComposerComponent implements OnInit { } - /* - //TODO: A REGIME LA TENDINA DOVRA' NESSERE RIEMPITA SECONDO QUESTO CRITERIO - //(LATO JAVA, VIA CHIAMATA A SERVIZIO) - if( PropertyTypeName.BaseType.BOOLEAN.ordinal() - BaseType.PROPERTY.ordinal()) { - // Tipi Base - } - - PropertyTypeName ptn = new PropertyTypeName("ValueSchema"); - ptn.getBaseType(); - if(ptn.isGenericType()){ - ptn.getGenericBaseType(); - ptn.getGenericClassName(); - } - */ - + optionTypes = [ { value: 'Boolean'}, { value: 'Date'}, @@ -93,11 +78,8 @@ export class FacetComposerComponent implements OnInit { ]; - credentialTypes: string[] = ['username/password', 'client-id/secret', 'token/secret']; + credentialTypes: string[] = ['username/password', 'clientId/secret', 'token/secret']; - onCredentialChoose(): void { - console.debug('******onOptionsSelected?...'+this.selectedType); - } //TODO: NOTA BENE--> FormGroup->access by NAME, FormArray->access by INDEX!! createForm(fData:ITypeSpecification):void{ @@ -191,7 +173,6 @@ export class FacetComposerComponent implements OnInit { setCredentialType(opt:any){ this.selectedCredentialType = opt.value; - console.debug("*******CAMBIATO: "+opt.value); } @@ -225,13 +206,9 @@ export class FacetComposerComponent implements OnInit { } } if(prop.type==="typeprop"){ - propsFg.addControl("credentials",this.fb.control('',Validators.required)); - propsFg.addControl("username",this.fb.control('',Validators.required)); - propsFg.addControl("password",this.fb.control('',Validators.required)); - propsFg.addControl("client-id",this.fb.control('',Validators.required)); - propsFg.addControl("secret",this.fb.control('',Validators.required)); - propsFg.addControl("token",this.fb.control('',Validators.required)); - propsFg.addControl("secret",this.fb.control('',Validators.required)); + propsFg.addControl("credentialsType",this.fb.control('')); + propsFg.addControl("user",this.fb.control('')); + propsFg.addControl("pwd",this.fb.control('')); }else{ propsFg.addControl(prop.name,fc); //formGroup.addControl(prop_'controlName', formControl); } diff --git a/src/main/webapp/app/facet-editor/facet-editor.component.html b/src/main/webapp/app/facet-editor/facet-editor.component.html index 30378d7..4ce51dd 100644 --- a/src/main/webapp/app/facet-editor/facet-editor.component.html +++ b/src/main/webapp/app/facet-editor/facet-editor.component.html @@ -12,11 +12,9 @@

{{typeSpec.description}}

-

{{guiFacetFields|json}}

-
diff --git a/src/main/webapp/app/facet-editor/facet-editor.component.ts b/src/main/webapp/app/facet-editor/facet-editor.component.ts index a69b01f..89c7920 100644 --- a/src/main/webapp/app/facet-editor/facet-editor.component.ts +++ b/src/main/webapp/app/facet-editor/facet-editor.component.ts @@ -85,21 +85,45 @@ export class FacetEditorComponent implements OnInit { }); } - - - createFillForm(fData:ITypeSpecification,fValues: Map):void{ + /* + createForm(fData:ITypeSpecification):void{ + for(let i=0; i):void{ + /* + for(let i=0; i{ - const fieldsArrays:IEditFieldObject[][] = fValues.get(key)!; - const facetCount = fieldsArrays.length; //num di facet dello stesso tipo + const facetFieldsArrays:IEditFieldObject[][] = fValues.get(key)!; + for(let i=0; ithis.fieldsMap.get(key),fieldsArrays[0]); + this.createFacetArrayEntry(this.fieldsMap.get(key),facetFieldsArrays[0]); }else{ for(let i=0; i>>> Creating Group for facet: '+item.name); const facetFg: FormGroup = this.fb.group({}); + console.debug(); const nameFc = this.fb.control(item.name); facetFg.addControl('facetName', nameFc); @@ -181,7 +207,7 @@ export class FacetEditorComponent implements OnInit { facetFg.addControl('extraProps', this.extraProps); //TODO: PASSARE I VALORI - return this.addPropertyControls(facetFg,item.guiProps,fieldValues); + return this.addPropertyControls(facetFg,item.guiProps,fieldValues); } @@ -231,29 +257,46 @@ export class FacetEditorComponent implements OnInit { for(let i=0; i