forked from p2-inc/keycloak-orgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
p2-inc#235 Implement own authenticator base on HomeIdp discovery
Use some tricks
- Loading branch information
Showing
47 changed files
with
172 additions
and
1,981 deletions.
There are no files selected for viewing
Binary file not shown.
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
File renamed without changes.
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
13 changes: 5 additions & 8 deletions
13
...il/OrgsEmailHomeIdpDiscovererFactory.java → ...pd/OrgsEmailHomeIdpDiscovererFactory.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
25 changes: 25 additions & 0 deletions
25
src/main/java/de/sventorben/keycloak/authentication/hidpd/OrgsIdentityProviders.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,25 @@ | ||
package de.sventorben.keycloak.authentication.hidpd; | ||
|
||
import de.sventorben.keycloak.authentication.hidpd.discovery.email.Domain; | ||
import de.sventorben.keycloak.authentication.hidpd.discovery.email.IdentityProviders; | ||
import io.phasetwo.service.model.OrganizationModel; | ||
import io.phasetwo.service.model.OrganizationProvider; | ||
import org.keycloak.authentication.AuthenticationFlowContext; | ||
import org.keycloak.models.IdentityProviderModel; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
final class OrgsIdentityProviders implements IdentityProviders { | ||
|
||
@Override | ||
public List<IdentityProviderModel> withMatchingDomain(AuthenticationFlowContext context, List<IdentityProviderModel> candidates, Domain domain) { | ||
var orgs = context.getSession().getProvider(OrganizationProvider.class); | ||
var config = new OrgsEmailHomeIdpDiscovererConfig(context.getAuthenticatorConfig()); | ||
return orgs.getOrganizationsStreamForDomain( | ||
context.getRealm(), domain.toString(), config.requireVerifiedDomain()) | ||
.flatMap(OrganizationModel::getIdentityProvidersStream) | ||
.filter(IdentityProviderModel::isEnabled) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
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
110 changes: 110 additions & 0 deletions
110
src/main/java/de/sventorben/keycloak/authentication/hidpd/PhaseTwoAuthenticatorFactory.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,110 @@ | ||
package de.sventorben.keycloak.authentication.hidpd; | ||
|
||
import com.google.auto.service.AutoService; | ||
import org.keycloak.Config; | ||
import org.keycloak.authentication.Authenticator; | ||
import org.keycloak.authentication.AuthenticatorFactory; | ||
import org.keycloak.models.AuthenticationExecutionModel; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.KeycloakSessionFactory; | ||
import org.keycloak.provider.ProviderConfigProperty; | ||
import org.keycloak.provider.ServerInfoAwareProviderFactory; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static org.keycloak.models.AuthenticationExecutionModel.Requirement.ALTERNATIVE; | ||
import static org.keycloak.models.AuthenticationExecutionModel.Requirement.DISABLED; | ||
import static org.keycloak.models.AuthenticationExecutionModel.Requirement.REQUIRED; | ||
|
||
@AutoService(AuthenticatorFactory.class) | ||
public final class PhaseTwoAuthenticatorFactory implements AuthenticatorFactory, ServerInfoAwareProviderFactory { | ||
|
||
private static final AuthenticationExecutionModel.Requirement[] REQUIREMENT_CHOICES = new AuthenticationExecutionModel.Requirement[]{REQUIRED, ALTERNATIVE, DISABLED}; | ||
|
||
private static final String PROVIDER_ID = "ext-auth-home-idp-discovery"; | ||
|
||
public Authenticator create(KeycloakSession session) { | ||
|
||
//@xpg -this could be simplified if we could convince the HomeIDPProvider guy to remove final from the creation phase | ||
// public final Authenticator create(KeycloakSession session) { | ||
// return new HomeIdpDiscoveryAuthenticator(discovererConfig); | ||
// } | ||
return new PhaseTwoAuthenticator(new AbstractHomeIdpDiscoveryAuthenticatorFactory.DiscovererConfig() { | ||
public List<ProviderConfigProperty> getProperties() { | ||
return OrgsEmailHomeIdpDiscovererConfig.CONFIG_PROPERTIES; | ||
} | ||
|
||
public String getProviderId() { | ||
return "orgs-ext-email"; | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public String getDisplayType() { | ||
return "PhaseTwo Home IdP Discovery"; | ||
} | ||
|
||
@Override | ||
public String getReferenceCategory() { | ||
return "Authorization"; | ||
} | ||
|
||
@Override | ||
public boolean isConfigurable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public final AuthenticationExecutionModel.Requirement[] getRequirementChoices() { | ||
return REQUIREMENT_CHOICES; | ||
} | ||
|
||
@Override | ||
public boolean isUserSetupAllowed() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getHelpText() { | ||
return "Redirects users to their home identity provider"; | ||
} | ||
|
||
@Override | ||
public final List<ProviderConfigProperty> getConfigProperties() { | ||
return Stream.concat( | ||
HomeIdpForwarderConfigProperties.CONFIG_PROPERTIES.stream(), | ||
OrgsEmailHomeIdpDiscovererConfig.CONFIG_PROPERTIES.stream()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return PROVIDER_ID; | ||
} | ||
|
||
@Override | ||
public Map<String, String> getOperationalInfo() { | ||
return OperationalInfo.get(); | ||
} | ||
|
||
|
||
@Override | ||
public void init(Config.Scope scope) { | ||
|
||
} | ||
|
||
@Override | ||
public void postInit(KeycloakSessionFactory keycloakSessionFactory) { | ||
|
||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
} | ||
|
134 changes: 0 additions & 134 deletions
134
src/main/java/io/phasetwo/service/auth/idp/AbstractHomeIdpDiscoveryAuthenticatorFactory.java
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
src/main/java/io/phasetwo/service/auth/idp/AlwaysSelectableIdentityProviderModel.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.