fixed problems for authentication-related fields

This commit is contained in:
Maria Teresa Paratore 2024-05-29 13:26:49 +02:00
parent 0f26bd2de3
commit d5533e0b02
7 changed files with 174 additions and 119 deletions

View File

@ -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);

View File

@ -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<String> resourceInstanceMapped(@RequestParam @Nullable String currentContext, @RequestParam String resourceType, @RequestParam String uid) {
log.debug("Request facets fields");
ArrayList<ResourceImplFieldsDTO> facetFields = new ArrayList<ResourceImplFieldsDTO>();
ArrayList<EditFacetDTO> facetEditObjects = new ArrayList<EditFacetDTO>();
ArrayList<String> facetRelations = new ArrayList<>();
ArrayList<String> facetNames = new ArrayList<>();
ArrayList<JSONArray> extraProps = new ArrayList<JSONArray>();
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<String> mapKeys = new ArrayList<String>();
for(int i=0; i<facetNames.size(); i++) {
EditFacetDTO editFacetObj = new EditFacetDTO();
Map<String, Object> targetObj = JsonPath.parse(rawJson).read("$.consistsOf.["+i+"].target");
String fName = facetNames.get(i);
ResourceImplFieldsDTO rif = new ResourceImplFieldsDTO();
rif.setFrname(fName+"_"+facetRelations.get(i));
Map<String, String> 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<EditFieldDTO>());
}
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<String, ArrayList<ArrayList<EditFieldDTO>>> tmpMap = new HashMap<String, ArrayList<ArrayList<EditFieldDTO>>>();
for(EditFacetDTO obj: facetEditObjects) {
if(!tmpMap.containsKey(obj.getFacetCompleteName())) {
ArrayList<ArrayList<EditFieldDTO>> tmpArr2 = new ArrayList<ArrayList<EditFieldDTO>>();
tmpArr2.add(obj.getFacetFields());
tmpMap.put(obj.getFacetCompleteName(), tmpArr2);
}else {
ArrayList<ArrayList<EditFieldDTO>> tmpArr2 = tmpMap.get(obj.getFacetCompleteName());
tmpArr2.add(obj.getFacetFields());
tmpMap.put(obj.getFacetCompleteName(), tmpArr2);
}
}
/*
* public class FieldsPerFacetDTO {
String facetCompleteName;
ArrayList<ArrayList<EditFieldDTO>> fieldsArrays;
*/
ArrayList<FieldsPerFacetDTO> result = new ArrayList<FieldsPerFacetDTO>();
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*************");

View File

@ -7,22 +7,17 @@ import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TypeProperty {
public class TypePropertyUserPassword {
String type;
String schema;
String value;
String user;
/*@Override
public
String toString(){
return this.type+"{\"schema:"+this.schema+",\"value:"+this.value+"}";
TypedValue pwd;
}
*/
@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 + "]";
}
}

View File

