Search in sources :

Example 51 with ClientRepresentation

use of org.keycloak.representations.idm.ClientRepresentation in project keycloak by keycloak.

the class LoginTest method loginWithDisabledCookies.

@Test
public void loginWithDisabledCookies() {
    String userId = adminClient.realm("test").users().search("test-user@localhost").get(0).getId();
    oauth.clientId("test-app");
    oauth.openLoginForm();
    driver.manage().deleteAllCookies();
    // Cookie has been deleted or disabled, the error shown in the UI should be Errors.COOKIE_NOT_FOUND
    loginPage.login("login@test.com", "password");
    events.expect(EventType.LOGIN_ERROR).user(new UserRepresentation()).client(new ClientRepresentation()).error(Errors.COOKIE_NOT_FOUND).assertEvent();
    errorPage.assertCurrent();
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 52 with ClientRepresentation

use of org.keycloak.representations.idm.ClientRepresentation in project keycloak by keycloak.

the class CustomFlowTest method configureTestRealm.

@Override
public void configureTestRealm(RealmRepresentation testRealm) {
    UserRepresentation user = UserBuilder.create().username("login-test").email("login@test.com").enabled(true).build();
    testRealm.getUsers().add(user);
    // Set passthrough clientAuthenticator for our clients
    ClientRepresentation dummyClient = ClientBuilder.create().clientId("dummy-client").name("dummy-client").authenticatorType(PassThroughClientAuthenticator.PROVIDER_ID).directAccessGrants().build();
    testRealm.getClients().add(dummyClient);
    ClientRepresentation testApp = RealmRepUtil.findClientByClientId(testRealm, "test-app");
    testApp.setClientAuthenticatorType(PassThroughClientAuthenticator.PROVIDER_ID);
    testApp.setDirectAccessGrantsEnabled(true);
}
Also used : UserRepresentation(org.keycloak.representations.idm.UserRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation)

Example 53 with ClientRepresentation

use of org.keycloak.representations.idm.ClientRepresentation in project keycloak by keycloak.

the class ResetPasswordTest method resetPasswordTwiceInNewTab.

private void resetPasswordTwiceInNewTab(UserRepresentation user, String clientId, boolean shouldLogOut, String redirectUri, String requiredUri) throws IOException {
    events.clear();
    updateForgottenPassword(user, clientId, redirectUri, requiredUri);
    if (shouldLogOut) {
        String sessionId = events.expectLogin().user(user.getId()).detail(Details.USERNAME, user.getUsername()).detail(Details.REDIRECT_URI, redirectUri).client(clientId).assertEvent().getSessionId();
        oauth.openLogout();
        events.expectLogout(sessionId).user(user.getId()).session(sessionId).assertEvent();
    }
    BrowserTabUtil util = BrowserTabUtil.getInstanceAndSetEnv(driver);
    assertThat(util.getCountOfTabs(), Matchers.equalTo(2));
    util.closeTab(1);
    assertThat(util.getCountOfTabs(), Matchers.equalTo(1));
    if (shouldLogOut) {
        final ClientRepresentation client = testRealm().clients().findByClientId(clientId).stream().findFirst().orElse(null);
        assertThat(client, Matchers.notNullValue());
        updateForgottenPassword(user, clientId, getValidRedirectUriWithRootUrl(client.getRootUrl(), client.getRedirectUris()));
    } else {
        doForgotPassword(user.getUsername());
    }
}
Also used : BrowserTabUtil(org.keycloak.testsuite.util.BrowserTabUtil) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation)

Example 54 with ClientRepresentation

use of org.keycloak.representations.idm.ClientRepresentation in project keycloak by keycloak.

the class LevelOfAssuranceFlowTest method testClientDefaultAcrValuesValidation.

