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();
}
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);
}
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());
}
}
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);
}
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);
}
Aggregations