KEYCLOAK-18829 FAPI-CIBA-ID1 conformance test : ClientRolesCondition needs to be evaluated on CIBA backchannel authentication request and token request
This commit is contained in:
parent
fe4e089e81
commit
02a9eb442d
2 changed files with 29 additions and 13 deletions
|
@ -75,6 +75,8 @@ public class ClientRolesCondition extends AbstractClientPolicyConditionProvider<
|
||||||
case TOKEN_INTROSPECT:
|
case TOKEN_INTROSPECT:
|
||||||
case USERINFO_REQUEST:
|
case USERINFO_REQUEST:
|
||||||
case LOGOUT_REQUEST:
|
case LOGOUT_REQUEST:
|
||||||
|
case BACKCHANNEL_AUTHENTICATION_REQUEST:
|
||||||
|
case BACKCHANNEL_TOKEN_REQUEST:
|
||||||
if (isRolesMatched(session.getContext().getClient())) return ClientPolicyVote.YES;
|
if (isRolesMatched(session.getContext().getClient())) return ClientPolicyVote.YES;
|
||||||
return ClientPolicyVote.NO;
|
return ClientPolicyVote.NO;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -37,6 +37,7 @@ import static org.keycloak.testsuite.admin.AbstractAdminTest.loadJson;
|
||||||
import static org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.AuthServer.QUARKUS;
|
import static org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.AuthServer.QUARKUS;
|
||||||
import static org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.AuthServer.REMOTE;
|
import static org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.AuthServer.REMOTE;
|
||||||
import static org.keycloak.testsuite.util.ClientPoliciesUtil.createAnyClientConditionConfig;
|
import static org.keycloak.testsuite.util.ClientPoliciesUtil.createAnyClientConditionConfig;
|
||||||
|
import static org.keycloak.testsuite.util.ClientPoliciesUtil.createClientRolesConditionConfig;
|
||||||
import static org.keycloak.testsuite.util.ClientPoliciesUtil.createClientUpdateContextConditionConfig;
|
import static org.keycloak.testsuite.util.ClientPoliciesUtil.createClientUpdateContextConditionConfig;
|
||||||
import static org.keycloak.testsuite.util.ClientPoliciesUtil.createSecureCibaAuthenticationRequestSigningAlgorithmExecutorConfig;
|
import static org.keycloak.testsuite.util.ClientPoliciesUtil.createSecureCibaAuthenticationRequestSigningAlgorithmExecutorConfig;
|
||||||
|
|
||||||
|
@ -94,8 +95,8 @@ import org.keycloak.services.clientpolicy.ClientPolicyEvent;
|
||||||
import org.keycloak.services.clientpolicy.ClientPoliciesUtil;
|
import org.keycloak.services.clientpolicy.ClientPoliciesUtil;
|
||||||
import org.keycloak.services.clientpolicy.ClientPolicyException;
|
import org.keycloak.services.clientpolicy.ClientPolicyException;
|
||||||
import org.keycloak.services.clientpolicy.condition.AnyClientConditionFactory;
|
import org.keycloak.services.clientpolicy.condition.AnyClientConditionFactory;
|
||||||
|
import org.keycloak.services.clientpolicy.condition.ClientRolesConditionFactory;
|
||||||
import org.keycloak.services.clientpolicy.condition.ClientUpdaterContextConditionFactory;
|
import org.keycloak.services.clientpolicy.condition.ClientUpdaterContextConditionFactory;
|
||||||
import org.keycloak.services.clientpolicy.executor.SecureSigningAlgorithmExecutorFactory;
|
|
||||||
import org.keycloak.testsuite.AssertEvents;
|
import org.keycloak.testsuite.AssertEvents;
|
||||||
import org.keycloak.testsuite.admin.ApiUtil;
|
import org.keycloak.testsuite.admin.ApiUtil;
|
||||||
import org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude;
|
import org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude;
|
||||||
|
@ -109,6 +110,7 @@ import org.keycloak.testsuite.util.InfinispanTestTimeServiceRule;
|
||||||
import org.keycloak.testsuite.util.KeycloakModelUtils;
|
import org.keycloak.testsuite.util.KeycloakModelUtils;
|
||||||
import org.keycloak.testsuite.util.Matchers;
|
import org.keycloak.testsuite.util.Matchers;
|
||||||
import org.keycloak.testsuite.util.OAuthClient;
|
import org.keycloak.testsuite.util.OAuthClient;
|
||||||
|
import org.keycloak.testsuite.util.RoleBuilder;
|
||||||
import org.keycloak.testsuite.util.UserBuilder;
|
import org.keycloak.testsuite.util.UserBuilder;
|
||||||
import org.keycloak.testsuite.util.ClientPoliciesUtil.ClientPoliciesBuilder;
|
import org.keycloak.testsuite.util.ClientPoliciesUtil.ClientPoliciesBuilder;
|
||||||
import org.keycloak.testsuite.util.ClientPoliciesUtil.ClientPolicyBuilder;
|
import org.keycloak.testsuite.util.ClientPoliciesUtil.ClientPolicyBuilder;
|
||||||
|
@ -1436,15 +1438,21 @@ public class CIBATest extends AbstractClientPoliciesTest {
|
||||||
).toString();
|
).toString();
|
||||||
updateProfiles(json);
|
updateProfiles(json);
|
||||||
|
|
||||||
// register policies
|
// register role policy
|
||||||
|
String roleName = "sample-client-role-alpha";
|
||||||
json = (new ClientPoliciesBuilder()).addPolicy(
|
json = (new ClientPoliciesBuilder()).addPolicy(
|
||||||
(new ClientPolicyBuilder()).createPolicy(POLICY_NAME, "La Premiere Politique", Boolean.TRUE)
|
(new ClientPolicyBuilder()).createPolicy(POLICY_NAME, "Den Forste Politikken", Boolean.TRUE)
|
||||||
.addCondition(AnyClientConditionFactory.PROVIDER_ID, createAnyClientConditionConfig())
|
.addCondition(ClientRolesConditionFactory.PROVIDER_ID,
|
||||||
.addProfile(PROFILE_NAME)
|
createClientRolesConditionConfig(Arrays.asList(roleName)))
|
||||||
.toRepresentation()
|
.addProfile(PROFILE_NAME)
|
||||||
).toString();
|
.toRepresentation()
|
||||||
|
).toString();
|
||||||
updatePolicies(json);
|
updatePolicies(json);
|
||||||
|
|
||||||
|
// Add role to the client
|
||||||
|
ClientResource clientResource = ApiUtil.findClientByClientId(adminClient.realm(REALM_NAME), clientId);
|
||||||
|
clientResource.roles().create(RoleBuilder.create().name(roleName).build());
|
||||||
|
|
||||||
AuthenticationRequestAcknowledgement response = oauth.doBackchannelAuthenticationRequest(clientId, clientSecret, TEST_USER_NAME, "Pjb9eD8w", null, null);
|
AuthenticationRequestAcknowledgement response = oauth.doBackchannelAuthenticationRequest(clientId, clientSecret, TEST_USER_NAME, "Pjb9eD8w", null, null);
|
||||||
assertEquals(400, response.getStatusCode());
|
assertEquals(400, response.getStatusCode());
|
||||||
assertEquals(ClientPolicyEvent.BACKCHANNEL_AUTHENTICATION_REQUEST.toString(), response.getError());
|
assertEquals(ClientPolicyEvent.BACKCHANNEL_AUTHENTICATION_REQUEST.toString(), response.getError());
|
||||||
|
@ -1489,15 +1497,21 @@ public class CIBATest extends AbstractClientPoliciesTest {
|
||||||
).toString();
|
).toString();
|
||||||
updateProfiles(json);
|
updateProfiles(json);
|
||||||
|
|
||||||
// register policies
|
// register role policy
|
||||||
|
String roleName = "sample-client-role-alpha";
|
||||||
json = (new ClientPoliciesBuilder()).addPolicy(
|
json = (new ClientPoliciesBuilder()).addPolicy(
|
||||||
(new ClientPolicyBuilder()).createPolicy(POLICY_NAME, "La Premiere Politique", Boolean.TRUE)
|
(new ClientPolicyBuilder()).createPolicy(POLICY_NAME, "Den Forste Politikken", Boolean.TRUE)
|
||||||
.addCondition(AnyClientConditionFactory.PROVIDER_ID, createAnyClientConditionConfig())
|
.addCondition(ClientRolesConditionFactory.PROVIDER_ID,
|
||||||
.addProfile(PROFILE_NAME)
|
createClientRolesConditionConfig(Arrays.asList(roleName)))
|
||||||
.toRepresentation()
|
.addProfile(PROFILE_NAME)
|
||||||
).toString();
|
.toRepresentation()
|
||||||
|
).toString();
|
||||||
updatePolicies(json);
|
updatePolicies(json);
|
||||||
|
|
||||||
|
// Add role to the client
|
||||||
|
ClientResource clientResource = ApiUtil.findClientByClientId(adminClient.realm(REALM_NAME), clientId);
|
||||||
|
clientResource.roles().create(RoleBuilder.create().name(roleName).build());
|
||||||
|
|
||||||
OAuthClient.AccessTokenResponse tokenRes = oauth.doBackchannelAuthenticationTokenRequest(clientId, clientSecret, response.getAuthReqId());
|
OAuthClient.AccessTokenResponse tokenRes = oauth.doBackchannelAuthenticationTokenRequest(clientId, clientSecret, response.getAuthReqId());
|
||||||
assertThat(tokenRes.getStatusCode(), is(equalTo(400)));
|
assertThat(tokenRes.getStatusCode(), is(equalTo(400)));
|
||||||
assertThat(tokenRes.getError(), is(OAuthErrorException.INVALID_GRANT));
|
assertThat(tokenRes.getError(), is(OAuthErrorException.INVALID_GRANT));
|
||||||
|
|
Loading…
Reference in a new issue