@Test
public void testClientDefaultAcrValuesValidation() throws IOException {
    // Setup realm acr-to-loa mapping
    RealmRepresentation realmRep = testRealm().toRepresentation();
    Map<String, Integer> acrLoaMap = new HashMap<>();
    acrLoaMap.put("realm:copper", 0);
    acrLoaMap.put("realm:silver", 1);
    realmRep.getAttributes().put(Constants.ACR_LOA_MAP, JsonSerialization.writeValueAsString(acrLoaMap));
    testRealm().update(realmRep);
    // Value "foo" not used in any ACR-To-Loa mapping
    ClientResource testClient = ApiUtil.findClientByClientId(testRealm(), "test-app");
    ClientRepresentation testClientRep = testClient.toRepresentation();
    OIDCAdvancedConfigWrapper.fromClientRepresentation(testClientRep).setAttributeMultivalued(Constants.DEFAULT_ACR_VALUES, Arrays.asList("silver", "2", "foo"));
    try {
        testClient.update(testClientRep);
        Assert.fail("Should not successfully update client");
    } catch (BadRequestException bre) {
    // Expected
    }
    // Value "5" too big
    OIDCAdvancedConfigWrapper.fromClientRepresentation(testClientRep).setAttributeMultivalued(Constants.DEFAULT_ACR_VALUES, Arrays.asList("silver", "2", "5"));
    try {
        testClient.update(testClientRep);
        Assert.fail("Should not successfully update client");
    } catch (BadRequestException bre) {
    // Expected
    }
    // Should be fine
    OIDCAdvancedConfigWrapper.fromClientRepresentation(testClientRep).setAttributeMultivalued(Constants.DEFAULT_ACR_VALUES, Arrays.asList("silver", "2"));
    testClient.update(testClientRep);
    // Revert
    testClientRep.getAttributes().put(Constants.DEFAULT_ACR_VALUES, null);
    testClient.update(testClientRep);
    realmRep.getAttributes().remove(Constants.ACR_LOA_MAP);
    testRealm().update(realmRep);
}
Also used : HashMap(java.util.HashMap) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) ClientResource(org.keycloak.admin.client.resource.ClientResource) BadRequestException(javax.ws.rs.BadRequestException) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 55 with ClientRepresentation

use of org.keycloak.representations.idm.ClientRepresentation in project keycloak by keycloak.

the class LevelOfAssuranceFlowTest method testRealmAcrLoaMapping.

@Test
public void testRealmAcrLoaMapping() throws IOException {
    // Setup realm acr-to-loa mapping
    RealmRepresentation realmRep = testRealm().toRepresentation();
    Map<String, Integer> acrLoaMap = new HashMap<>();
    acrLoaMap.put("realm:copper", 0);
    acrLoaMap.put("realm:silver", 1);
    acrLoaMap.put("realm:gold", 2);
    realmRep.getAttributes().put(Constants.ACR_LOA_MAP, JsonSerialization.writeValueAsString(acrLoaMap));
    testRealm().update(realmRep);
    // Remove acr-to-loa mapping from the client. It should use realm acr-to-loa mapping
    ClientResource testClient = ApiUtil.findClientByClientId(testRealm(), "test-app");
    ClientRepresentation testClientRep = testClient.toRepresentation();
    testClientRep.getAttributes().put(Constants.ACR_LOA_MAP, "{}");
    testClient.update(testClientRep);
    openLoginFormWithAcrClaim(true, "realm:gold");
    authenticateWithUsername();
    authenticateWithPassword();
    assertLoggedInWithAcr("realm:gold");
    // Add "acr-to-loa" back to the client. Client mapping will be used instead of realm mapping
    testClientRep.getAttributes().put(Constants.ACR_LOA_MAP, getAcrToLoaMappingForClient());
    testClient.update(testClientRep);
    openLoginFormWithAcrClaim(true, "realm:gold");
    assertErrorPage("Invalid parameter: claims");
    openLoginFormWithAcrClaim(true, "gold");
    authenticateWithPassword();
    assertLoggedInWithAcr("gold");
    // Rollback
    realmRep.getAttributes().remove(Constants.ACR_LOA_MAP);
    testRealm().update(realmRep);
}
Also used : HashMap(java.util.HashMap) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) ClientResource(org.keycloak.admin.client.resource.ClientResource) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Aggregations

ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)576 Test (org.junit.Test)359 ClientResource (org.keycloak.admin.client.resource.ClientResource)189 OIDCClientRepresentation (org.keycloak.representations.oidc.OIDCClientRepresentation)139 OAuthClient (org.keycloak.testsuite.util.OAuthClient)101 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)61 Response (javax.ws.rs.core.Response)59 Matchers.containsString (org.hamcrest.Matchers.containsString)58 RealmResource (org.keycloak.admin.client.resource.RealmResource)58 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)58 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)53 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)43 AuthenticationRequestAcknowledgement (org.keycloak.testsuite.util.OAuthClient.AuthenticationRequestAcknowledgement)41 ClientsResource (org.keycloak.admin.client.resource.ClientsResource)38 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)38 ClientPoliciesBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientPoliciesBuilder)37 ClientPolicyBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientPolicyBuilder)37 ClientProfileBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientProfileBuilder)37 ClientProfilesBuilder (org.keycloak.testsuite.util.ClientPoliciesUtil.ClientProfilesBuilder)37 HashMap (java.util.HashMap)33