Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Iturraspe Barturen, Urtza
PolicyEngine
Commits
9d0833a8
Commit
9d0833a8
authored
Sep 06, 2021
by
root
Browse files
Include the functionality for read dataset info
parent
03596c12
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/tecnalia/DVPolicyEngine/api/GetAccessApiController.java
View file @
9d0833a8
...
...
@@ -67,7 +67,7 @@ public class GetAccessApiController implements GetAccessApi {
*/
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
);
...
...
src/main/java/com/tecnalia/DVPolicyEngine/service/PolicyService.java
View file @
9d0833a8
...
...
@@ -47,8 +47,8 @@ public class PolicyService {
private
String
authClientSecret
=
""
;
@Value
(
"${datavaults.auth.grant.type}"
)
private
String
authGrantType
=
""
;
@Value
(
"${datavaults.auth.username}"
)
private
String
authUsername
=
""
;
/*
@Value("${datavaults.auth.username}")
private String authUsername = "";
*/
@Value
(
"${datavaults.auth.password}"
)
private
String
authPassword
=
""
;
...
...
@@ -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
)
{
...
...
@@ -133,119 +134,93 @@ public class PolicyService {
JSONObject
accessPolicyAsJSON
=
null
;
//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}
// boolean result= this.checkParameter("continent", "Continent", organizationAttributesAsString, accessPolicyasString);
try
{
organizationAttributesJson
=
new
JSONObject
(
organizationAttributesAsString
);
orgKeys
=
organizationAttributesJson
.
keys
();
/* String sContinent=organizationAttributesJson.getString("continent");
String sCountry=organizationAttributesJson.getString("country");
String sSector=organizationAttributesJson.getString("sector");
String sType=organizationAttributesJson.getString("type");
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
{
organizationAttributesJson
=
new
JSONObject
(
organizationAttributesAsString
);
orgKeys
=
organizationAttributesJson
.
keys
();
/* String sContinent=organizationAttributesJson.getString("continent");
String sCountry=organizationAttributesJson.getString("country");
String sSector=organizationAttributesJson.getString("sector");
String sType=organizationAttributesJson.getString("type");
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
{
accessPolicyAsJSON
=
new
JSONObject
(
accessPolicyasString
);
//policyKeys=accessPolicyAsJSON.keys();
/* JSONArray jArrayContinent=accessPolicyAsJSON.getJSONArray("Continent");
JSONArray jArrayCountry=accessPolicyAsJSON.getJSONArray("Country
JSONArray jArraySector=accessPolicyAsJSON.getJSONArray("Sector");
JSONArray jArrayType=accessPolicyAsJSON.getJSONArray("Type");
JSONArray jArraySize=accessPolicyAsJSON.getJSONArray("Size");
JSONArray jArrayReputation=accessPolicyAsJSON.getJSONArray("Reputation");*/
System
.
out
.
println
(
accessPolicyAsJSON
.
toString
());
try
{
accessPolicyAsJSON
=
new
JSONObject
(
accessPolicyasString
);
//policyKeys=accessPolicyAsJSON.keys();
/* JSONArray jArrayContinent=accessPolicyAsJSON.getJSONArray("Continent");
JSONArray jArrayCountry=accessPolicyAsJSON.getJSONArray("Country
JSONArray jArraySector=accessPolicyAsJSON.getJSONArray("Sector");
JSONArray jArrayType=accessPolicyAsJSON.getJSONArray("Type");
JSONArray jArraySize=accessPolicyAsJSON.getJSONArray("Size");
JSONArray jArrayReputation=accessPolicyAsJSON.getJSONArray("Reputation");*/
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
);
if
(
sNonConformities
.
equals
(
""
)){
access
.
setGranted
(
true
);
}
else
access
.
setGranted
(
false
);
access
.
setNonConformities
(
sNonConformities
);
// boolean result= this.checkParameter("continent", "Continent", organizationAttributesJson, accessPolicyAsJSON);
}
access
.
setDatasetID
(
datasetID
);
if
(
sNonConformities
.
equals
(
""
)){
access
.
setGranted
(
true
);
}
else
access
.
setGranted
(
false
);
access
.
setNonConformities
(
sNonConformities
);
//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
return
access
;
}
...
...
@@ -254,26 +229,41 @@ public class PolicyService {
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
);
// sOrgValue="testContinent";
}
catch
(
Exception
e
){
iOrgValue
=
organizationAttributesJson
.
getInt
(
parameterOrg
);
System
.
out
.
println
(
"Value for organization:"
+
iOrgValue
);
}
try
{
JSONArray
jArray
=
accessPolicyAsJSON
.
getJSONArray
(
parameterPolicy
);
if
(
jArray
.
toString
().
contains
(
sOrgValue
))
if
(
jArray
.
toString
().
contains
(
sOrgValue
))
{
result
=
true
;
System
.
out
.
println
(
"Is the same value?:"
+
result
);
}
}
catch
(
Exception
e
){
int
iValue
=
accessPolicyAsJSON
.
getInt
(
parameterPolicy
);
if
(
iValue
==
iOrgValue
){
result
=
true
;
System
.
out
.
println
(
"Is the same value?:"
+
result
);
}
}
return
result
;
...
...
src/main/resources/application.properties
View file @
9d0833a8
...
...
@@ -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.secret
=
04892d79-f600-4410-a9ac-6860aa5bdf3e
datavaults.auth.grant.type
=
password
datavaults.auth.username
=
trainer
#
datavaults.auth.username=trainer
datavaults.auth.password
=
3
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment