[KEYCLOAK-8142] - Fixing regression when setting path enforcement mode to disabled
This commit is contained in:
1 parent
2eddfd3ea8
commit
33efcc6b93
3 files changed
+59
-1
No files matched your search
+35
@@ -176,6 +176,41 @@ public class PolicyEnforcerTest extends AbstractKeycloakTest {
|
||||
assertEquals(403, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMappedPathEnforcementModeDisabled() {
|
||||
KeycloakDeployment deployment = KeycloakDeploymentBuilder.build(getAdapterConfiguration("enforcer-disabled-enforce-mode-path.json"));
|
||||
PolicyEnforcer policyEnforcer = deployment.getPolicyEnforcer();
|
||||
|
||||
OIDCHttpFacade httpFacade = createHttpFacade("/api/resource/public");
|
||||
AuthorizationContext context = policyEnforcer.enforce(httpFacade);
|
||||
assertTrue(context.isGranted());
|
||||
|
||||
httpFacade = createHttpFacade("/api/resourceb");
|
||||
context = policyEnforcer.enforce(httpFacade);
|
||||
assertFalse(context.isGranted());
|
||||
TestResponse response = TestResponse.class.cast(httpFacade.getResponse());
|
||||
assertEquals(403, response.getStatus());
|
||||
|
||||
oauth.realm(REALM_NAME);
|
||||
oauth.clientId("public-client-test");
|
||||
oauth.doLogin("marta", "password");
|
||||
String token = oauth.doAccessTokenRequest(oauth.getCurrentQuery().get(OAuth2Constants.CODE), null).getAccessToken();
|
||||
|
||||
httpFacade = createHttpFacade("/api/resourcea", token);
|
||||
context = policyEnforcer.enforce(httpFacade);
|
||||
assertTrue(context.isGranted());
|
||||
|
||||
httpFacade = createHttpFacade("/api/resourceb", token);
|
||||
context = policyEnforcer.enforce(httpFacade);
|
||||
assertFalse(context.isGranted());
|
||||
response = TestResponse.class.cast(httpFacade.getResponse());
|
||||
assertEquals(403, response.getStatus());
|
||||
|
||||
httpFacade = createHttpFacade("/api/resource/public", token);
|
||||
context = policyEnforcer.enforce(httpFacade);
|
||||
assertTrue(context.isGranted());
|
||||
}
|
||||
|
||||
private void initAuthorizationSettings(ClientResource clientResource) {
|
||||
if (clientResource.authorization().resources().findByName("Resource A").isEmpty()) {
|
||||
JSPolicyRepresentation policy = new JSPolicyRepresentation();
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"realm": "authz-test",
|
||||
"auth-server-url": "http://localhost:8180/auth",
|
||||
"ssl-required": "external",
|
||||
"resource": "resource-server-test",
|
||||
"credentials": {
|
||||
"secret": "secret"
|
||||
},
|
||||
"bearer-only": true,
|
||||
"policy-enforcer": {
|
||||
"paths": [
|
||||
{
|
||||
"name": "Resource B",
|
||||
"path": "/api/resource/public",
|
||||
"enforcement-mode": "DISABLED"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user