[KEYCLOAK-9402] - 401 response when enforcement mode is DISABLED
This commit is contained in:
parent
873c62bbef
commit
2a82ed6eea
3 changed files with 34 additions and 1 deletions
|
@ -59,14 +59,17 @@ public abstract class AbstractPolicyEnforcer {
|
|||
|
||||
public AuthorizationContext authorize(OIDCHttpFacade httpFacade) {
|
||||
EnforcementMode enforcementMode = getEnforcerConfig().getEnforcementMode();
|
||||
KeycloakSecurityContext securityContext = httpFacade.getSecurityContext();
|
||||
|
||||
if (EnforcementMode.DISABLED.equals(enforcementMode)) {
|
||||
if (securityContext == null) {
|
||||
httpFacade.getResponse().sendError(401, "Invalid bearer");
|
||||
}
|
||||
return createEmptyAuthorizationContext(true);
|
||||
}
|
||||
|
||||
Request request = httpFacade.getRequest();
|
||||
PathConfig pathConfig = getPathConfig(request);
|
||||
KeycloakSecurityContext securityContext = httpFacade.getSecurityContext();
|
||||
|
||||
if (securityContext == null) {
|
||||
if (!isDefaultAccessDeniedUri(request)) {
|
||||
|
|
|
@ -301,6 +301,17 @@ public class PolicyEnforcerTest extends AbstractKeycloakTest {
|
|||
assertTrue(context.isGranted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnforcementModeDisabled() {
|
||||
KeycloakDeployment deployment = KeycloakDeploymentBuilder.build(getAdapterConfiguration("enforcer-disabled-enforce-mode.json"));
|
||||
PolicyEnforcer policyEnforcer = deployment.getPolicyEnforcer();
|
||||
|
||||
OIDCHttpFacade httpFacade = createHttpFacade("/api/resource/public");
|
||||
policyEnforcer.enforce(httpFacade);
|
||||
TestResponse response = TestResponse.class.cast(httpFacade.getResponse());
|
||||
assertEquals(401, response.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultWWWAuthenticateCorsHeader() {
|
||||
KeycloakDeployment deployment = KeycloakDeploymentBuilder.build(getAdapterConfiguration("enforcer-disabled-enforce-mode-path.json"));
|
||||
|
|
|
@ -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": {
|
||||
"enforcement-mode": "DISABLED",
|
||||
"paths": [
|
||||
{
|
||||
"name": "Resource B",
|
||||
"path": "/api/resource/public"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue