Commit 9d0833a8 authored by root's avatar root
Browse files

Include the functionality for read dataset info

parent 03596c12
...@@ -67,7 +67,7 @@ public class GetAccessApiController implements GetAccessApi { ...@@ -67,7 +67,7 @@ public class GetAccessApiController implements GetAccessApi {
*/ */
String organizationAttributesAsString=policyService.getDataSeekersOrganizationPolicy(dataSeekerID); String organizationAttributesAsString=policyService.getDataSeekersOrganizationPolicy(dataSeekerID);
organizationAttributesAsString="{\"name\":\"Test Organization\",\"sector\":\"Test Sector\",\"continent\":\"EU\",\"country\":\"GRE\",\"type\":\"Private Entity\",\"size\":\"medium\",\"reputation\":\"7\"}"; organizationAttributesAsString="{\"name\":\"Test Organization\",\"sector\":\"Test Sector\",\"continent\":\"EU\",\"country\":\"GRE\",\"type\":\"Private Entity\",\"size\":\"medium\",\"reputation\":7}";
System.out.println("organizationAttributesAsString:"+organizationAttributesAsString); System.out.println("organizationAttributesAsString:"+organizationAttributesAsString);
......
...@@ -47,8 +47,8 @@ public class PolicyService { ...@@ -47,8 +47,8 @@ public class PolicyService {
private String authClientSecret = ""; private String authClientSecret = "";
@Value("${datavaults.auth.grant.type}") @Value("${datavaults.auth.grant.type}")
private String authGrantType = ""; private String authGrantType = "";
@Value("${datavaults.auth.username}") /* @Value("${datavaults.auth.username}")
private String authUsername = ""; private String authUsername = "";*/
@Value("${datavaults.auth.password}") @Value("${datavaults.auth.password}")
private String authPassword = ""; private String authPassword = "";
...@@ -75,7 +75,8 @@ public class PolicyService { ...@@ -75,7 +75,8 @@ public class PolicyService {
organizationAttributesAsString =httpUtils.sendHttpPostRequestWithOAuth(datavaultsUrl,authServerUrl,authClientId,authClientSecret,authGrantType,authUsername,authPassword); // organizationAttributesAsString =httpUtils.sendHttpPostRequestWithOAuth(datavaultsUrl,authServerUrl,authClientId,authClientSecret,authGrantType,authUsername,authPassword);
organizationAttributesAsString =httpUtils.sendHttpPostRequestWithOAuth(datavaultsUrl,authServerUrl,authClientId,authClientSecret,authGrantType,dataSeekerId,authPassword);
} catch (Exception e) { } catch (Exception e) {
...@@ -133,119 +134,93 @@ public class PolicyService { ...@@ -133,119 +134,93 @@ public class PolicyService {
JSONObject accessPolicyAsJSON = null; JSONObject accessPolicyAsJSON = null;
//Example //Example
//organizationAttributesAsString:{"name":"Test Organization","sector":"Test Sector","continent":"EU","country":"GRE","type":"Private Entity","size":"medium","reputation":"7"} //organizationAttributesAsString:{"name":"Test Organization","sector":"Test Sector","continent":"EU","country":"GRE","type":"Private Entity","size":"medium","reputation":7}
//accessPolicyasString:{"Continent":["testContinent","test2Continent"],"Type":["testType","test2Type"],"Sector":["testSector","test2Sector"],"Size":["testSize","test2Size"],"Country":["testCountry","test2Country"],"Reputation":11} //accessPolicyasString:{"Continent":["testContinent","test2Continent"],"Type":["testType","test2Type"],"Sector":["testSector","test2Sector"],"Size":["testSize","test2Size"],"Country":["testCountry","test2Country"],"Reputation":11}
try{
organizationAttributesJson = new JSONObject(organizationAttributesAsString);
// boolean result= this.checkParameter("continent", "Continent", organizationAttributesAsString, accessPolicyasString); orgKeys = organizationAttributesJson.keys();
/* String sContinent=organizationAttributesJson.getString("continent");
String sCountry=organizationAttributesJson.getString("country");
String sSector=organizationAttributesJson.getString("sector");
try{ String sType=organizationAttributesJson.getString("type");
organizationAttributesJson = new JSONObject(organizationAttributesAsString); String sSize=organizationAttributesJson.getString("size");
String sReputation=organizationAttributesJson.getString("reputation");*/
orgKeys = organizationAttributesJson.keys();
System.out.println(organizationAttributesJson.toString());
/* String sContinent=organizationAttributesJson.getString("continent"); //sector,continent,country,type,size,reputation
String sCountry=organizationAttributesJson.getString("country"); }
String sSector=organizationAttributesJson.getString("sector"); catch(Exception e){
String sType=organizationAttributesJson.getString("type"); System.out.println("Error");
String sSize=organizationAttributesJson.getString("size"); }
String sReputation=organizationAttributesJson.getString("reputation");*/
System.out.println(organizationAttributesJson.toString());
//sector,continent,country,type,size,reputation
}
catch(Exception e){
System.out.println("Error");
}
try{ try{
accessPolicyAsJSON = new JSONObject(accessPolicyasString); accessPolicyAsJSON = new JSONObject(accessPolicyasString);
//policyKeys=accessPolicyAsJSON.keys(); //policyKeys=accessPolicyAsJSON.keys();
/* JSONArray jArrayContinent=accessPolicyAsJSON.getJSONArray("Continent"); /* JSONArray jArrayContinent=accessPolicyAsJSON.getJSONArray("Continent");
JSONArray jArrayCountry=accessPolicyAsJSON.getJSONArray("Country JSONArray jArrayCountry=accessPolicyAsJSON.getJSONArray("Country
JSONArray jArraySector=accessPolicyAsJSON.getJSONArray("Sector"); JSONArray jArraySector=accessPolicyAsJSON.getJSONArray("Sector");
JSONArray jArrayType=accessPolicyAsJSON.getJSONArray("Type"); JSONArray jArrayType=accessPolicyAsJSON.getJSONArray("Type");
JSONArray jArraySize=accessPolicyAsJSON.getJSONArray("Size"); JSONArray jArraySize=accessPolicyAsJSON.getJSONArray("Size");
JSONArray jArrayReputation=accessPolicyAsJSON.getJSONArray("Reputation");*/ JSONArray jArrayReputation=accessPolicyAsJSON.getJSONArray("Reputation");*/
System.out.println(accessPolicyAsJSON.toString()); System.out.println(accessPolicyAsJSON.toString());
}
catch(Exception e){
System.out.println("Error");
}
boolean result=false;
boolean bFind=false;
String orgKey="";
String policyKey="";
String sNonConformities="";
while (orgKeys.hasNext()) {
orgKey = orgKeys.next();
System.out.println("Key organization:"+orgKey);
String lowerOrgKey=orgKey.toLowerCase();
policyKeys=accessPolicyAsJSON.keys();
while (policyKeys.hasNext()) {
policyKey = policyKeys.next();
System.out.println("Key policy:"+policyKey);
String lowerPolicyKey=policyKey.toLowerCase();
if (lowerOrgKey.equals(lowerPolicyKey)){
result= this.checkParameter(orgKey, policyKey, organizationAttributesJson, accessPolicyAsJSON);
System.out.println(result);
bFind=true;
break;
}
} }
catch(Exception e){
System.out.println("Error");
if ((!result)&&(bFind)){
sNonConformities+=" Organization key: "+ orgKey + " value not the same as policy key: "+ policyKey + " value.";
} }
boolean result=false;
String orgKey="";
String policyKey="";
String sNonConformities="";
while (orgKeys.hasNext()) {
orgKey = orgKeys.next();
System.out.println("Key organization:"+orgKey);
String lowerOrgKey=orgKey.toLowerCase();
policyKeys=accessPolicyAsJSON.keys();
while (policyKeys.hasNext()) {
policyKey = policyKeys.next();
System.out.println("Key policy:"+policyKey);
String lowerPolicyKey=policyKey.toLowerCase();
if (lowerOrgKey.equals(lowerPolicyKey)){
result= this.checkParameter(orgKey, policyKey, organizationAttributesJson, accessPolicyAsJSON);
System.out.println(result);
break;
}
}
// policyKeys.next();
if (!result){
sNonConformities+="Organization key: "+ orgKey + " value not the same as policy key: "+ policyKey + " value.\n";
}
} }
access.setDatasetID(datasetID); access.setDatasetID(datasetID);
if (sNonConformities.equals("")){ if (sNonConformities.equals("")){
access.setGranted(true); access.setGranted(true);
} }
else access.setGranted(false); else access.setGranted(false);
access.setNonConformities(sNonConformities); access.setNonConformities(sNonConformities);
// boolean result= this.checkParameter("continent", "Continent", organizationAttributesJson, accessPolicyAsJSON);
//check if any value in policy is same of the organization, if everything is on policy return true in granted value and conformities string is empty //check if any value in policy is same of the organization, if everything is on policy return true in granted value and conformities string is empty
//if one of the value is not the same return false and construct non conformities string //if one of the value is not the same return false and construct non conformities string
return access; return access;
} }
...@@ -254,26 +229,41 @@ public class PolicyService { ...@@ -254,26 +229,41 @@ public class PolicyService {
boolean result=false; boolean result=false;
try{
String sOrgValue="";
int iOrgValue=-1;
String sOrgValue=organizationAttributesJson.getString(parameterOrg); try{
sOrgValue=organizationAttributesJson.getString(parameterOrg);
System.out.println("Value for organization:"+sOrgValue); System.out.println("Value for organization:"+sOrgValue);
// sOrgValue="testContinent"; }
catch(Exception e){
iOrgValue=organizationAttributesJson.getInt(parameterOrg);
System.out.println("Value for organization:"+iOrgValue);
}
try{
JSONArray jArray=accessPolicyAsJSON.getJSONArray(parameterPolicy); JSONArray jArray=accessPolicyAsJSON.getJSONArray(parameterPolicy);
if (jArray.toString().contains(sOrgValue)) if (jArray.toString().contains(sOrgValue)){
result=true; result=true;
System.out.println("Is the same value?:"+result); System.out.println("Is the same value?:"+result);
}
} }
catch(Exception e){ catch(Exception e){
int iValue=accessPolicyAsJSON.getInt(parameterPolicy);
if (iValue==iOrgValue){
result=true;
System.out.println("Is the same value?:"+result);
}
} }
return result; return result;
......
...@@ -15,5 +15,5 @@ datavaults.auth.server.url=https://datavaults-auth.euprojects.net/auth/realms/pl ...@@ -15,5 +15,5 @@ datavaults.auth.server.url=https://datavaults-auth.euprojects.net/auth/realms/pl
datavaults.auth.client.id=backend-service datavaults.auth.client.id=backend-service
datavaults.auth.client.secret=04892d79-f600-4410-a9ac-6860aa5bdf3e datavaults.auth.client.secret=04892d79-f600-4410-a9ac-6860aa5bdf3e
datavaults.auth.grant.type=password datavaults.auth.grant.type=password
datavaults.auth.username=trainer #datavaults.auth.username=trainer
datavaults.auth.password=3 datavaults.auth.password=3
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment