[KEYCLOAK-9474] - Public endpoints are returning 403 with body when enforcement mode is disabled

This commit is contained in:
Pedro Igor 2019-01-31 14:30:08 -02:00
parent 366ee083ac
commit 4d5dff1d64
2 changed files with 22 additions and 3 deletions

View file

@ -159,11 +159,9 @@ public class AuthenticatedActionsHandler {
if (session != null) { if (session != null) {
session.setAuthorizationContext(authorizationContext); session.setAuthorizationContext(authorizationContext);
return authorizationContext.isGranted();
} }
return true; return authorizationContext.isGranted();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Failed to enforce policy decisions.", e); throw new RuntimeException("Failed to enforce policy decisions.", e);
} }

View file

@ -211,6 +211,27 @@ public class PolicyEnforcerTest extends AbstractKeycloakTest {
assertEquals(403, response.getStatus()); 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 @Test
public void testMappedPathEnforcementModeDisabled() { public void testMappedPathEnforcementModeDisabled() {
KeycloakDeployment deployment = KeycloakDeploymentBuilder.build(getAdapterConfiguration("enforcer-disabled-enforce-mode-path.json")); KeycloakDeployment deployment = KeycloakDeploymentBuilder.build(getAdapterConfiguration("enforcer-disabled-enforce-mode-path.json"));