Merge pull request #5004 from pedroigor/KEYCLOAK-6623
[KEYCLOAK-6623] - Policy enforcer gets confused with similar paths ending with wildcards
This commit is contained in:
commit
b9b1102b74
4 changed files with 65 additions and 1 deletions
|
@ -95,7 +95,9 @@ class PathMatcher {
|
|||
}
|
||||
|
||||
if (WILDCARD == expectedUri.charAt(expectedUri.length() - 1)) {
|
||||
matchingAnyPath = entry;
|
||||
if (matchingAnyPath == null || matchingAnyPath.getPath().length() < matchingUri.length()) {
|
||||
matchingAnyPath = entry;
|
||||
}
|
||||
} else {
|
||||
int suffixIndex = expectedUri.indexOf(WILDCARD + ".");
|
||||
|
||||
|
|
|
@ -107,6 +107,14 @@
|
|||
{
|
||||
"name": "Pattern 12",
|
||||
"uri": "/realm_uri"
|
||||
},
|
||||
{
|
||||
"name": "Pattern 13",
|
||||
"uri": "/keycloak-6623/*"
|
||||
},
|
||||
{
|
||||
"name": "Pattern 14",
|
||||
"uri": "/keycloak-6623/sub-resource/*"
|
||||
}
|
||||
],
|
||||
"policies": [
|
||||
|
@ -258,6 +266,26 @@
|
|||
"resources": "[\"Pattern 12\"]",
|
||||
"applyPolicies": "[\"Default Policy\"]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Pattern 13 Permission",
|
||||
"type": "resource",
|
||||
"logic": "POSITIVE",
|
||||
"decisionStrategy": "UNANIMOUS",
|
||||
"config": {
|
||||
"resources": "[\"Pattern 13\"]",
|
||||
"applyPolicies": "[\"Default Policy\"]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Pattern 14 Permission",
|
||||
"type": "resource",
|
||||
"logic": "POSITIVE",
|
||||
"decisionStrategy": "UNANIMOUS",
|
||||
"config": {
|
||||
"resources": "[\"Pattern 14\"]",
|
||||
"applyPolicies": "[\"Default Policy\"]"
|
||||
}
|
||||
}
|
||||
],
|
||||
"scopes": []
|
||||
|
|
|
@ -60,6 +60,14 @@
|
|||
{
|
||||
"name": "Pattern 12",
|
||||
"path": "/keycloak_json_uri"
|
||||
},
|
||||
{
|
||||
"name": "Pattern 14",
|
||||
"path": "/keycloak-6623/sub-resource/*"
|
||||
},
|
||||
{
|
||||
"name": "Pattern 13",
|
||||
"path": "/keycloak-6623/*"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -379,6 +379,32 @@ public abstract class AbstractServletPolicyEnforcerTest extends AbstractExampleA
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPathOrderWithAllPaths() {
|
||||
performTests(() -> {
|
||||
login("alice", "alice");
|
||||
navigateTo("/keycloak-6623");
|
||||
assertFalse(wasDenied());
|
||||
navigateTo("/keycloak-6623/sub-resource");
|
||||
assertFalse(wasDenied());
|
||||
|
||||
updatePermissionPolicies("Pattern 13 Permission", "Deny Policy");
|
||||
|
||||
login("alice", "alice");
|
||||
navigateTo("/keycloak-6623");
|
||||
assertTrue(wasDenied());
|
||||
navigateTo("/keycloak-6623/sub-resource");
|
||||
assertFalse(wasDenied());
|
||||
|
||||
updatePermissionPolicies("Pattern 14 Permission", "Deny Policy");
|
||||
|
||||
login("alice", "alice");
|
||||
navigateTo("/keycloak-6623");
|
||||
assertTrue(wasDenied());
|
||||
navigateTo("/keycloak-6623/sub-resource/resource");
|
||||
assertTrue(wasDenied());
|
||||
});
|
||||
}
|
||||
|
||||
private void navigateTo(String path) {
|
||||
this.driver.navigate().to(getResourceServerUrl() + path);
|
||||
|
|
Loading…
Reference in a new issue