Skip to content
Snippets Groups Projects
Commit 9d0833a8 authored by root's avatar root
Browse files

Include the functionality for read dataset info

parent 03596c12
No related branches found
No related tags found
No related merge requests found
...@@ -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,18 +134,10 @@ public class PolicyService { ...@@ -133,18 +134,10 @@ 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}
// boolean result= this.checkParameter("continent", "Continent", organizationAttributesAsString, accessPolicyasString);
try{ try{
organizationAttributesJson = new JSONObject(organizationAttributesAsString); organizationAttributesJson = new JSONObject(organizationAttributesAsString);
...@@ -184,6 +177,7 @@ public class PolicyService { ...@@ -184,6 +177,7 @@ public class PolicyService {
System.out.println("Error"); System.out.println("Error");
} }
boolean result=false; boolean result=false;
boolean bFind=false;
String orgKey=""; String orgKey="";
String policyKey=""; String policyKey="";
String sNonConformities=""; String sNonConformities="";
...@@ -202,15 +196,16 @@ public class PolicyService { ...@@ -202,15 +196,16 @@ public class PolicyService {
if (lowerOrgKey.equals(lowerPolicyKey)){ if (lowerOrgKey.equals(lowerPolicyKey)){
result= this.checkParameter(orgKey, policyKey, organizationAttributesJson, accessPolicyAsJSON); result= this.checkParameter(orgKey, policyKey, organizationAttributesJson, accessPolicyAsJSON);
System.out.println(result); System.out.println(result);
bFind=true;
break; break;
} }
} }
// policyKeys.next();
if (!result){
sNonConformities+="Organization key: "+ orgKey + " value not the same as policy key: "+ policyKey + " value.\n"; if ((!result)&&(bFind)){
sNonConformities+=" Organization key: "+ orgKey + " value not the same as policy key: "+ policyKey + " value.";
} }
...@@ -224,29 +219,9 @@ public class PolicyService { ...@@ -224,29 +219,9 @@ public class PolicyService {
} }
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,28 +229,43 @@ public class PolicyService { ...@@ -254,28 +229,43 @@ public class PolicyService {
boolean result=false; boolean result=false;
try{
String sOrgValue=organizationAttributesJson.getString(parameterOrg);
String sOrgValue="";
int iOrgValue=-1;
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment