From 27f6f7bf40e71e4c794286ef5d93c4edfe8ee285 Mon Sep 17 00:00:00 2001 From: mabartos Date: Thu, 6 Feb 2020 10:35:11 +0100 Subject: [PATCH] KEYCLOAK-12910 Impossible to compile keycloak examples --- examples/providers/authenticator/README.md | 20 ++++++++++++------- .../authenticator/secret-question.ftl | 2 +- .../SecretQuestionAuthenticator.java | 5 ++--- .../SecretQuestionCredentialProvider.java | 13 ++++++++++++ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/examples/providers/authenticator/README.md b/examples/providers/authenticator/README.md index 5d980deb3e..c86cd8837f 100755 --- a/examples/providers/authenticator/README.md +++ b/examples/providers/authenticator/README.md @@ -1,23 +1,29 @@ Example Custom Authenticator =================================================== -1. First, Keycloak must be running. +1. First, Keycloak must be running. See [Getting Started](https://github.com/keycloak/keycloak#getting-started), or you + can build distribution from [source](https://github.com/keycloak/keycloak/blob/master/docs/building.md). 2. Execute the follow. This will build the example and deploy it - $ mvn clean install wildfly:deploy + `$ mvn clean install wildfly:deploy` -3. Copy the secret-question.ftl and secret-question-config.ftl files to the themes/base/login directory. +3. Copy the `secret-question.ftl` and `secret-question-config.ftl` files to the `themes/base/login` server 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 +5. Go to the **Authentication** menu item and go to the **Flows** 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 +6. In your copy, click the **Actions** menu item in **Forms** subflow and **Add Execution**. Pick `Secret Question` and change + the **Requirement** choice. + +7. Go to the **Bindings** tab in **Authentication** menu and change the default **Browser Flow** to your copy of the browser flow + and click `Save`. -7. Next you have to register the required action that you created. Click on the Required Actions tab in the Authentication menu. - Click on the Register button and choose your new Required Action. +8. Next you have to register the required action that you created. Click on the **Required Actions** tab in the **Authentication** menu. + Click on the `Register` button and choose your new Required Action. You can also choose the `Default Action` for the Required Action + and each new user has to set the secret answer. Your new required action should now be displayed and enabled in the required actions list. diff --git a/examples/providers/authenticator/secret-question.ftl b/examples/providers/authenticator/secret-question.ftl index b1bad4b2f1..b8ca1c901a 100755 --- a/examples/providers/authenticator/secret-question.ftl +++ b/examples/providers/authenticator/secret-question.ftl @@ -1,4 +1,4 @@ -<#import "select.ftl" as layout> +<#import "template.ftl" as layout> <@layout.registrationLayout; section> <#if section = "title"> ${msg("loginTitle",realm.name)} 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 index 61dbbcdf38..5b5e189c54 100755 --- 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 @@ -98,7 +98,7 @@ public class SecretQuestionAuthenticator implements Authenticator, CredentialVal public void addCookie(AuthenticationFlowContext context, String name, String value, String path, String domain, String comment, int maxAge, boolean secure, boolean httpOnly) { HttpResponse response = context.getSession().getContext().getContextObject(HttpResponse.class); StringBuffer cookieBuf = new StringBuffer(); - ServerCookie.appendCookieValue(cookieBuf, 1, name, value, path, domain, comment, maxAge, secure, httpOnly); + ServerCookie.appendCookieValue(cookieBuf, 1, name, value, path, domain, comment, maxAge, secure, httpOnly, null); String cookie = cookieBuf.toString(); response.getOutputHeaders().add(HttpHeaders.SET_COOKIE, cookie); } @@ -107,11 +107,10 @@ public class SecretQuestionAuthenticator implements Authenticator, CredentialVal protected boolean validateAnswer(AuthenticationFlowContext context) { MultivaluedMap formData = context.getHttpRequest().getDecodedFormParameters(); String secret = formData.getFirst("secret_answer"); - String credentialId = context.getSelectedCredentialId(); + String credentialId = formData.getFirst("credentialId"); if (credentialId == null || credentialId.isEmpty()) { credentialId = getCredentialProvider(context.getSession()) .getDefaultCredential(context.getSession(), context.getRealm(), context.getUser()).getId(); - context.setSelectedCredentialId(credentialId); } UserCredentialModel input = new UserCredentialModel(credentialId, getType(context.getSession()), secret); 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 index 91db533481..7597468abb 100644 --- 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 @@ -22,6 +22,7 @@ import org.keycloak.credential.CredentialInput; import org.keycloak.credential.CredentialInputValidator; import org.keycloak.credential.CredentialModel; import org.keycloak.credential.CredentialProvider; +import org.keycloak.credential.CredentialTypeMetadata; import org.keycloak.credential.UserCredentialStore; import org.keycloak.examples.authenticator.credential.SecretQuestionCredentialModel; import org.keycloak.models.KeycloakSession; @@ -94,6 +95,18 @@ public class SecretQuestionCredentialProvider implements CredentialProvider