flow alias lookup
This commit is contained in:
parent
c52d16da6d
commit
fa99b5415d
10 changed files with 58 additions and 16 deletions
|
@ -187,6 +187,7 @@ public interface RealmModel extends RoleContainerModel {
|
||||||
void setSmtpConfig(Map<String, String> smtpConfig);
|
void setSmtpConfig(Map<String, String> smtpConfig);
|
||||||
|
|
||||||
List<AuthenticationFlowModel> getAuthenticationFlows();
|
List<AuthenticationFlowModel> getAuthenticationFlows();
|
||||||
|
AuthenticationFlowModel getFlowByAlias(String alias);
|
||||||
AuthenticationFlowModel addAuthenticationFlow(AuthenticationFlowModel model);
|
AuthenticationFlowModel addAuthenticationFlow(AuthenticationFlowModel model);
|
||||||
AuthenticationFlowModel getAuthenticationFlowById(String id);
|
AuthenticationFlowModel getAuthenticationFlowById(String id);
|
||||||
void removeAuthenticationFlow(AuthenticationFlowModel model);
|
void removeAuthenticationFlow(AuthenticationFlowModel model);
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class DefaultAuthenticationFlows {
|
||||||
execution.setRequirement(AuthenticationExecutionModel.Requirement.REQUIRED);
|
execution.setRequirement(AuthenticationExecutionModel.Requirement.REQUIRED);
|
||||||
execution.setAuthenticator(password.getId());
|
execution.setAuthenticator(password.getId());
|
||||||
execution.setPriority(11);
|
execution.setPriority(11);
|
||||||
execution.setUserSetupAllowed(false);
|
execution.setUserSetupAllowed(true);
|
||||||
execution.setAutheticatorFlow(false);
|
execution.setAutheticatorFlow(false);
|
||||||
realm.addAuthenticatorExecution(execution);
|
realm.addAuthenticatorExecution(execution);
|
||||||
|
|
||||||
|
|
|
@ -1213,6 +1213,19 @@ public class RealmAdapter implements RealmModel {
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthenticationFlowModel getFlowByAlias(String alias) {
|
||||||
|
for (AuthenticationFlowModel flow : getAuthenticationFlows()) {
|
||||||
|
if (flow.getAlias().equals(alias)) {
|
||||||
|
return flow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected AuthenticationFlowModel entityToModel(AuthenticationFlowEntity entity) {
|
protected AuthenticationFlowModel entityToModel(AuthenticationFlowEntity entity) {
|
||||||
AuthenticationFlowModel model = new AuthenticationFlowModel();
|
AuthenticationFlowModel model = new AuthenticationFlowModel();
|
||||||
model.setId(entity.getId());
|
model.setId(entity.getId());
|
||||||
|
|
|
@ -1024,6 +1024,16 @@ public class RealmAdapter implements RealmModel {
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthenticationFlowModel getFlowByAlias(String alias) {
|
||||||
|
for (AuthenticationFlowModel flow : getAuthenticationFlows()) {
|
||||||
|
if (flow.getAlias().equals(alias)) {
|
||||||
|
return flow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthenticationFlowModel addAuthenticationFlow(AuthenticationFlowModel model) {
|
public AuthenticationFlowModel addAuthenticationFlow(AuthenticationFlowModel model) {
|
||||||
getDelegateForUpdate();
|
getDelegateForUpdate();
|
||||||
|
|
|
@ -1519,6 +1519,17 @@ public class RealmAdapter implements RealmModel {
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthenticationFlowModel getFlowByAlias(String alias) {
|
||||||
|
for (AuthenticationFlowModel flow : getAuthenticationFlows()) {
|
||||||
|
if (flow.getAlias().equals(alias)) {
|
||||||
|
return flow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected AuthenticationFlowModel entityToModel(AuthenticationFlowEntity entity) {
|
protected AuthenticationFlowModel entityToModel(AuthenticationFlowEntity entity) {
|
||||||
AuthenticationFlowModel model = new AuthenticationFlowModel();
|
AuthenticationFlowModel model = new AuthenticationFlowModel();
|
||||||
model.setId(entity.getId());
|
model.setId(entity.getId());
|
||||||
|
|
|
@ -1244,6 +1244,17 @@ public class RealmAdapter extends AbstractMongoAdapter<MongoRealmEntity> impleme
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthenticationFlowModel getFlowByAlias(String alias) {
|
||||||
|
for (AuthenticationFlowModel flow : getAuthenticationFlows()) {
|
||||||
|
if (flow.getAlias().equals(alias)) {
|
||||||
|
return flow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected AuthenticationFlowModel entityToModel(AuthenticationFlowEntity entity) {
|
protected AuthenticationFlowModel entityToModel(AuthenticationFlowEntity entity) {
|
||||||
AuthenticationFlowModel model = new AuthenticationFlowModel();
|
AuthenticationFlowModel model = new AuthenticationFlowModel();
|
||||||
model.setId(entity.getId());
|
model.setId(entity.getId());
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.keycloak.models.IdentityProviderModel;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.UserSessionModel;
|
import org.keycloak.models.UserSessionModel;
|
||||||
|
import org.keycloak.models.utils.DefaultAuthenticationFlows;
|
||||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||||
import org.keycloak.protocol.oidc.utils.RedirectUtils;
|
import org.keycloak.protocol.oidc.utils.RedirectUtils;
|
||||||
import org.keycloak.saml.common.constants.GeneralConstants;
|
import org.keycloak.saml.common.constants.GeneralConstants;
|
||||||
|
@ -335,14 +336,8 @@ public class SamlService {
|
||||||
return buildRedirectToIdentityProvider(identityProvider.getAlias(), new ClientSessionCode(realm, clientSession).getCode() );
|
return buildRedirectToIdentityProvider(identityProvider.getAlias(), new ClientSessionCode(realm, clientSession).getCode() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
AuthenticationFlowModel flow = realm.getFlowByAlias(DefaultAuthenticationFlows.BROWSER_FLOW);
|
||||||
String flowId = null;
|
String flowId = flow.getId();
|
||||||
for (AuthenticationFlowModel flow : realm.getAuthenticationFlows()) {
|
|
||||||
if (flow.getAlias().equals("browser")) {
|
|
||||||
flowId = flow.getId();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AuthenticationProcessor processor = new AuthenticationProcessor();
|
AuthenticationProcessor processor = new AuthenticationProcessor();
|
||||||
processor.setClientSession(clientSession)
|
processor.setClientSession(clientSession)
|
||||||
.setFlowId(flowId)
|
.setFlowId(flowId)
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.net.URI;
|
||||||
public class AbstractFormAuthenticator {
|
public class AbstractFormAuthenticator {
|
||||||
|
|
||||||
public static final String LOGIN_FORM_ACTION = "login_form";
|
public static final String LOGIN_FORM_ACTION = "login_form";
|
||||||
|
public static final String REGISTRATION_FORM_ACTION = "registration_form";
|
||||||
public static final String ACTION = "action";
|
public static final String ACTION = "action";
|
||||||
|
|
||||||
protected boolean isAction(AuthenticatorContext context, String action) {
|
protected boolean isAction(AuthenticatorContext context, String action) {
|
||||||
|
|
|
@ -33,6 +33,10 @@ public class LoginFormUsernameAuthenticator extends AbstractFormAuthenticator im
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void authenticate(AuthenticatorContext context) {
|
public void authenticate(AuthenticatorContext context) {
|
||||||
|
if (isAction(context, REGISTRATION_FORM_ACTION) && context.getUser() != null) {
|
||||||
|
context.success();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!isAction(context, LOGIN_FORM_ACTION)) {
|
if (!isAction(context, LOGIN_FORM_ACTION)) {
|
||||||
MultivaluedMap<String, String> formData = new MultivaluedMapImpl<>();
|
MultivaluedMap<String, String> formData = new MultivaluedMapImpl<>();
|
||||||
String loginHint = context.getClientSession().getNote(OIDCLoginProtocol.LOGIN_HINT_PARAM);
|
String loginHint = context.getClientSession().getNote(OIDCLoginProtocol.LOGIN_HINT_PARAM);
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.keycloak.models.IdentityProviderModel;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.RequiredCredentialModel;
|
import org.keycloak.models.RequiredCredentialModel;
|
||||||
|
import org.keycloak.models.utils.DefaultAuthenticationFlows;
|
||||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||||
import org.keycloak.protocol.oidc.OIDCLoginProtocol;
|
import org.keycloak.protocol.oidc.OIDCLoginProtocol;
|
||||||
import org.keycloak.protocol.oidc.utils.RedirectUtils;
|
import org.keycloak.protocol.oidc.utils.RedirectUtils;
|
||||||
|
@ -259,13 +260,8 @@ public class AuthorizationEndpoint {
|
||||||
}
|
}
|
||||||
clientSession.setNote(Details.AUTH_TYPE, CODE_AUTH_TYPE);
|
clientSession.setNote(Details.AUTH_TYPE, CODE_AUTH_TYPE);
|
||||||
|
|
||||||
String flowId = null;
|
AuthenticationFlowModel flow = realm.getFlowByAlias(DefaultAuthenticationFlows.BROWSER_FLOW);
|
||||||
for (AuthenticationFlowModel flow : realm.getAuthenticationFlows()) {
|
String flowId = flow.getId();
|
||||||
if (flow.getAlias().equals("browser")) {
|
|
||||||
flowId = flow.getId();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AuthenticationProcessor processor = new AuthenticationProcessor();
|
AuthenticationProcessor processor = new AuthenticationProcessor();
|
||||||
processor.setClientSession(clientSession)
|
processor.setClientSession(clientSession)
|
||||||
.setFlowId(flowId)
|
.setFlowId(flowId)
|
||||||
|
|
Loading…
Reference in a new issue