@ -49,43 +49,26 @@
<p style="color: darkgrey;">{{prop.label}}</p>
<mat-form-field>
<mat-label for="credentials" >Choose:</mat-label>
<mat-select formControlName="credentials" id="credentials" (selectionChange)="setCredentialType($event)">
<mat-label for="credentialsType" >Choose:</mat-label>
<mat-select formControlName="credentialsType" id="credentialsType" (selectionChange)="setCredentialType($event)">
<mat-option *ngFor="let opt of credentialTypes" [value]="opt">
{{opt}}
</mat-option>
</mat-select>
</mat-form-field>
<div *ngIf="selectedCredentialType === 'username/password'">
<mat-form-field>
<mat-label for="username">username</mat-label>
<input matInput formControlName="username" type="text"/>
<!-- ['username/password', 'clientId/secret', 'token/secret'] -->
<mat-label *ngIf="selectedCredentialType==='username/password'" for="user">username</mat-label>
<mat-label *ngIf="selectedCredentialType==='clientId/secret'" for="user">clientId</mat-label>
<mat-label *ngIf="selectedCredentialType==='token/secret'" for="user">token</mat-label>
<input matInput formControlName="user" type="text"/>
</mat-form-field>
<mat-form-field>
<mat-label for="password">password</mat-label>
<input matInput formControlName="password" type="password"/>
<mat-label *ngIf="selectedCredentialType==='username/password'" for="pwd">password</mat-label>
<mat-label *ngIf="selectedCredentialType==='clientId/secret'" for="pwd">secret</mat-label>
<mat-label *ngIf="selectedCredentialType==='token/secret'" for="pwd">secret</mat-label>
<input matInput formControlName="pwd" type="password"/>
</mat-form-field>
</div>
<div *ngIf="selectedCredentialType === 'client-id/secret'">
<mat-form-field>
<mat-label for="client-id">client-id</mat-label>
<input matInput formControlName="client-id" type="text"/>
</mat-form-field>
<mat-form-field>
<mat-label for="secret">secret</mat-label>
<input matInput formControlName="secret" type="password"/>
</mat-form-field>
</div>
<div *ngIf="selectedCredentialType === 'token/secret'">
<mat-form-field>
<mat-label for="token">token</mat-label>
<input matInput formControlName="token" type="text"/>
</mat-form-field>
<mat-form-field>
<mat-label for="secret">secret</mat-label>
<input matInput formControlName="secret" type="password"/>
</mat-form-field>
</div>
</div>
<ng-template #singlefield>
<mat-form-field>

View File

@ -67,21 +67,6 @@ 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'},
@ -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);
}

View File

@ -12,11 +12,9 @@
</mat-panel-description>
</mat-expansion-panel-header>
<p> {{typeSpec.description}} </p>
<p>{{guiFacetFields|json}}</p>
</mat-expansion-panel>
<div [formGroup]="myForm">
<div formArrayName="{{facetTemplate.key}}" *ngFor="let facetTemplate of fieldsMap|keyvalue;" >
<div [formGroupName] ="ind" *ngFor="let fct of (getSingleFacetArray(facetTemplate.key)).controls; let ind=index;" style="border: 3px solid rgb(72, 157, 202); padding: 10px; margin: 5px;">
<mat-form-field appearance="outline" >

View File

