use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.
the class RealmTest method smtpPasswordSecret.
@Test
public void smtpPasswordSecret() {
RealmRepresentation rep = RealmBuilder.create().testEventListener().testMail().build();
rep.setRealm("realm-with-smtp");
rep.getSmtpServer().put("user", "user");
rep.getSmtpServer().put("password", "secret");
adminClient.realms().create(rep);
RealmRepresentation returned = adminClient.realm("realm-with-smtp").toRepresentation();
assertEquals(ComponentRepresentation.SECRET_VALUE, returned.getSmtpServer().get("password"));
KeycloakTestingClient.Server serverClient = testingClient.server("realm-with-smtp");
RealmRepresentation internalRep = serverClient.fetch(RunHelpers.internalRealm());
assertEquals("secret", internalRep.getSmtpServer().get("password"));
adminClient.realm("realm-with-smtp").update(rep);
AdminEventRepresentation event = testingClient.testing().pollAdminEvent();
assertFalse(event.getRepresentation().contains("some secret value!!"));
assertTrue(event.getRepresentation().contains(ComponentRepresentation.SECRET_VALUE));
internalRep = serverClient.fetch(RunHelpers.internalRealm());
assertEquals("secret", internalRep.getSmtpServer().get("password"));
RealmRepresentation realm = adminClient.realms().findAll().stream().filter(r -> r.getRealm().equals("realm-with-smtp")).findFirst().get();
assertEquals(ComponentRepresentation.SECRET_VALUE, realm.getSmtpServer().get("password"));
adminClient.realm("realm-with-smtp").remove();
}
use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.
the class AssertAdminEvents method assertEmpty.
public void assertEmpty() {
AdminEventRepresentation event = fetchNextEvent();
Assert.assertNull("Empty admin event queue expected, but there is " + event, event);
}
use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.
the class AssertAdminEvents method poll.
public AdminEventRepresentation poll() {
AdminEventRepresentation event = fetchNextEvent();
Assert.assertNotNull("Admin event expected", event);
return event;
}
use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.
the class AbstractProtocolMapperTest method testAddAllBuiltinMappers.
protected void testAddAllBuiltinMappers(ProtocolMappersResource resource, String protocolName, String adminEventPath) {
List<ProtocolMapperRepresentation> oldMappers = resource.getMappersPerProtocol(protocolName);
List<ProtocolMapperRepresentation> builtins = builtinMappers.get(protocolName);
List<ProtocolMapperRepresentation> mappersToAdd = mappersToAdd(oldMappers, builtins);
// This is used by admin console to add builtin mappers
resource.createMapper(mappersToAdd);
AdminEventRepresentation adminEvent = assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, adminEventPath + "/add-models", ResourceType.PROTOCOL_MAPPER);
try {
List<ProtocolMapperRepresentation> eventMappers = JsonSerialization.readValue(new ByteArrayInputStream(adminEvent.getRepresentation().getBytes()), new TypeReference<List<ProtocolMapperRepresentation>>() {
});
Assert.assertEquals(eventMappers.size(), mappersToAdd.size());
for (int i = 0; i < mappersToAdd.size(); i++) {
ProtocolMapperRepresentation repExpected = mappersToAdd.get(i);
ProtocolMapperRepresentation repActual = eventMappers.get(i);
assertEqualMappers(repExpected, repActual);
}
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
List<ProtocolMapperRepresentation> newMappers = resource.getMappersPerProtocol(protocolName);
assertEquals(oldMappers.size() + mappersToAdd.size(), newMappers.size());
for (ProtocolMapperRepresentation rep : mappersToAdd) {
assertTrue(containsMapper(newMappers, rep));
}
}
use of org.keycloak.representations.idm.AdminEventRepresentation in project keycloak by keycloak.
the class PartialImportTest method testAddUsersWithTermsAndConditions.
@Test
public void testAddUsersWithTermsAndConditions() {
assertAdminEvents.clear();
setFail();
addUsersWithTermsAndConditions();
PartialImportResults results = doImport();
assertEquals(NUM_ENTITIES, results.getAdded());
// Need to do this way as admin events from partial import are unsorted
Set<String> userIds = new HashSet<>();
for (int i = 0; i < NUM_ENTITIES; i++) {
AdminEventRepresentation adminEvent = assertAdminEvents.poll();
Assert.assertEquals(realmId, adminEvent.getRealmId());
Assert.assertEquals(OperationType.CREATE.name(), adminEvent.getOperationType());
Assert.assertTrue(adminEvent.getResourcePath().startsWith("users/"));
String userId = adminEvent.getResourcePath().substring(6);
userIds.add(userId);
}
assertAdminEvents.assertEmpty();
for (PartialImportResult result : results.getResults()) {
String id = result.getId();
UserResource userRsc = testRealmResource().users().get(id);
UserRepresentation user = userRsc.toRepresentation();
assertTrue(user.getUsername().startsWith(USER_PREFIX));
Assert.assertTrue(userIds.contains(id));
}
}
Aggregations