use of org.keycloak.representations.idm.RealmEventsConfigRepresentation in project keycloak by keycloak.
the class GenericPolicyManagementAdminEventTest method afterAbstractKeycloakTestRealmImport.
@Override
protected void afterAbstractKeycloakTestRealmImport() {
super.afterAbstractKeycloakTestRealmImport();
RealmEventsConfigRepresentation rep = new RealmEventsConfigRepresentation();
rep.setAdminEventsEnabled(true);
rep.setEventsEnabled(true);
testRealmResource().updateRealmEventsConfig(rep);
}
use of org.keycloak.representations.idm.RealmEventsConfigRepresentation in project keycloak by keycloak.
the class EntitlementAPITest method testInvalidTokenSignature.
@Test
public void testInvalidTokenSignature() throws Exception {
RealmEventsConfigRepresentation eventConfig = getRealm().getRealmEventsConfig();
eventConfig.setEventsEnabled(true);
eventConfig.setEnabledEventTypes(Arrays.asList(EventType.PERMISSION_TOKEN_ERROR.name()));
getRealm().updateRealmEventsConfig(eventConfig);
ClientResource client = getClient(getRealm(), RESOURCE_SERVER_TEST);
AuthorizationResource authorization = client.authorization();
JSPolicyRepresentation policy = new JSPolicyRepresentation();
policy.setName(KeycloakModelUtils.generateId());
policy.setCode("$evaluation.grant();");
authorization.policies().js().create(policy).close();
ResourceRepresentation resource = new ResourceRepresentation();
resource.setName("Sensors");
try (Response response = authorization.resources().create(resource)) {
response.readEntity(ResourceRepresentation.class);
}
ResourcePermissionRepresentation permission = new ResourcePermissionRepresentation();
permission.setName("View Sensor");
permission.addPolicy(policy.getName());
authorization.permissions().resource().create(permission).close();
String accessToken = new OAuthClient().realm("authz-test").clientId(RESOURCE_SERVER_TEST).doGrantAccessTokenRequest("secret", "marta", "password").getAccessToken();
AuthzClient authzClient = getAuthzClient(AUTHZ_CLIENT_CONFIG);
AuthorizationRequest request = new AuthorizationRequest();
request.addPermission("Sensors");
request.setSubjectToken(accessToken + "i");
try {
authzClient.authorization().authorize(request);
fail("should fail, session invalidated");
} catch (Exception e) {
Throwable expected = e.getCause();
assertEquals(400, HttpResponseException.class.cast(expected).getStatusCode());
assertTrue(HttpResponseException.class.cast(expected).toString().contains("unauthorized_client"));
}
List<EventRepresentation> events = getRealm().getEvents(Arrays.asList(EventType.PERMISSION_TOKEN_ERROR.name()), null, null, null, null, null, null, null);
assertEquals(1, events.size());
}
use of org.keycloak.representations.idm.RealmEventsConfigRepresentation in project keycloak by keycloak.
the class RealmTest method copyRealmEventsConfigRepresentation.
private RealmEventsConfigRepresentation copyRealmEventsConfigRepresentation(RealmEventsConfigRepresentation rep) {
RealmEventsConfigRepresentation recr = new RealmEventsConfigRepresentation();
recr.setEnabledEventTypes(rep.getEnabledEventTypes());
recr.setEventsListeners(rep.getEventsListeners());
recr.setEventsExpiration(rep.getEventsExpiration());
recr.setEventsEnabled(rep.isEventsEnabled());
recr.setAdminEventsEnabled(rep.isAdminEventsEnabled());
recr.setAdminEventsDetailsEnabled(rep.isAdminEventsDetailsEnabled());
return recr;
}
use of org.keycloak.representations.idm.RealmEventsConfigRepresentation in project keycloak by keycloak.
the class RealmAdminResource method getRealmEventsConfig.
/**
* Get the events provider configuration
*
* Returns JSON object with events provider configuration
*
* @return
*/
@GET
@NoCache
@Path("events/config")
@Produces(MediaType.APPLICATION_JSON)
public RealmEventsConfigRepresentation getRealmEventsConfig() {
auth.realm().requireViewEvents();
RealmEventsConfigRepresentation config = ModelToRepresentation.toEventsConfigReprensetation(realm);
if (config.getEnabledEventTypes() == null || config.getEnabledEventTypes().isEmpty()) {
List<String> eventTypes = Arrays.stream(EventType.values()).filter(EventType::isSaveByDefault).map(EventType::name).collect(Collectors.toList());
config.setEnabledEventTypes(eventTypes);
}
return config;
}
use of org.keycloak.representations.idm.RealmEventsConfigRepresentation in project keycloak by keycloak.
the class RealmTest method updateRealmEventsConfig.
@Test
public void updateRealmEventsConfig() {
RealmEventsConfigRepresentation rep = realm.getRealmEventsConfig();
RealmEventsConfigRepresentation repOrig = copyRealmEventsConfigRepresentation(rep);
// the "event-queue" listener should be enabled by default
assertTrue("event-queue should be enabled initially", rep.getEventsListeners().contains(TestEventsListenerProviderFactory.PROVIDER_ID));
// first modification => remove "event-queue", should be sent to the queue
rep.setEnabledEventTypes(Arrays.asList(EventType.LOGIN.name(), EventType.LOGIN_ERROR.name()));
rep.setEventsListeners(Arrays.asList(JBossLoggingEventListenerProviderFactory.ID));
rep.setEventsExpiration(36000L);
rep.setEventsEnabled(true);
rep.setAdminEventsEnabled(true);
rep.setAdminEventsDetailsEnabled(true);
adminClient.realms().realm(REALM_NAME).updateRealmEventsConfig(rep);
assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, "events/config", rep, ResourceType.REALM);
RealmEventsConfigRepresentation actual = realm.getRealmEventsConfig();
checkRealmEventsConfigRepresentation(rep, actual);
// second modification => should not be sent cos event-queue was removed in the first mod
rep.setEnabledEventTypes(Arrays.asList(EventType.LOGIN.name(), EventType.LOGIN_ERROR.name(), EventType.CLIENT_LOGIN.name()));
adminClient.realms().realm(REALM_NAME).updateRealmEventsConfig(rep);
assertAdminEvents.assertEmpty();
actual = realm.getRealmEventsConfig();
checkRealmEventsConfigRepresentation(rep, actual);
// third modification => restore queue => should be sent and recovered
adminClient.realms().realm(REALM_NAME).updateRealmEventsConfig(repOrig);
assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, "events/config", repOrig, ResourceType.REALM);
actual = realm.getRealmEventsConfig();
checkRealmEventsConfigRepresentation(repOrig, actual);
}
Aggregations