@ -85,19 +85,43 @@ export class FacetEditorComponent implements OnInit {
});
}
/*
createForm(fData:ITypeSpecification):void{
for(let i=0; i<fData.facetSpecs.length; i++){
const facetSpec = fData.facetSpecs[i];
this.createFacetArrayEntry(facetSpec);
}
}
export interface ITypeSpecification{
name:string, //nome tipo
description:string; //descrizione tipo
facetSpecs: IFacetComposer[];
}
*/
createFillForm(fData:ITypeSpecification,fValues: Map<string,IEditFieldObject[][]>):void{
createFillForm(typeSpec:ITypeSpecification,fValues: Map<string,IEditFieldObject[][]>):void{
/*
for(let i=0; i<typeSpec.facetSpecs.length; i++){
const facetSpec = typeSpec.facetSpecs[i];
this.createFacetArrayEntry(facetSpec);
}
*/
fValues.forEach((val,key) =>{
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; i<facetFieldsArrays.length ; i++){
/*
const facetCount = facetFieldsArrays.length; //num di facet dello stesso tipo
if(facetCount===1){
this.createFacetArrayEntry(<IFacetComposer>this.fieldsMap.get(key),fieldsArrays[0]);
this.createFacetArrayEntry(<IFacetComposer>this.fieldsMap.get(key),facetFieldsArrays[0]);
}else{
for(let i=0; i<facetCount; i++){
this.addAndFillFacet(key,fieldsArrays[i]); //aggiungo elemento
this.addAndFillFacet(key,facetFieldsArrays[i]); //aggiungo elemento
}
*/
}
});
@ -160,7 +184,9 @@ export class FacetEditorComponent implements OnInit {
}
createFacetGroup(item: IFacetComposer,isAdded: boolean,fieldValues:IEditFieldObject[]|null):FormGroup{
console.debug('------>>>> 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<props.length; i++){
const prop=props[i];
for(let j=0; j<fieldValues.length; j++){
console.debug('+++++++++++++ fieldValues[j].fieldKey...'+fieldValues[j].fieldKey);
console.debug('+++++++++++++ fieldValues[j].fieldValue...'+fieldValues[j].fieldValue);
if(prop.name === fieldValues[j].fieldKey){
if(prop.name === fieldValues[j].fieldKey){
console.debug('+++++++++++++ fieldValues[j].Key/Value/type...'+fieldValues[j].fieldKey+' / '+fieldValues[j].fieldValue+
' / '+prop.type);
// this.assignValueToControl(prop.type, fieldValues[j].fieldValue);
if(prop.type==="date"){
//2024-03-25 14:24:35.934 +0100
const dateValue = Date.parse(fieldValues[j].fieldValue)
if(fieldValues[j].fieldValue){
fc = this.fb.control(fieldValues[j].fieldValue)
fc = this.fb.control(dateValue);
}else{
fc = this.fb.control(new Date())
fc = this.fb.control(new Date());
console.debug('VUOTO');
}
}
if(prop.type==="number"){
if(fieldValues[j].fieldValue){
fc = this.fb.control(fieldValues[j].fieldValue)
const numValue = +fieldValues[j].fieldValue;
fc = this.fb.control(numValue);
}else{
fc = this.fb.control(0)
fc = this.fb.control(0);
console.debug('VUOTO');
}
}
if(prop.type==="boolean"){
if(fieldValues[j].fieldValue){
fc = this.fb.control(fieldValues[j].fieldValue)
const boolValue = (fieldValues[j].fieldValue.toLowerCase() === 'true');
fc = this.fb.control(boolValue);
}else{
fc = this.fb.control(true)
console.debug('VUOTO');
}
}
//TODO: per ora trattiamo questo tipo come stringa
if(prop.type==="typegroup"){
if(fieldValues[j].fieldValue){
fc = this.fb.control(fieldValues[j].fieldValue);
}else{
fc = this.fb.control('');
console.debug('VUOTO');
}
}
else{
@ -269,17 +312,26 @@ export class FacetEditorComponent implements OnInit {
}
}
}
if(prop.type==="typeprop"){ //TODO: forse va messo il controllo anche sul tipo di facet
let fc2:FormControl;
propsFg.addControl("schema",fc);
// eslint-disable-next-line prefer-const
fc2 = this.fb.control('') //text or typeprop
propsFg.addControl("value",fc2);
}else{
propsFg.addControl(prop.name,fc); //formGroup.addControl(prop_'controlName', formControl);
}
}
propsFg.addControl(prop.name,fc); //formGroup.addControl(prop_'controlName', formControl);
//TODO: check this
/*
if(prop.type==="typeprop"){ //nel caso di typeprop vanno aggiunti campi!! (ad es, value e schema)
console.debug('+++++++++++++ typeprop +++++');
let fc2:FormControl;
propsFg.addControl("schema",fc);
// eslint-disable-next-line prefer-const
fc2 = this.fb.control('') //text or typeprop
propsFg.addControl("value",fc2);
}else{
propsFg.addControl(prop.name,fc); //formGroup.addControl(prop_'controlName', formControl);
}
*/
}
//TODO: else? if(prop.name !== fieldValues[j].fieldKey){
//extraprops?
}
}
@ -288,6 +340,11 @@ export class FacetEditorComponent implements OnInit {
return facetFg;
}
/*
assignValueToControl():void{
}
*/
stringToBoolean(str: string): boolean {
return str.toLowerCase() as unknown as boolean;