-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from tidepool-org/BACK-2916-separate-personal-…
…and-clinical-registration [BACK-2916/BACK-2913] Separate personal and clinical registration
- Loading branch information
Showing
35 changed files
with
1,002 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,7 @@ Dockerfile | |
|
||
.git/ | ||
.gitignore | ||
|
||
# Environment | ||
.env | ||
.envrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,8 @@ | |
target/ | ||
|
||
# Original theme | ||
themes/base | ||
themes/base | ||
|
||
# Environment | ||
.env | ||
.envrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...rg/tidepool/keycloak/extensions/authenticator/RegistrationRoleDiscoveryAuthenticator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.tidepool.keycloak.extensions.authenticator; | ||
|
||
import org.keycloak.authentication.AuthenticationFlowContext; | ||
import org.keycloak.authentication.AuthenticationFlowError; | ||
import org.keycloak.authentication.Authenticator; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.RealmModel; | ||
import org.keycloak.models.UserModel; | ||
import org.keycloak.protocol.AuthorizationEndpointBase; | ||
import org.tidepool.keycloak.extensions.model.RoleBean; | ||
import org.tidepool.keycloak.extensions.roles.UserRolePromptRequiredAction; | ||
|
||
final class RegistrationRoleDiscoveryAuthenticator implements Authenticator { | ||
|
||
@Override | ||
public void close() { | ||
} | ||
|
||
@Override | ||
public void authenticate(AuthenticationFlowContext context) { | ||
|
||
// Reset APP_INITIATED_FLOW so restart redirects to login, not registration | ||
context.getAuthenticationSession().setClientNote(AuthorizationEndpointBase.APP_INITIATED_FLOW, null); | ||
|
||
String role = context.getUriInfo().getQueryParameters().getFirst(RoleBean.PARAMETER_ROLE); | ||
if (RoleBean.ROLES_SET.contains(role)) { | ||
context.getAuthenticationSession().setAuthNote(RoleBean.AUTH_NOTE_ROLE, role); | ||
context.success(); | ||
} else { | ||
context.challenge(context.form().createForm(UserRolePromptRequiredAction.ROLES_FORM_FTL)); | ||
} | ||
} | ||
|
||
@Override | ||
public void action(AuthenticationFlowContext context) { | ||
String role = context.getHttpRequest().getDecodedFormParameters().getFirst(RoleBean.PARAMETER_ROLE); | ||
if (RoleBean.ROLES_SET.contains(role)) { | ||
context.getAuthenticationSession().setAuthNote(RoleBean.AUTH_NOTE_ROLE, role); | ||
context.success(); | ||
} else { | ||
context.failure(AuthenticationFlowError.INTERNAL_ERROR); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean requiresUser() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean configuredFor(KeycloakSession session, RealmModel realm, UserModel user) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void setRequiredActions(KeycloakSession session, RealmModel realm, UserModel user) { | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...pool/keycloak/extensions/authenticator/RegistrationRoleDiscoveryAuthenticatorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.tidepool.keycloak.extensions.authenticator; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.keycloak.Config.Scope; | ||
import org.keycloak.authentication.Authenticator; | ||
import org.keycloak.authentication.AuthenticatorFactory; | ||
import org.keycloak.models.AuthenticationExecutionModel.Requirement; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.KeycloakSessionFactory; | ||
import org.keycloak.provider.ProviderConfigProperty; | ||
import org.keycloak.provider.ServerInfoAwareProviderFactory; | ||
|
||
public final class RegistrationRoleDiscoveryAuthenticatorFactory | ||
implements AuthenticatorFactory, ServerInfoAwareProviderFactory { | ||
|
||
private static final String ID = "tidepool-registration-role-discovery"; | ||
|
||
private static final Requirement[] REQUIREMENT_CHOICES = { Requirement.REQUIRED, Requirement.DISABLED }; | ||
|
||
@Override | ||
public Authenticator create(KeycloakSession session) { | ||
return new RegistrationRoleDiscoveryAuthenticator(); | ||
} | ||
|
||
@Override | ||
public void init(Scope config) { | ||
} | ||
|
||
@Override | ||
public void postInit(KeycloakSessionFactory factory) { | ||
} | ||
|
||
@Override | ||
public void close() { | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return ID; | ||
} | ||
|
||
@Override | ||
public String getDisplayType() { | ||
return "Tidepool Registration Role Discovery"; | ||
} | ||
|
||
@Override | ||
public String getReferenceCategory() { | ||
return "registration-role-discovery"; | ||
} | ||
|
||
@Override | ||
public boolean isConfigurable() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Requirement[] getRequirementChoices() { | ||
return REQUIREMENT_CHOICES; | ||
} | ||
|
||
@Override | ||
public boolean isUserSetupAllowed() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getHelpText() { | ||
return "Ensures a role is provided upon registration via query parameter or displayed form and sets the associated auth note"; | ||
} | ||
|
||
@Override | ||
public List<ProviderConfigProperty> getConfigProperties() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Map<String, String> getOperationalInfo() { | ||
String version = getClass().getPackage().getImplementationVersion(); | ||
if (version == null) { | ||
version = "dev-snapshot"; | ||
} | ||
return Map.of("Version", version); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
.../main/java/org/tidepool/keycloak/extensions/authenticator/RegistrationRoleFormAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.tidepool.keycloak.extensions.authenticator; | ||
|
||
import org.keycloak.authentication.FormAction; | ||
import org.keycloak.authentication.FormContext; | ||
import org.keycloak.authentication.ValidationContext; | ||
import org.keycloak.forms.login.LoginFormsProvider; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.RealmModel; | ||
import org.keycloak.models.RoleModel; | ||
import org.keycloak.models.UserModel; | ||
import org.tidepool.keycloak.extensions.model.RoleBean; | ||
|
||
final class RegistrationRoleFormAction implements FormAction { | ||
|
||
private static final String EVENT_DETAIL_ROLE = "role"; | ||
|
||
@Override | ||
public void close() { | ||
} | ||
|
||
@Override | ||
public void buildPage(FormContext context, LoginFormsProvider form) { | ||
} | ||
|
||
@Override | ||
public void validate(ValidationContext context) { | ||
String role = context.getAuthenticationSession().getAuthNote(RoleBean.AUTH_NOTE_ROLE); | ||
if (RoleBean.ROLES_SET.contains(role)) { | ||
context.getEvent().detail(EVENT_DETAIL_ROLE, role); | ||
} | ||
|
||
context.success(); | ||
} | ||
|
||
@Override | ||
public void success(FormContext context) { | ||
String role = context.getAuthenticationSession().getAuthNote(RoleBean.AUTH_NOTE_ROLE); | ||
if (RoleBean.ROLES_SET.contains(role)) { | ||
RoleModel roleModel = context.getRealm().getRole(role); | ||
if (roleModel != null) { | ||
context.getUser().grantRole(roleModel); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean requiresUser() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean configuredFor(KeycloakSession session, RealmModel realm, UserModel user) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void setRequiredActions(KeycloakSession session, RealmModel realm, UserModel user) { | ||
} | ||
} |
Oops, something went wrong.