Skip to content

Commit

Permalink
form auth
Browse files Browse the repository at this point in the history
  • Loading branch information
patriot1burke committed Jun 25, 2015
1 parent 0001592 commit 064d677
Show file tree
Hide file tree
Showing 32 changed files with 794 additions and 235 deletions.
Expand Up @@ -12,6 +12,16 @@
<constraints nullable="true"/> <constraints nullable="true"/>
</column> </column>
</addColumn> </addColumn>
<addColumn tableName="AUTHENTICATION_FLOW">
<column name="PROVIDER_ID" type="VARCHAR(36)" defaultValue="basic-flow">
<constraints nullable="false"/>
</column>
</addColumn>
<addColumn tableName="AUTHENTICATION_EXECUTION">
<column name="AUTH_FLOW_ID" type="VARCHAR(36)">
<constraints nullable="true"/>
</column>
</addColumn>
<dropColumn tableName="AUTHENTICATOR" columnName="PROVIDER_ID"/> <dropColumn tableName="AUTHENTICATOR" columnName="PROVIDER_ID"/>
<renameTable oldTableName="AUTHENTICATOR_CONFIG" newTableName="AUTHENTICATOR_CONFIG_ENTRY"/> <renameTable oldTableName="AUTHENTICATOR_CONFIG" newTableName="AUTHENTICATOR_CONFIG_ENTRY"/>
<renameTable oldTableName="AUTHENTICATOR" newTableName="AUTHENTICATOR_CONFIG"/> <renameTable oldTableName="AUTHENTICATOR" newTableName="AUTHENTICATOR_CONFIG"/>
Expand Down
Expand Up @@ -22,6 +22,7 @@ public int compare(AuthenticationExecutionModel o1, AuthenticationExecutionModel
private String id; private String id;
private String authenticatorConfig; private String authenticatorConfig;
private String authenticator; private String authenticator;
private String flowId;
private boolean autheticatorFlow; private boolean autheticatorFlow;
private Requirement requirement; private Requirement requirement;
private boolean userSetupAllowed; private boolean userSetupAllowed;
Expand Down Expand Up @@ -84,6 +85,19 @@ public void setParentFlow(String parentFlow) {
this.parentFlow = parentFlow; this.parentFlow = parentFlow;
} }


/**
* If this execution is a flow, this is the flowId pointing to an AuthenticationFlowModel
*
* @return
*/
public String getFlowId() {
return flowId;
}

public void setFlowId(String flowId) {
this.flowId = flowId;
}

