KEYCLOAK-12910 Impossible to compile keycloak examples
This commit is contained in:
parent
a506115a93
commit
27f6f7bf40
4 changed files with 29 additions and 11 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<#import "select.ftl" as layout>
|
||||
<#import "template.ftl" as layout>
|
||||
<@layout.registrationLayout; section>
|
||||
<#if section = "title">
|
||||
${msg("loginTitle",realm.name)}
|
||||
|
|
|
@ -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<String, String> 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);
|
||||
|
|
|
@ -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<Secr
|
|||
return SecretQuestionCredentialModel.createFromCredentialModel(model);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CredentialTypeMetadata getCredentialTypeMetadata() {
|
||||
return CredentialTypeMetadata.builder()
|
||||
.type(getType())
|
||||
.category(CredentialTypeMetadata.Category.TWO_FACTOR)
|
||||
.displayName(SecretQuestionCredentialProviderFactory.PROVIDER_ID)
|
||||
.helpText("secret-question-text")
|
||||
.createAction(SecretQuestionAuthenticatorFactory.PROVIDER_ID)
|
||||
.removeable(false)
|
||||
.build(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return SecretQuestionCredentialModel.TYPE;
|
||||
|
|
Loading…
Reference in a new issue