Skip to content

Commit 1bcc048

Browse files
committed
Merge develop into master for release
2 parents 6c1222d + e073469 commit 1bcc048

17 files changed

Lines changed: 67 additions & 23 deletions

File tree

actions/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>io.em2m.sdk</groupId>
2727
<artifactId>em2m-java-sdk-pom</artifactId>
28-
<version>2.91.0</version>
28+
<version>2.92.0</version>
2929
</parent>
3030

3131
<packaging>jar</packaging>

ext/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>io.em2m.sdk</groupId>
2727
<artifactId>em2m-java-sdk-pom</artifactId>
28-
<version>2.91.0</version>
28+
<version>2.92.0</version>
2929
</parent>
3030

3131
<packaging>jar</packaging>

geo/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>io.em2m.sdk</groupId>
2727
<artifactId>em2m-java-sdk-pom</artifactId>
28-
<version>2.91.0</version>
28+
<version>2.92.0</version>
2929
</parent>
3030

3131
<packaging>jar</packaging>

policy/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>io.em2m.sdk</groupId>
2727
<artifactId>em2m-java-sdk-pom</artifactId>
28-
<version>2.91.0</version>
28+
<version>2.92.0</version>
2929
</parent>
3030

3131
<packaging>jar</packaging>

policy/src/main/java/io/em2m/policy/basic/BasicPolicyEngine.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ class BasicPolicyEngine(policySource: PolicySource, val simplex: Simplex = Simpl
1313

1414
override fun findAllowedActions(context: PolicyContext): List<String> {
1515
val roles = context.claims.roles.plus("anonymous").distinct()
16-
val statements = statementsForRoles(roles)
16+
17+
val (allowedStatements, deniedStatements) = statementsForRoles(roles)
1718
.filter { testResource(it, context) }
1819
.filter { it.condition.call(context.map) }
19-
.filter { it.effect == Effect.Allow }
20-
return statements.flatMap { it.actions }.distinct()
20+
.partition { it.effect == Effect.Allow }
21+
22+
val allowed = allowedStatements.flatMap { it.actions }.distinct()
23+
val denied = deniedStatements.flatMap { it.actions }.distinct()
24+
25+
return allowed.filter { action -> action !in denied }
2126
}
2227

2328
override fun isActionAllowed(actionName: String, context: PolicyContext): Boolean {

policy/src/test/data/policies/AccountFullAccess.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
"fimanager"
3131
]
3232
}
33-
}}
33+
}},
34+
{
35+
"effect": "Deny",
36+
"actions": [
37+
"ident:DeleteAccount"
38+
],
39+
"resource": "em2m:ident:account:*",
40+
"condition": true
41+
}
3442
]
3543
}

policy/src/test/data/roles/sales.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
"feature:SalesRoleFeature"
1111
],
1212
"resource": "em2m:ident:account:*"
13+
},
14+
{
15+
"effect": "Deny",
16+
"actions": [
17+
"ident:ChangeMyPassword"
18+
],
19+
"resource": "*"
1320
}
1421
]
15-
}
22+
}

policy/src/test/java/io/em2m/policy/PolicyEngineTest.kt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ class PolicyEngineTest : Assert() {
3737
println(allowed)
3838
}
3939

40+
@Test
41+
fun testIsActionAllowedFalse() {
42+
val claims = Claims(mapOf("sub" to "userid", "roles" to listOf("admin"), "exp" to Date(),
43+
"features" to listOf("maintenance")))
44+
val environment = Environment(emptyMap())
45+
val resource = "em2m:ident:account:1234"
46+
val isActionAllowed = policyEngine.isActionAllowed("ident:DeleteAccount", PolicyContext(claims, environment, resource))
47+
assertFalse(isActionAllowed)
48+
}
49+
4050
@Test
4151
@Ignore
4252
fun testAllowIfFeature() {
@@ -85,9 +95,23 @@ class PolicyEngineTest : Assert() {
8595
}
8696

8797
@Test
88-
@Ignore
8998
fun testDeny() {
90-
error("Not implemented")
99+
val claims = Claims(mapOf("sub" to "1234", "roles" to listOf("sales"), "exp" to Date()))
100+
val environment = Environment(emptyMap())
101+
val resource = "em2m:ident:account:1234"
102+
val context = PolicyContext(claims, environment, resource)
103+
val allowed = policyEngine.isActionAllowed("ident:ChangeMyPassword", context)
104+
assertFalse(allowed)
105+
}
106+
107+
@Test
108+
fun testAllowedActionsFiltering() {
109+
val claims = Claims(mapOf("sub" to "1234", "roles" to listOf("sales"), "exp" to Date()))
110+
val environment = Environment(emptyMap())
111+
val resource = "em2m:ident:account:1234"
112+
val context = PolicyContext(claims, environment, resource)
113+
val allowedActions = policyEngine.findAllowedActions(context)
114+
assertFalse("ident:ChangeMyPassword" in allowedActions)
91115
}
92116

93117
class ReportTypeKey : KeyHandlerSupport() {
@@ -111,4 +135,4 @@ class PolicyEngineTest : Assert() {
111135
}
112136
}
113137

114-
}
138+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<artifactId>em2m-java-sdk-pom</artifactId>
2727
<packaging>pom</packaging>
2828
<name>em2m-java-sdk-pom</name>
29-
<version>2.91.0</version>
29+
<version>2.92.0</version>
3030

3131
<modules>
3232
<module>utils</module>

problem/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
<parent>
2626
<groupId>io.em2m.sdk</groupId>
2727
<artifactId>em2m-java-sdk-pom</artifactId>
28-
<version>2.91.0</version>
28+
<version>2.92.0</version>
2929
</parent>
3030

3131
<packaging>jar</packaging>
3232
<artifactId>em2m-java-sdk-problem</artifactId>
33-
<version>2.91.0</version>
33+
<version>2.92.0</version>
3434
<name>em2m-java-sdk-problem</name>
3535

3636
<dependencies>

0 commit comments

Comments
 (0)