Java Code Examples for org.keycloak.representations.idm.RealmRepresentation#setEnabledEventTypes()
The following examples show how to use
org.keycloak.representations.idm.RealmRepresentation#setEnabledEventTypes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExportImportTest.java From keycloak with Apache License 2.0 | 5 votes |
private void setEventsConfig(RealmRepresentation realm) { realm.setEventsEnabled(true); realm.setAdminEventsEnabled(true); realm.setAdminEventsDetailsEnabled(true); realm.setEventsExpiration(600); realm.setEnabledEventTypes(Arrays.asList("REGISTER", "REGISTER_ERROR", "LOGIN", "LOGIN_ERROR", "LOGOUT_ERROR")); }
Example 2
Source File: DemoServletsAdapterTest.java From keycloak with Apache License 2.0 | 5 votes |
private void expectResultOfClientAuthenticatedInClientSecretJwt(String targetClientId, AbstractPageWithInjectedUrl portal) { RealmRepresentation realm = testRealmResource().toRepresentation(); realm.setEventsEnabled(true); realm.setEnabledEventTypes(Arrays.asList("LOGIN", "CODE_TO_TOKEN")); realm.setEventsListeners(Arrays.asList("jboss-logging", "event-queue")); testRealmResource().update(realm); portal.navigateTo(); assertCurrentUrlStartsWithLoginUrlOf(testRealmPage); testRealmLoginPage.form().login("[email protected]", "password"); String userId = ApiUtil.findUserByUsername(testRealmResource(), "[email protected]").getId(); assertEvents.expectLogin() .realm(realm.getId()) .client(targetClientId) .user(userId) .detail(Details.USERNAME, "[email protected]") .detail(Details.CONSENT, Details.CONSENT_VALUE_NO_CONSENT_REQUIRED) .detail(Details.REDIRECT_URI, org.hamcrest.Matchers.anyOf(org.hamcrest.Matchers.equalTo(portal.getInjectedUrl().toString()), org.hamcrest.Matchers.equalTo(portal.getInjectedUrl().toString() + "/"))) .removeDetail(Details.CODE_ID) .assertEvent(); assertEvents.expectCodeToToken(null, null) .realm(realm.getId()) .client(targetClientId) .user(userId) .session(AssertEvents.isUUID()) .clearDetails() .assertEvent(); }
Example 3
Source File: DemoServletsAdapterTest.java From keycloak with Apache License 2.0 | 5 votes |
private void expectResultOfClientNotAuthenticatedInClientSecretJwt(String targetClientId, String expectedErrorString) { RealmRepresentation realm = testRealmResource().toRepresentation(); realm.setEventsEnabled(true); realm.setEnabledEventTypes(Arrays.asList("LOGIN", "CODE_TO_TOKEN_ERROR")); realm.setEventsListeners(Arrays.asList("jboss-logging", "event-queue")); testRealmResource().update(realm); clientSecretJwtSecurePortal.navigateTo(); assertCurrentUrlStartsWithLoginUrlOf(testRealmPage); testRealmLoginPage.form().login("[email protected]", "password"); String userId = ApiUtil.findUserByUsername(testRealmResource(), "[email protected]").getId(); assertEvents.expectLogin() .realm(realm.getId()) .client(targetClientId) .user(userId) .detail(Details.USERNAME, "[email protected]") .detail(Details.CONSENT, Details.CONSENT_VALUE_NO_CONSENT_REQUIRED) .detail(Details.REDIRECT_URI, org.hamcrest.Matchers.anyOf(org.hamcrest.Matchers.equalTo(clientSecretJwtSecurePortal.getInjectedUrl().toString()), org.hamcrest.Matchers.equalTo(clientSecretJwtSecurePortal.getInjectedUrl().toString() + "/"))) .removeDetail(Details.CODE_ID) .assertEvent(); assertEvents.expectCodeToToken(null, null) .realm(realm.getId()) .client(targetClientId) .user((String)null) .error(expectedErrorString) .clearDetails() .assertEvent(); }
Example 4
Source File: LoginEventsTest.java From keycloak with Apache License 2.0 | 5 votes |
@Before public void beforeLoginEventsTest() { RealmRepresentation realm = testRealmResource().toRepresentation(); realm.setEventsEnabled(true); realm.setEnabledEventTypes(Arrays.asList("LOGIN", "LOGIN_ERROR", "LOGOUT")); testRealmResource().update(realm); }
Example 5
Source File: DemoServletsAdapterTest.java From keycloak with Apache License 2.0 | 4 votes |
@Test public void grantServerBasedApp() { ClientResource clientResource = ApiUtil.findClientResourceByClientId(testRealmResource(), "customer-portal"); ClientRepresentation client = clientResource.toRepresentation(); client.setConsentRequired(true); clientResource.update(client); RealmRepresentation realm = testRealmResource().toRepresentation(); realm.setEventsEnabled(true); realm.setEnabledEventTypes(Arrays.asList("REVOKE_GRANT", "LOGIN")); realm.setEventsListeners(Arrays.asList("jboss-logging", "event-queue")); testRealmResource().update(realm); customerPortal.navigateTo(); loginPage.form().login("[email protected]", "password"); assertTrue(oAuthGrantPage.isCurrent()); oAuthGrantPage.accept(); waitForPageToLoad(); assertLogged(); String userId = ApiUtil.findUserByUsername(testRealmResource(), "[email protected]").getId(); assertEvents.expectLogin() .realm(realm.getId()) .client("customer-portal") .user(userId) .detail(Details.USERNAME, "[email protected]") .detail(Details.CONSENT, Details.CONSENT_VALUE_CONSENT_GRANTED) .detail(Details.REDIRECT_URI, org.hamcrest.Matchers.anyOf(org.hamcrest.Matchers.equalTo(customerPortal.getInjectedUrl().toString()), org.hamcrest.Matchers.equalTo(customerPortal.getInjectedUrl().toString() + "/"))) .removeDetail(Details.CODE_ID) .assertEvent(); assertEvents.expectCodeToToken(null, null) .realm(realm.getId()) .client("customer-portal") .user(userId) .session(AssertEvents.isUUID()) .removeDetail(Details.CODE_ID) .assertEvent(); applicationsPage.navigateTo(); applicationsPage.revokeGrantForApplication("customer-portal"); customerPortal.navigateTo(); assertTrue(oAuthGrantPage.isCurrent()); assertEvents.expect(EventType.REVOKE_GRANT) .realm(realm.getId()) .client("account") .user(userId) .detail(Details.REVOKED_CLIENT, "customer-portal") .assertEvent(); assertEvents.assertEmpty(); // Revert consent client = clientResource.toRepresentation(); client.setConsentRequired(false); clientResource.update(client); }
Example 6
Source File: DemoServletsAdapterTest.java From keycloak with Apache License 2.0 | 4 votes |
@Test public void historyOfAccessResourceTest() throws IOException { RealmRepresentation realm = testRealmResource().toRepresentation(); realm.setEventsEnabled(true); realm.setEnabledEventTypes(Arrays.asList("LOGIN", "LOGIN_ERROR", "LOGOUT", "CODE_TO_TOKEN")); realm.setEventsListeners(Arrays.asList("jboss-logging", "event-queue")); testRealmResource().update(realm); customerPortal.navigateTo(); testRealmLoginPage.form().login("[email protected]", "password"); waitForPageToLoad(); assertLogged(); String userId = ApiUtil.findUserByUsername(testRealmResource(), "[email protected]").getId(); assertEvents.expectLogin() .realm(realm.getId()) .client("customer-portal") .user(userId) .detail(Details.USERNAME, "[email protected]") .detail(Details.CONSENT, Details.CONSENT_VALUE_NO_CONSENT_REQUIRED) .detail(Details.REDIRECT_URI, org.hamcrest.Matchers.anyOf(org.hamcrest.Matchers.equalTo(customerPortal.getInjectedUrl().toString()), org.hamcrest.Matchers.equalTo(customerPortal.getInjectedUrl().toString() + "/"))) .removeDetail(Details.CODE_ID) .assertEvent(); assertEvents.expectCodeToToken(null, null) .realm(realm.getId()) .client("customer-portal") .user(userId) .session(AssertEvents.isUUID()) .removeDetail(Details.CODE_ID) .assertEvent(); driver.navigate().to(testRealmPage.getOIDCLogoutUrl() + "?redirect_uri=" + customerPortal); assertCurrentUrlStartsWithLoginUrlOf(testRealmPage); assertEvents.expectLogout(null) .realm(realm.getId()) .user(userId) .session(AssertEvents.isUUID()) .detail(Details.REDIRECT_URI, org.hamcrest.Matchers.anyOf(org.hamcrest.Matchers.equalTo(customerPortal.getInjectedUrl().toString()), org.hamcrest.Matchers.equalTo(customerPortal.getInjectedUrl().toString() + "/"))) .assertEvent(); assertEvents.assertEmpty(); String serverLogPath = null; String appServer = System.getProperty("app.server"); if (appServer != null && (appServer.equals("wildfly") || appServer.equals("eap6") || appServer.equals("eap"))) { serverLogPath = System.getProperty("app.server.home") + "/standalone-test/log/server.log"; } String appServerUrl; if (Boolean.parseBoolean(System.getProperty("app.server.ssl.required"))) { appServerUrl = "https://localhost:" + System.getProperty("app.server.https.port", "8543") + "/"; } else { appServerUrl = "http://localhost:" + System.getProperty("app.server.http.port", "8280") + "/"; } if (serverLogPath != null) { log.info("Checking app server log at: " + serverLogPath); File serverLog = new File(serverLogPath); String serverLogContent = FileUtils.readFileToString(serverLog, "UTF-8"); UserRepresentation bburke = ApiUtil.findUserByUsername(testRealmResource(), "[email protected]"); //the expected log message has DEBUG level assertThat(serverLogContent, containsString("User '" + bburke.getId() + "' invoking '" + appServerUrl + "customer-db/' on client 'customer-db'")); } else { log.info("Checking app server log on app-server: \"" + System.getProperty("app.server") + "\" is not supported."); } }