diff --git a/adapters/oidc/adapter-core/src/main/java/org/keycloak/adapters/AuthenticatedActionsHandler.java b/adapters/oidc/adapter-core/src/main/java/org/keycloak/adapters/AuthenticatedActionsHandler.java index 137f6d305a..342cefce3d 100755 --- a/adapters/oidc/adapter-core/src/main/java/org/keycloak/adapters/AuthenticatedActionsHandler.java +++ b/adapters/oidc/adapter-core/src/main/java/org/keycloak/adapters/AuthenticatedActionsHandler.java @@ -159,11 +159,9 @@ public class AuthenticatedActionsHandler { if (session != null) { session.setAuthorizationContext(authorizationContext); - - return authorizationContext.isGranted(); } - return true; + return authorizationContext.isGranted(); } catch (Exception e) { throw new RuntimeException("Failed to enforce policy decisions.", e); } diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/authorization/PolicyEnforcerTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/authorization/PolicyEnforcerTest.java index a4fae18647..160113d60d 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/authorization/PolicyEnforcerTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/client/authorization/PolicyEnforcerTest.java @@ -211,6 +211,27 @@ public class PolicyEnforcerTest extends AbstractKeycloakTest { assertEquals(403, response.getStatus()); } + @Test + public void testPublicEndpointNoBearerAbortRequest() { + KeycloakDeployment deployment = KeycloakDeploymentBuilder.build(getAdapterConfiguration("enforcer-bearer-only.json")); + OIDCHttpFacade httpFacade = createHttpFacade("/api/public"); + AuthenticatedActionsHandler handler = new AuthenticatedActionsHandler(deployment, httpFacade); + + assertTrue(handler.handledRequest()); + + oauth.realm(REALM_NAME); + oauth.clientId("public-client-test"); + oauth.doLogin("marta", "password"); + + String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE); + OAuthClient.AccessTokenResponse response = oauth.doAccessTokenRequest(code, null); + String token = response.getAccessToken(); + httpFacade = createHttpFacade("/api/resourcea", token); + handler = new AuthenticatedActionsHandler(deployment, httpFacade); + + assertFalse(handler.handledRequest()); + } + @Test public void testMappedPathEnforcementModeDisabled() { KeycloakDeployment deployment = KeycloakDeploymentBuilder.build(getAdapterConfiguration("enforcer-disabled-enforce-mode-path.json"));