diff --git a/examples/README.md b/examples/README.md index 5637f1005f..ecd1b8e8c5 100755 --- a/examples/README.md +++ b/examples/README.md @@ -43,8 +43,6 @@ Providers Example providers for Event Listener SPI, Event Store SPI and User Federation SPI. For more information look at: -* Event Listener that outputs event detalis to sysout - `providers/event-listener-sysout/README.md` -* Event Store that stores events in memory - `providers/event-store-mem/README.md` * User Federation that loads users from a text file - `providers/federation-provider/README.md` diff --git a/examples/providers/authenticator/README.md b/examples/providers/authenticator/README.md deleted file mode 100755 index ef612cc2a7..0000000000 --- a/examples/providers/authenticator/README.md +++ /dev/null @@ -1,23 +0,0 @@ -Example Custom Authenticator -=================================================== - -1. First, Keycloak must be running. - -2. Execute the follow. This will build the example and deploy it - - $ mvn clean install wildfly:deploy - -3. Copy the secret-question.ftl and secret-question-config.ftl files to the themes/base/login directory. - -4. Login to admin console. Hit browser refresh if you are already logged in so that the new providers show up. - -5. Go to the Authentication menu item and go to the Flow tab, you will be able to view the currently - defined flows. You cannot modify an built in flows, so, to add the Authenticator you - have to copy an existing flow or create your own. Copy the "Browser" flow. - -6. In your copy, click the "Actions" menu item and "Add Execution". Pick Secret Question - -7. Next you have to register the required action that you created. Click on the Required Actions tab in the Authenticaiton menu. - Click on the Register button and choose your new Required Action. - Your new required action should now be displayed and enabled in the required actions list. - diff --git a/examples/providers/authenticator/pom.xml b/examples/providers/authenticator/pom.xml deleted file mode 100755 index 49f1fd3029..0000000000 --- a/examples/providers/authenticator/pom.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - keycloak-examples-providers-parent - org.keycloak - 4.8.0.Final-SNAPSHOT - - - Authenticator Example - - 4.0.0 - - authenticator-required-action-example - jar - - - - org.keycloak - keycloak-core - provided - - - org.keycloak - keycloak-server-spi - provided - - - org.keycloak - keycloak-server-spi-private - provided - - - org.jboss.logging - jboss-logging - provided - - - org.keycloak - keycloak-services - provided - - - - - authenticator-required-action-example - - - org.wildfly.plugins - wildfly-maven-plugin - - false - - - - - diff --git a/examples/providers/authenticator/secret-question-config.ftl b/examples/providers/authenticator/secret-question-config.ftl deleted file mode 100755 index 54e69026b0..0000000000 --- a/examples/providers/authenticator/secret-question-config.ftl +++ /dev/null @@ -1,33 +0,0 @@ -<#import "template.ftl" as layout> -<@layout.registrationLayout; section> - <#if section = "title"> - ${msg("loginTitle",realm.name)} - <#elseif section = "header"> - Setup Secret Question - <#elseif section = "form"> -
-
-
- -
- -
- -
-
- -
-
-
-
-
- -
-
- -
-
-
-
- - \ No newline at end of file diff --git a/examples/providers/authenticator/secret-question.ftl b/examples/providers/authenticator/secret-question.ftl deleted file mode 100755 index b69c5206a2..0000000000 --- a/examples/providers/authenticator/secret-question.ftl +++ /dev/null @@ -1,34 +0,0 @@ -<#import "template.ftl" as layout> -<@layout.registrationLayout; section> - <#if section = "title"> - ${msg("loginTitle",realm.name)} - <#elseif section = "header"> - ${msg("loginTitleHtml",realm.name)} - <#elseif section = "form"> -
-
-
- -
- -
- -
-
- -
-
-
-
-
- -
-
- - -
-
-
-
- - \ No newline at end of file diff --git a/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionAuthenticator.java b/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionAuthenticator.java deleted file mode 100755 index 73d821fbcd..0000000000 --- a/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionAuthenticator.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.examples.authenticator; - -import org.jboss.resteasy.spi.HttpResponse; -import org.jboss.resteasy.spi.ResteasyProviderFactory; -import org.keycloak.authentication.AuthenticationFlowContext; -import org.keycloak.authentication.AuthenticationFlowError; -import org.keycloak.authentication.Authenticator; -import org.keycloak.common.util.ServerCookie; -import org.keycloak.models.AuthenticatorConfigModel; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.RealmModel; -import org.keycloak.models.UserCredentialModel; -import org.keycloak.models.UserModel; - -import javax.ws.rs.core.Cookie; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.Response; -import java.net.URI; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class SecretQuestionAuthenticator implements Authenticator { - - public static final String CREDENTIAL_TYPE = "secret_question"; - - protected boolean hasCookie(AuthenticationFlowContext context) { - Cookie cookie = context.getHttpRequest().getHttpHeaders().getCookies().get("SECRET_QUESTION_ANSWERED"); - boolean result = cookie != null; - if (result) { - System.out.println("Bypassing secret question because cookie is set"); - } - return result; - } - - @Override - public void authenticate(AuthenticationFlowContext context) { - if (hasCookie(context)) { - context.success(); - return; - } - Response challenge = context.form().createForm("secret-question.ftl"); - context.challenge(challenge); - } - - @Override - public void action(AuthenticationFlowContext context) { - MultivaluedMap formData = context.getHttpRequest().getDecodedFormParameters(); - if (formData.containsKey("cancel")) { - context.cancelLogin(); - return; - } - boolean validated = validateAnswer(context); - if (!validated) { - Response challenge = context.form() - .setError("badSecret") - .createForm("secret-question.ftl"); - context.failureChallenge(AuthenticationFlowError.INVALID_CREDENTIALS, challenge); - return; - } - setCookie(context); - context.success(); - } - - protected void setCookie(AuthenticationFlowContext context) { - AuthenticatorConfigModel config = context.getAuthenticatorConfig(); - int maxCookieAge = 60 * 60 * 24 * 30; // 30 days - if (config != null) { - maxCookieAge = Integer.valueOf(config.getConfig().get("cookie.max.age")); - - } - URI uri = context.getUriInfo().getBaseUriBuilder().path("realms").path(context.getRealm().getName()).build(); - addCookie("SECRET_QUESTION_ANSWERED", "true", - uri.getRawPath(), - null, null, - maxCookieAge, - false, true); - } - - public static void addCookie(String name, String value, String path, String domain, String comment, int maxAge, boolean secure, boolean httpOnly) { - HttpResponse response = ResteasyProviderFactory.getContextData(HttpResponse.class); - StringBuffer cookieBuf = new StringBuffer(); - ServerCookie.appendCookieValue(cookieBuf, 1, name, value, path, domain, comment, maxAge, secure, httpOnly); - String cookie = cookieBuf.toString(); - response.getOutputHeaders().add(HttpHeaders.SET_COOKIE, cookie); - } - - - protected boolean validateAnswer(AuthenticationFlowContext context) { - MultivaluedMap formData = context.getHttpRequest().getDecodedFormParameters(); - String secret = formData.getFirst("secret_answer"); - UserCredentialModel input = new UserCredentialModel(); - input.setType(SecretQuestionCredentialProvider.SECRET_QUESTION); - input.setValue(secret); - return context.getSession().userCredentialManager().isValid(context.getRealm(), context.getUser(), input); - } - - @Override - public boolean requiresUser() { - return true; - } - - @Override - public boolean configuredFor(KeycloakSession session, RealmModel realm, UserModel user) { - return session.userCredentialManager().isConfiguredFor(realm, user, SecretQuestionCredentialProvider.SECRET_QUESTION); - } - - @Override - public void setRequiredActions(KeycloakSession session, RealmModel realm, UserModel user) { - user.addRequiredAction(SecretQuestionRequiredAction.PROVIDER_ID); - } - - @Override - public void close() { - - } -} diff --git a/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionAuthenticatorFactory.java b/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionAuthenticatorFactory.java deleted file mode 100755 index 77c93b6e23..0000000000 --- a/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionAuthenticatorFactory.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.examples.authenticator; - -import org.keycloak.Config; -import org.keycloak.authentication.Authenticator; -import org.keycloak.authentication.AuthenticatorFactory; -import org.keycloak.authentication.ConfigurableAuthenticatorFactory; -import org.keycloak.models.AuthenticationExecutionModel; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.KeycloakSessionFactory; -import org.keycloak.provider.ProviderConfigProperty; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class SecretQuestionAuthenticatorFactory implements AuthenticatorFactory, ConfigurableAuthenticatorFactory { - - public static final String PROVIDER_ID = "secret-question-authenticator"; - private static final SecretQuestionAuthenticator SINGLETON = new SecretQuestionAuthenticator(); - - @Override - public String getId() { - return PROVIDER_ID; - } - - @Override - public Authenticator create(KeycloakSession session) { - return SINGLETON; - } - - private static AuthenticationExecutionModel.Requirement[] REQUIREMENT_CHOICES = { - AuthenticationExecutionModel.Requirement.REQUIRED, - AuthenticationExecutionModel.Requirement.DISABLED - }; - @Override - public AuthenticationExecutionModel.Requirement[] getRequirementChoices() { - return REQUIREMENT_CHOICES; - } - - @Override - public boolean isUserSetupAllowed() { - return true; - } - - @Override - public boolean isConfigurable() { - return true; - } - - @Override - public List getConfigProperties() { - return configProperties; - } - - private static final List configProperties = new ArrayList(); - - static { - ProviderConfigProperty property; - property = new ProviderConfigProperty(); - property.setName("cookie.max.age"); - property.setLabel("Cookie Max Age"); - property.setType(ProviderConfigProperty.STRING_TYPE); - property.setHelpText("Max age in seconds of the SECRET_QUESTION_COOKIE."); - configProperties.add(property); - } - - - @Override - public String getHelpText() { - return "A secret question that a user has to answer. i.e. What is your mother's maiden name."; - } - - @Override - public String getDisplayType() { - return "Secret Question"; - } - - @Override - public String getReferenceCategory() { - return "Secret Question"; - } - - @Override - public void init(Config.Scope config) { - - } - - @Override - public void postInit(KeycloakSessionFactory factory) { - - } - - @Override - public void close() { - - } - - -} diff --git a/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionCredentialProvider.java b/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionCredentialProvider.java deleted file mode 100644 index 76b3239ea9..0000000000 --- a/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionCredentialProvider.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.keycloak.examples.authenticator; - -import org.keycloak.common.util.Time; -import org.keycloak.credential.CredentialInput; -import org.keycloak.credential.CredentialInputUpdater; -import org.keycloak.credential.CredentialInputValidator; -import org.keycloak.credential.CredentialModel; -import org.keycloak.credential.CredentialProvider; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.RealmModel; -import org.keycloak.models.UserCredentialModel; -import org.keycloak.models.UserModel; -import org.keycloak.models.cache.CachedUserModel; -import org.keycloak.models.cache.OnUserCache; - -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class SecretQuestionCredentialProvider implements CredentialProvider, CredentialInputValidator, CredentialInputUpdater, OnUserCache { - public static final String SECRET_QUESTION = "SECRET_QUESTION"; - public static final String CACHE_KEY = SecretQuestionCredentialProvider.class.getName() + "." + SECRET_QUESTION; - - protected KeycloakSession session; - - public SecretQuestionCredentialProvider(KeycloakSession session) { - this.session = session; - } - - public CredentialModel getSecret(RealmModel realm, UserModel user) { - CredentialModel secret = null; - if (user instanceof CachedUserModel) { - CachedUserModel cached = (CachedUserModel)user; - secret = (CredentialModel)cached.getCachedWith().get(CACHE_KEY); - - } else { - List creds = session.userCredentialManager().getStoredCredentialsByType(realm, user, SECRET_QUESTION); - if (!creds.isEmpty()) secret = creds.get(0); - } - return secret; - } - - - @Override - public boolean updateCredential(RealmModel realm, UserModel user, CredentialInput input) { - if (!SECRET_QUESTION.equals(input.getType())) return false; - if (!(input instanceof UserCredentialModel)) return false; - UserCredentialModel credInput = (UserCredentialModel) input; - List creds = session.userCredentialManager().getStoredCredentialsByType(realm, user, SECRET_QUESTION); - if (creds.isEmpty()) { - CredentialModel secret = new CredentialModel(); - secret.setType(SECRET_QUESTION); - secret.setValue(credInput.getValue()); - secret.setCreatedDate(Time.currentTimeMillis()); - session.userCredentialManager().createCredential(realm ,user, secret); - } else { - creds.get(0).setValue(credInput.getValue()); - session.userCredentialManager().updateCredential(realm, user, creds.get(0)); - } - session.userCache().evict(realm, user); - return true; - } - - @Override - public void disableCredentialType(RealmModel realm, UserModel user, String credentialType) { - if (!SECRET_QUESTION.equals(credentialType)) return; - - List credentials = session.userCredentialManager().getStoredCredentialsByType(realm, user, SECRET_QUESTION); - for (CredentialModel cred : credentials) { - session.userCredentialManager().removeStoredCredential(realm, user, cred.getId()); - } - session.userCache().evict(realm, user); - } - - @Override - public Set getDisableableCredentialTypes(RealmModel realm, UserModel user) { - if (!session.userCredentialManager().getStoredCredentialsByType(realm, user, SECRET_QUESTION).isEmpty()) { - Set set = new HashSet<>(); - set.add(SECRET_QUESTION); - return set; - } else { - return Collections.EMPTY_SET; - } - - } - - @Override - public boolean supportsCredentialType(String credentialType) { - return SECRET_QUESTION.equals(credentialType); - } - - @Override - public boolean isConfiguredFor(RealmModel realm, UserModel user, String credentialType) { - if (!SECRET_QUESTION.equals(credentialType)) return false; - return getSecret(realm, user) != null; - } - - @Override - public boolean isValid(RealmModel realm, UserModel user, CredentialInput input) { - if (!SECRET_QUESTION.equals(input.getType())) return false; - if (!(input instanceof UserCredentialModel)) return false; - - String secret = getSecret(realm, user).getValue(); - - return secret != null && ((UserCredentialModel)input).getValue().equals(secret); - } - - @Override - public void onCache(RealmModel realm, CachedUserModel user, UserModel delegate) { - List creds = session.userCredentialManager().getStoredCredentialsByType(realm, user, SECRET_QUESTION); - if (!creds.isEmpty()) user.getCachedWith().put(CACHE_KEY, creds.get(0)); - } -} diff --git a/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionCredentialProviderFactory.java b/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionCredentialProviderFactory.java deleted file mode 100644 index 98b65ae9df..0000000000 --- a/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionCredentialProviderFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.keycloak.examples.authenticator; - -import org.keycloak.credential.CredentialProvider; -import org.keycloak.credential.CredentialProviderFactory; -import org.keycloak.models.KeycloakSession; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class SecretQuestionCredentialProviderFactory implements CredentialProviderFactory { - @Override - public String getId() { - return "secret-question"; - } - - @Override - public CredentialProvider create(KeycloakSession session) { - return new SecretQuestionCredentialProvider(session); - } -} diff --git a/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionRequiredAction.java b/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionRequiredAction.java deleted file mode 100755 index cc1425e742..0000000000 --- a/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionRequiredAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.examples.authenticator; - -import org.keycloak.authentication.RequiredActionContext; -import org.keycloak.authentication.RequiredActionProvider; -import org.keycloak.models.UserCredentialModel; - -import javax.ws.rs.core.Response; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class SecretQuestionRequiredAction implements RequiredActionProvider { - public static final String PROVIDER_ID = "secret_question_config"; - - @Override - public void evaluateTriggers(RequiredActionContext context) { - - } - - @Override - public void requiredActionChallenge(RequiredActionContext context) { - Response challenge = context.form().createForm("secret-question-config.ftl"); - context.challenge(challenge); - - } - - @Override - public void processAction(RequiredActionContext context) { - String answer = (context.getHttpRequest().getDecodedFormParameters().getFirst("secret_answer")); - UserCredentialModel input = new UserCredentialModel(); - input.setType(SecretQuestionCredentialProvider.SECRET_QUESTION); - input.setValue(answer); - context.getSession().userCredentialManager().updateCredential(context.getRealm(), context.getUser(), input); - context.success(); - } - - @Override - public void close() { - - } -} diff --git a/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionRequiredActionFactory.java b/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionRequiredActionFactory.java deleted file mode 100755 index 46ad4ebc75..0000000000 --- a/examples/providers/authenticator/src/main/java/org/keycloak/examples/authenticator/SecretQuestionRequiredActionFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.examples.authenticator; - -import org.keycloak.Config; -import org.keycloak.authentication.RequiredActionFactory; -import org.keycloak.authentication.RequiredActionProvider; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.KeycloakSessionFactory; - -/** - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class SecretQuestionRequiredActionFactory implements RequiredActionFactory { - - private static final SecretQuestionRequiredAction SINGLETON = new SecretQuestionRequiredAction(); - - @Override - public RequiredActionProvider create(KeycloakSession session) { - return SINGLETON; - } - - - @Override - public String getId() { - return SecretQuestionRequiredAction.PROVIDER_ID; - } - - @Override - public String getDisplayText() { - return "Secret Question"; - } - - @Override - public void init(Config.Scope config) { - - } - - @Override - public void postInit(KeycloakSessionFactory factory) { - - } - - @Override - public void close() { - - } - -} diff --git a/examples/providers/authenticator/src/main/resources/META-INF/services/org.keycloak.authentication.AuthenticatorFactory b/examples/providers/authenticator/src/main/resources/META-INF/services/org.keycloak.authentication.AuthenticatorFactory deleted file mode 100755 index f288d3daa9..0000000000 --- a/examples/providers/authenticator/src/main/resources/META-INF/services/org.keycloak.authentication.AuthenticatorFactory +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright 2016 Red Hat, Inc. and/or its affiliates -# and other contributors as indicated by the @author tags. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -org.keycloak.examples.authenticator.SecretQuestionAuthenticatorFactory \ No newline at end of file diff --git a/examples/providers/authenticator/src/main/resources/META-INF/services/org.keycloak.authentication.RequiredActionFactory b/examples/providers/authenticator/src/main/resources/META-INF/services/org.keycloak.authentication.RequiredActionFactory deleted file mode 100755 index 034c2f17c2..0000000000 --- a/examples/providers/authenticator/src/main/resources/META-INF/services/org.keycloak.authentication.RequiredActionFactory +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright 2016 Red Hat, Inc. and/or its affiliates -# and other contributors as indicated by the @author tags. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -org.keycloak.examples.authenticator.SecretQuestionRequiredActionFactory \ No newline at end of file diff --git a/examples/providers/authenticator/src/main/resources/META-INF/services/org.keycloak.credential.CredentialProviderFactory b/examples/providers/authenticator/src/main/resources/META-INF/services/org.keycloak.credential.CredentialProviderFactory deleted file mode 100644 index a221e371cc..0000000000 --- a/examples/providers/authenticator/src/main/resources/META-INF/services/org.keycloak.credential.CredentialProviderFactory +++ /dev/null @@ -1 +0,0 @@ - org.keycloak.examples.authenticator.SecretQuestionCredentialProviderFactory \ No newline at end of file diff --git a/examples/providers/event-listener-sysout/README.md b/examples/providers/event-listener-sysout/README.md deleted file mode 100644 index 5540d9b25c..0000000000 --- a/examples/providers/event-listener-sysout/README.md +++ /dev/null @@ -1,29 +0,0 @@ -Example Event Listener that prints events to System.out -======================================================= - -To deploy copy target/event-listener-sysout-example.jar to providers directory. Alternatively you can deploy as a module by running: - - KEYCLOAK_HOME/bin/jboss-cli.sh --command="module add --name=org.keycloak.examples.event-sysout --resources=target/event-listener-sysout-example.jar --dependencies=org.keycloak.keycloak-core,org.keycloak.keycloak-server-spi,org.keycloak.keycloak-server-spi-private" - -Then registering the provider by editing `standalone/configuration/standalone.xml` and adding the module to the providers element: - - - ... - module:org.keycloak.examples.event-sysout - - -Then start (or restart) the server. Once started open the admin console, select your realm, then click on Events, -followed by config. Click on Listeners select box, then pick sysout from the dropdown. After this try to logout and -login again to see events printed to System.out. - -The example event listener can be configured to exclude certain events, for example to exclude REFRESH_TOKEN and -CODE_TO_TOKEN events add the following to `standalone.xml`: - - ... - - - - - - diff --git a/examples/providers/event-listener-sysout/pom.xml b/examples/providers/event-listener-sysout/pom.xml deleted file mode 100755 index 5c34613f55..0000000000 --- a/examples/providers/event-listener-sysout/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - keycloak-examples-providers-parent - org.keycloak - 4.8.0.Final-SNAPSHOT - - - Event Listener System.out Example - - 4.0.0 - - event-listener-sysout-example - jar - - - - org.keycloak - keycloak-core - - - org.keycloak - keycloak-server-spi - provided - - - org.keycloak - keycloak-server-spi-private - provided - - - - - event-listener-sysout-example - - diff --git a/examples/providers/event-listener-sysout/src/main/java/org/keycloak/examples/providers/events/SysoutEventListenerProvider.java b/examples/providers/event-listener-sysout/src/main/java/org/keycloak/examples/providers/events/SysoutEventListenerProvider.java deleted file mode 100755 index 91d2a3067d..0000000000 --- a/examples/providers/event-listener-sysout/src/main/java/org/keycloak/examples/providers/events/SysoutEventListenerProvider.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.examples.providers.events; - -import org.keycloak.events.Event; -import org.keycloak.events.EventListenerProvider; -import org.keycloak.events.EventType; -import org.keycloak.events.admin.AdminEvent; -import org.keycloak.events.admin.OperationType; - -import java.util.Map; -import java.util.Set; - -/** - * @author Stian Thorgersen - */ -public class SysoutEventListenerProvider implements EventListenerProvider { - - private Set excludedEvents; - private Set excludedAdminOperations; - - public SysoutEventListenerProvider(Set excludedEvents, Set excludedAdminOpearations) { - this.excludedEvents = excludedEvents; - this.excludedAdminOperations = excludedAdminOpearations; - } - - @Override - public void onEvent(Event event) { - // Ignore excluded events - if (excludedEvents != null && excludedEvents.contains(event.getType())) { - return; - } else { - System.out.println("EVENT: " + toString(event)); - } - } - - @Override - public void onEvent(AdminEvent event, boolean includeRepresentation) { - // Ignore excluded operations - if (excludedAdminOperations != null && excludedAdminOperations.contains(event.getOperationType())) { - return; - } else { - System.out.println("EVENT: " + toString(event)); - } - } - - private String toString(Event event) { - StringBuilder sb = new StringBuilder(); - - sb.append("type="); - sb.append(event.getType()); - sb.append(", realmId="); - sb.append(event.getRealmId()); - sb.append(", clientId="); - sb.append(event.getClientId()); - sb.append(", userId="); - sb.append(event.getUserId()); - sb.append(", ipAddress="); - sb.append(event.getIpAddress()); - - if (event.getError() != null) { - sb.append(", error="); - sb.append(event.getError()); - } - - if (event.getDetails() != null) { - for (Map.Entry e : event.getDetails().entrySet()) { - sb.append(", "); - sb.append(e.getKey()); - if (e.getValue() == null || e.getValue().indexOf(' ') == -1) { - sb.append("="); - sb.append(e.getValue()); - } else { - sb.append("='"); - sb.append(e.getValue()); - sb.append("'"); - } - } - } - - return sb.toString(); - } - - private String toString(AdminEvent adminEvent) { - StringBuilder sb = new StringBuilder(); - - sb.append("operationType="); - sb.append(adminEvent.getOperationType()); - sb.append(", realmId="); - sb.append(adminEvent.getAuthDetails().getRealmId()); - sb.append(", clientId="); - sb.append(adminEvent.getAuthDetails().getClientId()); - sb.append(", userId="); - sb.append(adminEvent.getAuthDetails().getUserId()); - sb.append(", ipAddress="); - sb.append(adminEvent.getAuthDetails().getIpAddress()); - sb.append(", resourcePath="); - sb.append(adminEvent.getResourcePath()); - - if (adminEvent.getError() != null) { - sb.append(", error="); - sb.append(adminEvent.getError()); - } - - return sb.toString(); - } - - @Override - public void close() { - } - -} diff --git a/examples/providers/event-listener-sysout/src/main/java/org/keycloak/examples/providers/events/SysoutEventListenerProviderFactory.java b/examples/providers/event-listener-sysout/src/main/java/org/keycloak/examples/providers/events/SysoutEventListenerProviderFactory.java deleted file mode 100755 index a6b6502faa..0000000000 --- a/examples/providers/event-listener-sysout/src/main/java/org/keycloak/examples/providers/events/SysoutEventListenerProviderFactory.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.examples.providers.events; - -import org.keycloak.Config; -import org.keycloak.events.EventListenerProvider; -import org.keycloak.events.EventListenerProviderFactory; -import org.keycloak.events.EventType; -import org.keycloak.events.admin.OperationType; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.KeycloakSessionFactory; - -import java.util.HashSet; -import java.util.Set; - -/** - * @author Stian Thorgersen - */ -public class SysoutEventListenerProviderFactory implements EventListenerProviderFactory { - - private Set excludedEvents; - private Set excludedAdminOperations; - - @Override - public EventListenerProvider create(KeycloakSession session) { - return new SysoutEventListenerProvider(excludedEvents, excludedAdminOperations); - } - - @Override - public void init(Config.Scope config) { - String[] excludes = config.getArray("exclude-events"); - if (excludes != null) { - excludedEvents = new HashSet<>(); - for (String e : excludes) { - excludedEvents.add(EventType.valueOf(e)); - } - } - - String[] excludesOperations = config.getArray("excludesOperations"); - if (excludesOperations != null) { - excludedAdminOperations = new HashSet<>(); - for (String e : excludesOperations) { - excludedAdminOperations.add(OperationType.valueOf(e)); - } - } - } - - @Override - public void postInit(KeycloakSessionFactory factory) { - - } - @Override - public void close() { - } - - @Override - public String getId() { - return "sysout"; - } - -} diff --git a/examples/providers/event-listener-sysout/src/main/resources/META-INF/services/org.keycloak.events.EventListenerProviderFactory b/examples/providers/event-listener-sysout/src/main/resources/META-INF/services/org.keycloak.events.EventListenerProviderFactory deleted file mode 100644 index a0ee81c449..0000000000 --- a/examples/providers/event-listener-sysout/src/main/resources/META-INF/services/org.keycloak.events.EventListenerProviderFactory +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright 2016 Red Hat, Inc. and/or its affiliates -# and other contributors as indicated by the @author tags. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -org.keycloak.examples.providers.events.SysoutEventListenerProviderFactory \ No newline at end of file diff --git a/examples/providers/event-store-mem/README.md b/examples/providers/event-store-mem/README.md deleted file mode 100644 index 2c55109190..0000000000 --- a/examples/providers/event-store-mem/README.md +++ /dev/null @@ -1,29 +0,0 @@ -Example Event Store that stores events in memory -================================================ - -To deploy copy target/event-store-mem-example.jar to providers directory. Alternatively you can deploy as a module by running: - - KEYCLOAK_HOME/bin/jboss-cli.sh --command="module add --name=org.keycloak.examples.event-inmem --resources=target/event-store-mem-example.jar --dependencies=org.keycloak.keycloak-core,org.keycloak.keycloak-server-spi,org.keycloak.keycloak-server-spi-private" - -Then registering the provider by editing `standalone/configuration/standalone.xml` and adding the module to the providers element: - - - ... - module:org.keycloak.examples.event-inmem - - -Then edit `standalone/configuration/standalone.xml`, change: - - - jpa - - -to: - - - in-mem - - -Then start (or restart)the server. Once started open the admin console, select your realm, then click on Events, -followed by config. Set the toggle for Enabled to ON. After this try to logout and login again then open the Events tab -again in the admin console to view events from the in-mem provider. diff --git a/examples/providers/event-store-mem/pom.xml b/examples/providers/event-store-mem/pom.xml deleted file mode 100755 index 3e41b78532..0000000000 --- a/examples/providers/event-store-mem/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - keycloak-examples-providers-parent - org.keycloak - 4.8.0.Final-SNAPSHOT - - - Event Store In-Mem Example - - 4.0.0 - - event-store-mem-example - jar - - - - org.keycloak - keycloak-core - - - org.keycloak - keycloak-server-spi - provided - - - org.keycloak - keycloak-server-spi-private - provided - - - - - event-store-mem-example - - diff --git a/examples/providers/event-store-mem/src/main/java/org/keycloak/examples/providers/events/MemAdminEventQuery.java b/examples/providers/event-store-mem/src/main/java/org/keycloak/examples/providers/events/MemAdminEventQuery.java deleted file mode 100755 index 7736fb7d0f..0000000000 --- a/examples/providers/event-store-mem/src/main/java/org/keycloak/examples/providers/events/MemAdminEventQuery.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.examples.providers.events; - -import org.keycloak.events.admin.AdminEvent; -import org.keycloak.events.admin.AdminEventQuery; -import org.keycloak.events.admin.OperationType; -import org.keycloak.events.admin.ResourceType; - -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.regex.Pattern; - -/** - * @author Giriraj Sharma - */ -public class MemAdminEventQuery implements AdminEventQuery { - - private List adminEvents; - - private int first; - private int max; - - public MemAdminEventQuery(List events) { - this.adminEvents = events; - } - - - @Override - public AdminEventQuery realm(String realmId) { - Iterator itr = adminEvents.iterator(); - while (itr.hasNext()) { - if (!itr.next().getRealmId().equals(realmId)) { - itr.remove(); - } - } - return this; - } - - @Override - public AdminEventQuery operation(OperationType... operations) { - Iterator itr = this.adminEvents.iterator(); - while (itr.hasNext()) { - AdminEvent next = itr.next(); - boolean include = false; - for (OperationType e : operations) { - if (next.getOperationType().equals(e)) { - include = true; - break; - } - } - if (!include) { - itr.remove(); - } - } - return this; - } - - @Override - public AdminEventQuery resourceType(ResourceType... resourceTypes) { - - Iterator itr = this.adminEvents.iterator(); - while (itr.hasNext()) { - AdminEvent next = itr.next(); - boolean include = false; - for (ResourceType e : resourceTypes) { - if (next.getResourceType().equals(e)) { - include = true; - break; - } - } - if (!include) { - itr.remove(); - } - } - - return this; - } - - @Override - public AdminEventQuery authRealm(String authRealmId) { - Iterator itr = adminEvents.iterator(); - while (itr.hasNext()) { - if (!itr.next().getAuthDetails().getRealmId().equals(authRealmId)) { - itr.remove(); - } - } - return this; - } - - @Override - public AdminEventQuery authClient(String authClientId) { - Iterator itr = adminEvents.iterator(); - while (itr.hasNext()) { - if (!itr.next().getAuthDetails().getClientId().equals(authClientId)) { - itr.remove(); - } - } - return this; - } - - @Override - public AdminEventQuery authUser(String authUserId) { - Iterator itr = adminEvents.iterator(); - while (itr.hasNext()) { - if (!itr.next().getAuthDetails().getUserId().equals(authUserId)) { - itr.remove(); - } - } - return this; - } - - @Override - public AdminEventQuery authIpAddress(String ipAddress) { - Iterator itr = adminEvents.iterator(); - while (itr.hasNext()) { - if (!itr.next().getAuthDetails().getIpAddress().equals(ipAddress)) { - itr.remove(); - } - } - return this; - } - - @Override - public AdminEventQuery resourcePath(String resourcePath) { - Iterator itr = this.adminEvents.iterator(); - while (itr.hasNext()) { - if(!Pattern.compile(resourcePath).matcher(itr.next().getResourcePath()).find()) { - itr.remove(); - } - } - return (AdminEventQuery) this; - } - - @Override - public AdminEventQuery fromTime(Date fromTime) { - Iterator itr = this.adminEvents.iterator(); - while (itr.hasNext()) { - if (!(itr.next().getTime() >= fromTime.getTime())) { - itr.remove(); - } - } - return this; - } - - @Override - public AdminEventQuery toTime(Date toTime) { - Iterator itr = this.adminEvents.iterator(); - while (itr.hasNext()) { - if (!(itr.next().getTime() <= toTime.getTime())) { - itr.remove(); - } - } - return this; - } - - @Override - public AdminEventQuery firstResult(int result) { - this.first = result; - return this; - } - - @Override - public AdminEventQuery maxResults(int results) { - this.max = results; - return this; - } - - @Override - public List getResultList() { - if (adminEvents.size() < first) { - return Collections.emptyList(); - } - int end = first + max <= adminEvents.size() ? first + max : adminEvents.size(); - - return adminEvents.subList(first, end); - } - -} diff --git a/examples/providers/event-store-mem/src/main/java/org/keycloak/examples/providers/events/MemEventQuery.java b/examples/providers/event-store-mem/src/main/java/org/keycloak/examples/providers/events/MemEventQuery.java deleted file mode 100755 index 293cdda20b..0000000000 --- a/examples/providers/event-store-mem/src/main/java/org/keycloak/examples/providers/events/MemEventQuery.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.examples.providers.events; - -import org.keycloak.events.Event; -import org.keycloak.events.EventQuery; -import org.keycloak.events.EventType; - -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -/** - * @author Stian Thorgersen - */ -public class MemEventQuery implements EventQuery { - - private List events; - - private int first; - private int max; - - public MemEventQuery(List events) { - this.events = events; - } - - @Override - public EventQuery type(EventType... types) { - Iterator itr = this.events.iterator(); - while (itr.hasNext()) { - Event next = itr.next(); - boolean include = false; - for (EventType e : types) { - if (next.getType().equals(e)) { - include = true; - break; - } - } - if (!include) { - itr.remove(); - } - } - return this; - } - - @Override - public EventQuery realm(String realmId) { - Iterator itr = this.events.iterator(); - while (itr.hasNext()) { - if (!itr.next().getRealmId().equals(realmId)) { - itr.remove(); - } - } - return this; - } - - @Override - public EventQuery client(String clientId) { - Iterator itr = this.events.iterator(); - while (itr.hasNext()) { - if (!itr.next().getClientId().equals(clientId)) { - itr.remove(); - } - } - return this; - } - - @Override - public EventQuery user(String userId) { - Iterator itr = this.events.iterator(); - while (itr.hasNext()) { - if (!itr.next().getUserId().equals(userId)) { - itr.remove(); - } - } - return this; - } - - @Override - public EventQuery fromDate(Date fromDate) { - Iterator itr = this.events.iterator(); - while (itr.hasNext()) { - if (!(itr.next().getTime() >= fromDate.getTime())) { - itr.remove(); - } - } - return this; - } - - @Override - public EventQuery toDate(Date toDate) { - Iterator itr = this.events.iterator(); - while (itr.hasNext()) { - if (!(itr.next().getTime() <= toDate.getTime())) { - itr.remove(); - } - } - return this; - } - - @Override - public EventQuery ipAddress(String ipAddress) { - Iterator itr = this.events.iterator(); - while (itr.hasNext()) { - if (!itr.next().getIpAddress().equals(ipAddress)) { - itr.remove(); - } - } - return this; - } - - @Override - public EventQuery firstResult(int result) { - this.first = result; - return this; - } - - @Override - public EventQuery maxResults(int results) { - this.max = results; - return this; - } - - @Override - public List getResultList() { - if (events.size() < first) { - return Collections.emptyList(); - } - int end = first + max <= events.size() ? first + max : events.size(); - - return events.subList(first, end); - } - -} diff --git a/examples/providers/event-store-mem/src/main/java/org/keycloak/examples/providers/events/MemEventStoreProvider.java b/examples/providers/event-store-mem/src/main/java/org/keycloak/examples/providers/events/MemEventStoreProvider.java deleted file mode 100755 index b06f7ad00f..0000000000 --- a/examples/providers/event-store-mem/src/main/java/org/keycloak/examples/providers/events/MemEventStoreProvider.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.examples.providers.events; - -import org.keycloak.events.Event; -import org.keycloak.events.EventQuery; -import org.keycloak.events.EventStoreProvider; -import org.keycloak.events.EventType; -import org.keycloak.events.admin.AdminEvent; -import org.keycloak.events.admin.AdminEventQuery; -import org.keycloak.events.admin.OperationType; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -/** - * @author Stian Thorgersen - */ -public class MemEventStoreProvider implements EventStoreProvider { - private final List events; - private final Set excludedEvents; - private final List adminEvents; - private final Set excludedOperations; - - public MemEventStoreProvider(List events, Set excludedEvents, - List adminEvents, Set excludedOperations) { - this.events = events; - this.excludedEvents = excludedEvents; - - this.adminEvents = adminEvents; - this.excludedOperations = excludedOperations; - } - - @Override - public EventQuery createQuery() { - return new MemEventQuery(new LinkedList<>(events)); - } - - @Override - public void clear() { - - } - - @Override - public void clear(String realmId) { - synchronized(events) { - Iterator itr = events.iterator(); - while (itr.hasNext()) { - if (itr.next().getRealmId().equals(realmId)) { - itr.remove(); - } - } - } - } - - @Override - public void clear(String realmId, long olderThan) { - synchronized(events) { - Iterator itr = events.iterator(); - while (itr.hasNext()) { - Event e = itr.next(); - if (e.getRealmId().equals(realmId) && e.getTime() < olderThan) { - itr.remove(); - } - } - } - } - - @Override - public void onEvent(Event event) { - if (excludedEvents == null || !excludedEvents.contains(event.getType())) { - events.add(0, event); - } - } - - @Override - public AdminEventQuery createAdminQuery() { - return new MemAdminEventQuery(new LinkedList<>(adminEvents)); - } - - @Override - public void clearAdmin() { - - } - - @Override - public void clearAdmin(String realmId) { - synchronized(adminEvents) { - Iterator itr = adminEvents.iterator(); - while (itr.hasNext()) { - if (itr.next().getRealmId().equals(realmId)) { - itr.remove(); - } - } - } - } - - @Override - public void clearAdmin(String realmId, long olderThan) { - synchronized(adminEvents) { - Iterator itr = adminEvents.iterator(); - while (itr.hasNext()) { - AdminEvent e = itr.next(); - if (e.getRealmId().equals(realmId) && e.getTime() < olderThan) { - itr.remove(); - } - } - } - } - - @Override - public void onEvent(AdminEvent adminEvent, boolean includeRepresentation) { - if (excludedOperations == null || !excludedOperations.contains(adminEvent.getOperationType())) { - adminEvents.add(0, adminEvent); - } - } - - @Override - public void close() { - } - -} diff --git a/examples/providers/event-store-mem/src/main/java/org/keycloak/examples/providers/events/MemEventStoreProviderFactory.java b/examples/providers/event-store-mem/src/main/java/org/keycloak/examples/providers/events/MemEventStoreProviderFactory.java deleted file mode 100755 index e6b0d8b70f..0000000000 --- a/examples/providers/event-store-mem/src/main/java/org/keycloak/examples/providers/events/MemEventStoreProviderFactory.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.examples.providers.events; - -import org.keycloak.Config; -import org.keycloak.events.Event; -import org.keycloak.events.EventStoreProvider; -import org.keycloak.events.EventStoreProviderFactory; -import org.keycloak.events.EventType; -import org.keycloak.events.admin.AdminEvent; -import org.keycloak.events.admin.OperationType; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.KeycloakSessionFactory; - -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -/** - * @author Stian Thorgersen - */ -public class MemEventStoreProviderFactory implements EventStoreProviderFactory { - - private List events; - private Set excludedEvents; - private List adminEvents; - private Set excludedOperations; - - @Override - public EventStoreProvider create(KeycloakSession session) { - return new MemEventStoreProvider(events, excludedEvents, adminEvents, excludedOperations); - } - - @Override - public void init(Config.Scope config) { - events = Collections.synchronizedList(new LinkedList()); - adminEvents = Collections.synchronizedList(new LinkedList()); - - String[] excludes = config.getArray("exclude-events"); - if (excludes != null) { - excludedEvents = new HashSet<>(); - for (String e : excludes) { - excludedEvents.add(EventType.valueOf(e)); - } - } - - String excludesOperations = config.get("excludesOperations"); - if (excludesOperations != null) { - excludedOperations = new HashSet<>(); - for (String e : excludesOperations.split(",")) { - excludedOperations.add(OperationType.valueOf(e)); - } - } - } - - @Override - public void postInit(KeycloakSessionFactory factory) { - - } - @Override - public void close() { - events = null; - excludedEvents = null; - adminEvents = null; - excludedOperations = null; - } - - @Override - public String getId() { - return "in-mem"; - } -} diff --git a/examples/providers/event-store-mem/src/main/resources/META-INF/services/org.keycloak.events.EventStoreProviderFactory b/examples/providers/event-store-mem/src/main/resources/META-INF/services/org.keycloak.events.EventStoreProviderFactory deleted file mode 100644 index fb3398f1d5..0000000000 --- a/examples/providers/event-store-mem/src/main/resources/META-INF/services/org.keycloak.events.EventStoreProviderFactory +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright 2016 Red Hat, Inc. and/or its affiliates -# and other contributors as indicated by the @author tags. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -org.keycloak.examples.providers.events.MemEventStoreProviderFactory \ No newline at end of file diff --git a/examples/providers/pom.xml b/examples/providers/pom.xml index 239224d1dd..0036e5a527 100755 --- a/examples/providers/pom.xml +++ b/examples/providers/pom.xml @@ -31,9 +31,6 @@ pom - event-listener-sysout - event-store-mem - authenticator rest domain-extension