use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class LDAPSyncTest method test07SyncRestAPIWrongAction.
// KEYCLOAK-10770 user-storage/{id}/sync should return 400 instead of 404
@Test
public void test07SyncRestAPIWrongAction() {
ComponentRepresentation ldapRep = testRealm().components().component(ldapModelId).toRepresentation();
try {
SynchronizationResultRepresentation syncResultRep = adminClient.realm("test").userStorage().syncUsers(ldapModelId, "wrong action");
Assert.fail("Should throw 400");
} catch (Exception e) {
Assert.assertTrue(e instanceof BadRequestException);
}
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class LDAPSyncTest method test06SyncRestAPIMissingAction.
// KEYCLOAK-10770 user-storage/{id}/sync should return 400 instead of 404
@Test
public void test06SyncRestAPIMissingAction() {
ComponentRepresentation ldapRep = testRealm().components().component(ldapModelId).toRepresentation();
try {
SynchronizationResultRepresentation syncResultRep = adminClient.realm("test").userStorage().syncUsers(ldapModelId, null);
Assert.fail("Should throw 400");
} catch (Exception e) {
Assert.assertTrue(e instanceof BadRequestException);
}
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class UserStorageTest method testWeeklyEviction.
@Test
public void testWeeklyEviction() {
ApiUtil.findUserByUsername(testRealmResource(), "thor");
// set eviction to 4 days from now
Calendar eviction = Calendar.getInstance();
eviction.add(Calendar.HOUR, 4 * 24);
ComponentRepresentation propProviderRW = testRealmResource().components().component(propProviderRWId).toRepresentation();
propProviderRW.getConfig().putSingle(CACHE_POLICY, CachePolicy.EVICT_WEEKLY.name());
propProviderRW.getConfig().putSingle(EVICTION_DAY, Integer.toString(eviction.get(DAY_OF_WEEK)));
propProviderRW.getConfig().putSingle(EVICTION_HOUR, Integer.toString(eviction.get(HOUR_OF_DAY)));
propProviderRW.getConfig().putSingle(EVICTION_MINUTE, Integer.toString(eviction.get(MINUTE)));
testRealmResource().components().component(propProviderRWId).update(propProviderRW);
// now
testingClient.server().run(session -> {
RealmModel realm = session.realms().getRealmByName("test");
UserModel user = session.users().getUserByUsername(realm, "thor");
System.out.println("User class: " + user.getClass());
// should still be cached
Assert.assertTrue(user instanceof CachedUserModel);
});
// 2 days in future
setTimeOffset(2 * 24 * 60 * 60);
// now
testingClient.server().run(session -> {
RealmModel realm = session.realms().getRealmByName("test");
UserModel user = session.users().getUserByUsername(realm, "thor");
System.out.println("User class: " + user.getClass());
// should still be cached
Assert.assertTrue(user instanceof CachedUserModel);
});
// 5 days in future
setTimeOffset(5 * 24 * 60 * 60);
testingClient.server().run(session -> {
RealmModel realm = session.realms().getRealmByName("test");
UserModel user = session.users().getUserByUsername(realm, "thor");
System.out.println("User class: " + user.getClass());
// should be evicted
Assert.assertFalse(user instanceof CachedUserModel);
});
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class RealmManager method deactivateOtherRsaKeys.
private void deactivateOtherRsaKeys(String providerId) {
List<String> otherRsaKeyProviderIds = realm.keys().getKeyMetadata().getKeys().stream().filter(key -> KeyType.RSA.equals(key.getType()) && !providerId.equals(key.getProviderId())).map(key -> key.getProviderId()).collect(Collectors.toList());
for (String otherRsaKeyProviderId : otherRsaKeyProviderIds) {
ComponentResource componentResource = realm.components().component(otherRsaKeyProviderId);
ComponentRepresentation componentRepresentation = componentResource.toRepresentation();
componentRepresentation.getConfig().putSingle(Attributes.ACTIVE_KEY, "false");
componentResource.update(componentRepresentation);
}
}
use of org.keycloak.representations.idm.ComponentRepresentation in project keycloak by keycloak.
the class AccountLinkTest method beforeBrokerTest.
@Before
public void beforeBrokerTest() {
if (testContext.isInitialized()) {
return;
}
// addIdpUser
RealmResource realmParent = adminClient.realms().realm(PARENT_IDP);
UserRepresentation user = new UserRepresentation();
user.setUsername(PARENT_USERNAME);
user.setEnabled(true);
String userId = createUserAndResetPasswordWithAdminClient(realmParent, user, "password");
// addChildUser
RealmResource realmChild = adminClient.realms().realm(CHILD_IDP);
user = new UserRepresentation();
user.setUsername("child");
user.setEnabled(true);
userId = createUserAndResetPasswordWithAdminClient(realmChild, user, "password");
// setupUserStorageProvider
ComponentRepresentation provider = new ComponentRepresentation();
provider.setName("passthrough");
provider.setProviderId(PassThroughFederatedUserStorageProviderFactory.PROVIDER_ID);
provider.setProviderType(UserStorageProvider.class.getName());
provider.setConfig(new MultivaluedHashMap<>());
provider.getConfig().putSingle("priority", Integer.toString(1));
realmChild.components().add(provider);
// createBroker
createParentChild();
testContext.setInitialized(true);
}
Aggregations