/** /**
* Is the referenced authenticator a flow? * Is the referenced authenticator a flow?
* *
Expand Down
Expand Up @@ -12,6 +12,7 @@ public class AuthenticationFlowModel implements Serializable {
private String id; private String id;
private String alias; private String alias;
private String description; private String description;
private String providerId;


public String getId() { public String getId() {
return id; return id;
Expand All @@ -36,4 +37,12 @@ public String getDescription() {
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }

public String getProviderId() {
return providerId;
}

public void setProviderId(String providerId) {
this.providerId = providerId;
}
} }
Expand Up @@ -10,6 +10,7 @@
public class AuthenticationExecutionEntity { public class AuthenticationExecutionEntity {
protected String id; protected String id;
protected String authenticator; protected String authenticator;
protected String flowId;
protected AuthenticationExecutionModel.Requirement requirement; protected AuthenticationExecutionModel.Requirement requirement;
protected int priority; protected int priority;
private boolean userSetupAllowed; private boolean userSetupAllowed;
Expand Down Expand Up @@ -71,4 +72,12 @@ public String getParentFlow() {
public void setParentFlow(String parentFlow) { public void setParentFlow(String parentFlow) {
this.parentFlow = parentFlow; this.parentFlow = parentFlow;
} }

public String getFlowId() {
return flowId;
}

public void setFlowId(String flowId) {
this.flowId = flowId;
}
} }
Expand Up @@ -12,6 +12,8 @@ public class AuthenticationFlowEntity {
protected String id; protected String id;
protected String alias; protected String alias;
protected String description; protected String description;
protected String providerId;

List<AuthenticationExecutionEntity> executions = new ArrayList<AuthenticationExecutionEntity>(); List<AuthenticationExecutionEntity> executions = new ArrayList<AuthenticationExecutionEntity>();
public String getId() { public String getId() {
return id; return id;
Expand Down Expand Up @@ -44,4 +46,12 @@ public List<AuthenticationExecutionEntity> getExecutions() {
public void setExecutions(List<AuthenticationExecutionEntity> executions) { public void setExecutions(List<AuthenticationExecutionEntity> executions) {
this.executions = executions; this.executions = executions;
} }

public String getProviderId() {
return providerId;
}

public void setProviderId(String providerId) {
this.providerId = providerId;
}
} }
Expand Up @@ -18,6 +18,7 @@ public static void addFlows(RealmModel realm) {
AuthenticationFlowModel browser = new AuthenticationFlowModel(); AuthenticationFlowModel browser = new AuthenticationFlowModel();
browser.setAlias(BROWSER_FLOW); browser.setAlias(BROWSER_FLOW);
browser.setDescription("browser based authentication"); browser.setDescription("browser based authentication");
browser.setProviderId("basic-flow");
browser = realm.addAuthenticationFlow(browser); browser = realm.addAuthenticationFlow(browser);
AuthenticationExecutionModel execution = new AuthenticationExecutionModel(); AuthenticationExecutionModel execution = new AuthenticationExecutionModel();
execution.setParentFlow(browser.getId()); execution.setParentFlow(browser.getId());
Expand All @@ -40,11 +41,12 @@ public static void addFlows(RealmModel realm) {
AuthenticationFlowModel forms = new AuthenticationFlowModel(); AuthenticationFlowModel forms = new AuthenticationFlowModel();
forms.setAlias(FORMS_FLOW); forms.setAlias(FORMS_FLOW);
forms.setDescription("Username, password, otp and other auth forms."); forms.setDescription("Username, password, otp and other auth forms.");
forms.setProviderId("basic-flow");
forms = realm.addAuthenticationFlow(forms); forms = realm.addAuthenticationFlow(forms);
execution = new AuthenticationExecutionModel(); execution = new AuthenticationExecutionModel();
execution.setParentFlow(browser.getId()); execution.setParentFlow(browser.getId());
execution.setRequirement(AuthenticationExecutionModel.Requirement.ALTERNATIVE); execution.setRequirement(AuthenticationExecutionModel.Requirement.ALTERNATIVE);
execution.setAuthenticator(forms.getId()); execution.setFlowId(forms.getId());
execution.setPriority(30); execution.setPriority(30);
execution.setUserSetupAllowed(false); execution.setUserSetupAllowed(false);
execution.setAutheticatorFlow(true); execution.setAutheticatorFlow(true);
Expand Down
Expand Up @@ -1233,6 +1233,7 @@ protected AuthenticationFlowModel entityToModel(AuthenticationFlowEntity entity)
model.setId(entity.getId()); model.setId(entity.getId());
model.setAlias(entity.getAlias()); model.setAlias(entity.getAlias());
model.setDescription(entity.getDescription()); model.setDescription(entity.getDescription());
model.setProviderId(entity.getProviderId());
return model; return model;
} }


Expand Down Expand Up @@ -1266,6 +1267,7 @@ public void updateAuthenticationFlow(AuthenticationFlowModel model) {
if (toUpdate == null) return; if (toUpdate == null) return;
toUpdate.setAlias(model.getAlias()); toUpdate.setAlias(model.getAlias());
toUpdate.setDescription(model.getDescription()); toUpdate.setDescription(model.getDescription());
toUpdate.setProviderId(model.getProviderId());


} }


Expand All @@ -1275,6 +1277,7 @@ public AuthenticationFlowModel addAuthenticationFlow(AuthenticationFlowModel mod
entity.setId(KeycloakModelUtils.generateId()); entity.setId(KeycloakModelUtils.generateId());
entity.setAlias(model.getAlias()); entity.setAlias(model.getAlias());
entity.setDescription(model.getDescription()); entity.setDescription(model.getDescription());
entity.setProviderId(model.getProviderId());
realm.getAuthenticationFlows().add(entity); realm.getAuthenticationFlows().add(entity);
model.setId(entity.getId()); model.setId(entity.getId());
return model; return model;
Expand Down Expand Up @@ -1303,6 +1306,7 @@ public AuthenticationExecutionModel entityToModel(AuthenticationExecutionEntity
model.setPriority(entity.getPriority()); model.setPriority(entity.getPriority());
model.setAuthenticator(entity.getAuthenticator()); model.setAuthenticator(entity.getAuthenticator());
model.setParentFlow(entity.getParentFlow()); model.setParentFlow(entity.getParentFlow());
model.setFlowId(entity.getFlowId());
model.setAutheticatorFlow(entity.isAuthenticatorFlow()); model.setAutheticatorFlow(entity.isAuthenticatorFlow());
return model; return model;
} }
Expand Down Expand Up @@ -1334,6 +1338,7 @@ public AuthenticationExecutionModel addAuthenticatorExecution(AuthenticationExec
entity.setRequirement(model.getRequirement()); entity.setRequirement(model.getRequirement());
entity.setUserSetupAllowed(model.isUserSetupAllowed()); entity.setUserSetupAllowed(model.isUserSetupAllowed());
entity.setAuthenticatorFlow(model.isAutheticatorFlow()); entity.setAuthenticatorFlow(model.isAutheticatorFlow());
entity.setFlowId(model.getFlowId());
AuthenticationFlowEntity flow = getFlowEntity(model.getId()); AuthenticationFlowEntity flow = getFlowEntity(model.getId());
flow.getExecutions().add(entity); flow.getExecutions().add(entity);
model.setId(entity.getId()); model.setId(entity.getId());
Expand All @@ -1355,6 +1360,7 @@ public void updateAuthenticatorExecution(AuthenticationExecutionModel model) {
entity.setAuthenticator(model.getAuthenticator()); entity.setAuthenticator(model.getAuthenticator());
entity.setPriority(model.getPriority()); entity.setPriority(model.getPriority());
entity.setRequirement(model.getRequirement()); entity.setRequirement(model.getRequirement());
entity.setFlowId(model.getFlowId());
entity.setUserSetupAllowed(model.isUserSetupAllowed()); entity.setUserSetupAllowed(model.isUserSetupAllowed());
} }


Expand Down
Expand Up @@ -1542,6 +1542,7 @@ protected AuthenticationFlowModel entityToModel(AuthenticationFlowEntity entity)
AuthenticationFlowModel model = new AuthenticationFlowModel(); AuthenticationFlowModel model = new AuthenticationFlowModel();
model.setId(entity.getId()); model.setId(entity.getId());
model.setAlias(entity.getAlias()); model.setAlias(entity.getAlias());
model.setProviderId(entity.getProviderId());
model.setDescription(entity.getDescription()); model.setDescription(entity.getDescription());
return model; return model;
} }
Expand All @@ -1567,6 +1568,7 @@ public void updateAuthenticationFlow(AuthenticationFlowModel model) {
if (entity == null) return; if (entity == null) return;
entity.setAlias(model.getAlias()); entity.setAlias(model.getAlias());
entity.setDescription(model.getDescription()); entity.setDescription(model.getDescription());
entity.setProviderId(model.getProviderId());


} }


Expand All @@ -1576,6 +1578,7 @@ public AuthenticationFlowModel addAuthenticationFlow(AuthenticationFlowModel mod
entity.setId(KeycloakModelUtils.generateId()); entity.setId(KeycloakModelUtils.generateId());
entity.setAlias(model.getAlias()); entity.setAlias(model.getAlias());
entity.setDescription(model.getDescription()); entity.setDescription(model.getDescription());
entity.setProviderId(model.getProviderId());
entity.setRealm(realm); entity.setRealm(realm);
realm.getAuthenticationFlows().add(entity); realm.getAuthenticationFlows().add(entity);
em.persist(entity); em.persist(entity);
Expand All @@ -1589,7 +1592,7 @@ public List<AuthenticationExecutionModel> getAuthenticationExecutions(String flo
TypedQuery<AuthenticationExecutionEntity> query = em.createNamedQuery("getAuthenticationExecutionsByFlow", AuthenticationExecutionEntity.class); TypedQuery<AuthenticationExecutionEntity> query = em.createNamedQuery("getAuthenticationExecutionsByFlow", AuthenticationExecutionEntity.class);
AuthenticationFlowEntity flow = em.getReference(AuthenticationFlowEntity.class, flowId); AuthenticationFlowEntity flow = em.getReference(AuthenticationFlowEntity.class, flowId);
query.setParameter("realm", realm); query.setParameter("realm", realm);
query.setParameter("flow", flow); query.setParameter("parentFlow", flow);
List<AuthenticationExecutionEntity> queryResult = query.getResultList(); List<AuthenticationExecutionEntity> queryResult = query.getResultList();
List<AuthenticationExecutionModel> executions = new LinkedList<>(); List<AuthenticationExecutionModel> executions = new LinkedList<>();
for (AuthenticationExecutionEntity entity : queryResult) { for (AuthenticationExecutionEntity entity : queryResult) {
Expand All @@ -1607,7 +1610,8 @@ public AuthenticationExecutionModel entityToModel(AuthenticationExecutionEntity
model.setRequirement(entity.getRequirement()); model.setRequirement(entity.getRequirement());
model.setPriority(entity.getPriority()); model.setPriority(entity.getPriority());
model.setAuthenticator(entity.getAuthenticator()); model.setAuthenticator(entity.getAuthenticator());
model.setParentFlow(entity.getFlow().getId()); model.setFlowId(entity.getFlowId());
model.setParentFlow(entity.getParentFlow().getId());
model.setAutheticatorFlow(entity.isAutheticatorFlow()); model.setAutheticatorFlow(entity.isAutheticatorFlow());
return model; return model;
} }
Expand All @@ -1625,9 +1629,10 @@ public AuthenticationExecutionModel addAuthenticatorExecution(AuthenticationExec
entity.setId(KeycloakModelUtils.generateId()); entity.setId(KeycloakModelUtils.generateId());
entity.setAuthenticator(model.getAuthenticator()); entity.setAuthenticator(model.getAuthenticator());
entity.setPriority(model.getPriority()); entity.setPriority(model.getPriority());
entity.setFlowId(model.getFlowId());
entity.setRequirement(model.getRequirement()); entity.setRequirement(model.getRequirement());
AuthenticationFlowEntity flow = em.find(AuthenticationFlowEntity.class, model.getParentFlow()); AuthenticationFlowEntity flow = em.find(AuthenticationFlowEntity.class, model.getParentFlow());
entity.setFlow(flow); entity.setParentFlow(flow);
flow.getExecutions().add(entity); flow.getExecutions().add(entity);
entity.setRealm(realm); entity.setRealm(realm);
entity.setUserSetupAllowed(model.isUserSetupAllowed()); entity.setUserSetupAllowed(model.isUserSetupAllowed());
Expand All @@ -1648,6 +1653,7 @@ public void updateAuthenticatorExecution(AuthenticationExecutionModel model) {
entity.setPriority(model.getPriority()); entity.setPriority(model.getPriority());
entity.setRequirement(model.getRequirement()); entity.setRequirement(model.getRequirement());
entity.setUserSetupAllowed(model.isUserSetupAllowed()); entity.setUserSetupAllowed(model.isUserSetupAllowed());
entity.setFlowId(model.getFlowId());
em.flush(); em.flush();
} }


Expand Down
Expand Up @@ -19,9 +19,9 @@
@Table(name="AUTHENTICATION_EXECUTION") @Table(name="AUTHENTICATION_EXECUTION")
@Entity @Entity
@NamedQueries({ @NamedQueries({
@NamedQuery(name="getAuthenticationExecutionsByFlow", query="select authenticator from AuthenticationExecutionEntity authenticator where authenticator.realm = :realm and authenticator.flow = :flow"), @NamedQuery(name="getAuthenticationExecutionsByFlow", query="select authenticator from AuthenticationExecutionEntity authenticator where authenticator.realm = :realm and authenticator.parentFlow = :parentFlow"),
@NamedQuery(name="deleteAuthenticationExecutionsByRealm", query="delete from AuthenticationExecutionEntity authenticator where authenticator.realm = :realm"), @NamedQuery(name="deleteAuthenticationExecutionsByRealm", query="delete from AuthenticationExecutionEntity authenticator where authenticator.realm = :realm"),
@NamedQuery(name="deleteAuthenticationExecutionsByRealmAndFlow", query="delete from AuthenticationExecutionEntity authenticator where authenticator.realm = :realm and authenticator.flow = :flow"), @NamedQuery(name="deleteAuthenticationExecutionsByRealmAndFlow", query="delete from AuthenticationExecutionEntity authenticator where authenticator.realm = :realm and authenticator.parentFlow = :parentFlow"),
}) })
public class AuthenticationExecutionEntity { public class AuthenticationExecutionEntity {
@Id @Id
Expand All @@ -34,11 +34,14 @@ public class AuthenticationExecutionEntity {


@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "FLOW_ID") @JoinColumn(name = "FLOW_ID")
protected AuthenticationFlowEntity flow; protected AuthenticationFlowEntity parentFlow;


@Column(name="AUTHENTICATOR") @Column(name="AUTHENTICATOR")
protected String authenticator; protected String authenticator;


@Column(name="AUTH_FLOW_ID")
protected String flowId;

@Column(name="REQUIREMENT") @Column(name="REQUIREMENT")
protected AuthenticationExecutionModel.Requirement requirement; protected AuthenticationExecutionModel.Requirement requirement;


Expand Down Expand Up @@ -107,11 +110,19 @@ public void setAutheticatorFlow(boolean autheticatorFlow) {
this.autheticatorFlow = autheticatorFlow; this.autheticatorFlow = autheticatorFlow;
} }


public AuthenticationFlowEntity getFlow() { public AuthenticationFlowEntity getParentFlow() {
return flow; return parentFlow;
}

public void setParentFlow(AuthenticationFlowEntity flow) {
this.parentFlow = flow;
}

public String getFlowId() {
return flowId;
} }


public void setFlow(AuthenticationFlowEntity flow) { public void setFlowId(String flowId) {
this.flow = flow; this.flowId = flowId;
} }
} }
Expand Up @@ -36,10 +36,13 @@ public class AuthenticationFlowEntity {
@Column(name="ALIAS") @Column(name="ALIAS")
protected String alias; protected String alias;


@Column(name="PROVIDER_ID")
protected String providerId;

@Column(name="DESCRIPTION") @Column(name="DESCRIPTION")
protected String description; protected String description;


@OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "flow") @OneToMany(fetch = FetchType.LAZY, cascade ={CascadeType.REMOVE}, orphanRemoval = true, mappedBy = "parentFlow")
Collection<AuthenticationExecutionEntity> executions = new ArrayList<AuthenticationExecutionEntity>(); Collection<AuthenticationExecutionEntity> executions = new ArrayList<AuthenticationExecutionEntity>();
public String getId() { public String getId() {
return id; return id;
Expand Down Expand Up @@ -80,4 +83,12 @@ public Collection<AuthenticationExecutionEntity> getExecutions() {
public void setExecutions(Collection<AuthenticationExecutionEntity> executions) { public void setExecutions(Collection<AuthenticationExecutionEntity> executions) {
this.executions = executions; this.executions = executions;
} }

public String getProviderId() {
return providerId;
}

public void setProviderId(String providerId) {
this.providerId = providerId;
}
} }
Expand Up @@ -1341,6 +1341,7 @@ public void updateAuthenticationFlow(AuthenticationFlowModel model) {
if (toUpdate == null) return; if (toUpdate == null) return;
toUpdate.setAlias(model.getAlias()); toUpdate.setAlias(model.getAlias());
toUpdate.setDescription(model.getDescription()); toUpdate.setDescription(model.getDescription());
toUpdate.setProviderId(model.getProviderId());
updateMongoEntity(); updateMongoEntity();
} }


Expand All @@ -1350,6 +1351,7 @@ public AuthenticationFlowModel addAuthenticationFlow(AuthenticationFlowModel mod
entity.setId(KeycloakModelUtils.generateId()); entity.setId(KeycloakModelUtils.generateId());
entity.setAlias(model.getAlias()); entity.setAlias(model.getAlias());
entity.setDescription(model.getDescription()); entity.setDescription(model.getDescription());
entity.setProviderId(model.getProviderId());
getMongoEntity().getAuthenticationFlows().add(entity); getMongoEntity().getAuthenticationFlows().add(entity);
model.setId(entity.getId()); model.setId(entity.getId());
updateMongoEntity(); updateMongoEntity();
Expand Down Expand Up @@ -1378,6 +1380,7 @@ public AuthenticationExecutionModel entityToModel(AuthenticationExecutionEntity
model.setRequirement(entity.getRequirement()); model.setRequirement(entity.getRequirement());
model.setPriority(entity.getPriority()); model.setPriority(entity.getPriority());
model.setAuthenticator(entity.getAuthenticator()); model.setAuthenticator(entity.getAuthenticator());
model.setFlowId(entity.getFlowId());
model.setParentFlow(entity.getParentFlow()); model.setParentFlow(entity.getParentFlow());
model.setAutheticatorFlow(entity.isAuthenticatorFlow()); model.setAutheticatorFlow(entity.isAuthenticatorFlow());
return model; return model;
Expand Down Expand Up @@ -1410,6 +1413,7 @@ public AuthenticationExecutionModel addAuthenticatorExecution(AuthenticationExec
entity.setRequirement(model.getRequirement()); entity.setRequirement(model.getRequirement());
entity.setUserSetupAllowed(model.isUserSetupAllowed()); entity.setUserSetupAllowed(model.isUserSetupAllowed());
entity.setAuthenticatorFlow(model.isAutheticatorFlow()); entity.setAuthenticatorFlow(model.isAutheticatorFlow());
entity.setFlowId(model.getFlowId());
entity.setParentFlow(model.getParentFlow()); entity.setParentFlow(model.getParentFlow());
AuthenticationFlowEntity flow = getFlowEntity(model.getParentFlow()); AuthenticationFlowEntity flow = getFlowEntity(model.getParentFlow());
flow.getExecutions().add(entity); flow.getExecutions().add(entity);
Expand All @@ -1433,6 +1437,7 @@ public void updateAuthenticatorExecution(AuthenticationExecutionModel model) {
entity.setAuthenticator(model.getAuthenticator()); entity.setAuthenticator(model.getAuthenticator());
entity.setPriority(model.getPriority()); entity.setPriority(model.getPriority());
entity.setRequirement(model.getRequirement()); entity.setRequirement(model.getRequirement());
entity.setFlowId(model.getFlowId());
entity.setUserSetupAllowed(model.isUserSetupAllowed()); entity.setUserSetupAllowed(model.isUserSetupAllowed());
updateMongoEntity(); updateMongoEntity();
} }
Expand Down
@@ -0,0 +1,12 @@
package org.keycloak.authentication;

import javax.ws.rs.core.Response;

/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public interface AuthenticationFlow {
Response processAction(String actionExecution);
Response processFlow();
}

0 comments on commit 064d677

Please sign in to comment.