use of org.keycloak.events.EventStoreProvider in project keycloak by keycloak.
the class AccountConsole method getMainPage.
@GET
@NoCache
public Response getMainPage() throws IOException, FreeMarkerException {
UriInfo uriInfo = session.getContext().getUri(UrlType.FRONTEND);
URI accountBaseUrl = uriInfo.getBaseUriBuilder().path(RealmsResource.class).path(realm.getName()).path(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID).path("/").build(realm);
if (!session.getContext().getUri().getRequestUri().getPath().endsWith("/")) {
UriBuilder redirectUri = session.getContext().getUri().getRequestUriBuilder().uri(accountBaseUrl);
return Response.status(302).location(redirectUri.build()).build();
} else {
Map<String, Object> map = new HashMap<>();
URI adminBaseUri = session.getContext().getUri(UrlType.ADMIN).getBaseUri();
URI authUrl = uriInfo.getBaseUri();
map.put("authUrl", authUrl.getPath().endsWith("/") ? authUrl : authUrl + "/");
map.put("baseUrl", accountBaseUrl);
map.put("realm", realm);
map.put("resourceUrl", Urls.themeRoot(authUrl).getPath() + "/" + Constants.ACCOUNT_MANAGEMENT_CLIENT_ID + "/" + theme.getName());
map.put("resourceCommonUrl", Urls.themeRoot(adminBaseUri).getPath() + "/common/keycloak");
map.put("resourceVersion", Version.RESOURCES_VERSION);
String[] referrer = getReferrer();
if (referrer != null) {
map.put("referrer", referrer[0]);
map.put("referrerName", referrer[1]);
map.put("referrer_uri", referrer[2]);
}
UserModel user = null;
if (auth != null)
user = auth.getUser();
Locale locale = session.getContext().resolveLocale(user);
map.put("locale", locale.toLanguageTag());
Properties messages = theme.getMessages(locale);
messages.putAll(realm.getRealmLocalizationTextsByLocale(locale.toLanguageTag()));
map.put("msg", new MessageFormatterMethod(locale, messages));
map.put("msgJSON", messagesToJsonString(messages));
map.put("supportedLocales", supportedLocales(messages));
map.put("properties", theme.getProperties());
map.put("theme", (Function<String, String>) file -> {
try {
final InputStream resource = theme.getResourceAsStream(file);
return new Scanner(resource, "UTF-8").useDelimiter("\\A").next();
} catch (IOException e) {
throw new RuntimeException("could not load file", e);
}
});
EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
map.put("isEventsEnabled", eventStore != null && realm.isEventsEnabled());
map.put("isAuthorizationEnabled", Profile.isFeatureEnabled(Profile.Feature.AUTHORIZATION));
boolean isTotpConfigured = false;
boolean deleteAccountAllowed = false;
if (user != null) {
isTotpConfigured = session.userCredentialManager().isConfiguredFor(realm, user, realm.getOTPPolicy().getType());
RoleModel deleteAccountRole = realm.getClientByClientId(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID).getRole(AccountRoles.DELETE_ACCOUNT);
deleteAccountAllowed = deleteAccountRole != null && user.hasRole(deleteAccountRole) && realm.getRequiredActionProviderByAlias(DeleteAccount.PROVIDER_ID).isEnabled();
}
map.put("isTotpConfigured", isTotpConfigured);
map.put("deleteAccountAllowed", deleteAccountAllowed);
FreeMarkerUtil freeMarkerUtil = new FreeMarkerUtil();
String result = freeMarkerUtil.processTemplate(map, "index.ftl", theme);
Response.ResponseBuilder builder = Response.status(Response.Status.OK).type(MediaType.TEXT_HTML_UTF_8).language(Locale.ENGLISH).entity(result);
return builder.build();
}
}
use of org.keycloak.events.EventStoreProvider in project keycloak by keycloak.
the class TestingResourceProvider method clearEventStore.
@GET
@Path("/clear-event-store")
@Produces(MediaType.APPLICATION_JSON)
public Response clearEventStore() {
EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
eventStore.clear();
return Response.noContent().build();
}
use of org.keycloak.events.EventStoreProvider in project keycloak by keycloak.
the class AdminEventQueryTest method testClear.
@Test
public void testClear() {
inRolledBackTransaction(null, (session, t) -> {
EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
eventStore.clear();
});
}
use of org.keycloak.events.EventStoreProvider in project keycloak by keycloak.
the class TestingResourceProvider method onAdminEvent.
@POST
@Path("/on-admin-event")
@Consumes(MediaType.APPLICATION_JSON)
public void onAdminEvent(final AdminEventRepresentation rep, @QueryParam("includeRepresentation") boolean includeRepresentation) {
EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
eventStore.onEvent(repToModel(rep), includeRepresentation);
}
use of org.keycloak.events.EventStoreProvider in project keycloak by keycloak.
the class TestingResourceProvider method onEvent.
@PUT
@Path("/on-event")
@Consumes(MediaType.APPLICATION_JSON)
public void onEvent(final EventRepresentation rep) {
EventStoreProvider eventStore = session.getProvider(EventStoreProvider.class);
eventStore.onEvent(repToModel(rep));
}
Aggregations