-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support KC Organization Feature (DRAFT)
This is just a rough draft - needs testing and refactorings.
- Loading branch information
1 parent
810d84a
commit e10811a
Showing
16 changed files
with
355 additions
and
16 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
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
15 changes: 15 additions & 0 deletions
15
src/main/java/de/sventorben/keycloak/authentication/hidpd/OperationalInfo.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,15 @@ | ||
package de.sventorben.keycloak.authentication.hidpd; | ||
|
||
import java.util.Map; | ||
|
||
public final class OperationalInfo { | ||
|
||
public static Map<String, String> get() { | ||
String version = OperationalInfo.class.getPackage().getImplementationVersion(); | ||
if (version == null) { | ||
version = "dev-snapshot"; | ||
} | ||
return Map.of("Version", version); | ||
} | ||
|
||
} |
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
44 changes: 44 additions & 0 deletions
44
...ntorben/keycloak/authentication/hidpd/discovery/orgs/domainhint/OrgsDomainDiscoverer.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,44 @@ | ||
package de.sventorben.keycloak.authentication.hidpd.discovery.orgs.domainhint; | ||
|
||
import de.sventorben.keycloak.authentication.hidpd.discovery.spi.HomeIdpDiscoverer; | ||
import org.keycloak.authentication.AuthenticationFlowContext; | ||
import org.keycloak.models.IdentityProviderModel; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.OrganizationModel; | ||
import org.keycloak.organization.OrganizationProvider; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
final class OrgsDomainDiscoverer implements HomeIdpDiscoverer { | ||
|
||
private final KeycloakSession keycloakSession; | ||
|
||
OrgsDomainDiscoverer(KeycloakSession keycloakSession) { | ||
this.keycloakSession = keycloakSession; | ||
} | ||
|
||
@Override | ||
public List<IdentityProviderModel> discoverForUser(AuthenticationFlowContext context, String username) { | ||
String domain = username; | ||
OrganizationProvider orgProvider = keycloakSession.getProvider(OrganizationProvider.class); | ||
|
||
if (!orgProvider.isEnabled()) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
OrganizationModel org = orgProvider.getByDomainName(domain); | ||
if (org != null) { | ||
IdentityProviderModel idp = org.getIdentityProvider(); | ||
if (idp != null) { | ||
return Collections.singletonList(idp); | ||
} | ||
} | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...k/authentication/hidpd/discovery/orgs/domainhint/OrgsDomainDiscovererProviderFactory.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,54 @@ | ||
package de.sventorben.keycloak.authentication.hidpd.discovery.orgs.domainhint; | ||
|
||
import de.sventorben.keycloak.authentication.hidpd.OperationalInfo; | ||
import de.sventorben.keycloak.authentication.hidpd.discovery.spi.HomeIdpDiscoverer; | ||
import de.sventorben.keycloak.authentication.hidpd.discovery.spi.HomeIdpDiscovererFactory; | ||
import org.keycloak.Config; | ||
import org.keycloak.common.Profile; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.KeycloakSessionFactory; | ||
import org.keycloak.provider.EnvironmentDependentProviderFactory; | ||
import org.keycloak.provider.ServerInfoAwareProviderFactory; | ||
|
||
import java.util.Map; | ||
|
||
public final class OrgsDomainDiscovererProviderFactory implements HomeIdpDiscovererFactory, EnvironmentDependentProviderFactory, ServerInfoAwareProviderFactory { | ||
|
||
private static final String PROVIDER_ID = "orgs-domain"; | ||
|
||
@Override | ||
public boolean isSupported(Config.Scope config) { | ||
return Profile.isFeatureEnabled(Profile.Feature.ORGANIZATION); | ||
} | ||
|
||
@Override | ||
public HomeIdpDiscoverer create(KeycloakSession keycloakSession) { | ||
return new OrgsDomainDiscoverer(keycloakSession); | ||
} | ||
|
||
@Override | ||
public void init(Config.Scope scope) { | ||
|
||
} | ||
|
||
@Override | ||
public void postInit(KeycloakSessionFactory keycloakSessionFactory) { | ||
|
||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
|
||
@Override | ||
public String getId() { | ||
return PROVIDER_ID; | ||
} | ||
|
||
@Override | ||
public final Map<String, String> getOperationalInfo() { | ||
return OperationalInfo.get(); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...ation/hidpd/discovery/orgs/domainhint/OrgsDomainHomeIdpDiscoveryAuthenticatorFactory.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,53 @@ | ||
package de.sventorben.keycloak.authentication.hidpd.discovery.orgs.domainhint; | ||
|
||
import de.sventorben.keycloak.authentication.hidpd.AbstractHomeIdpDiscoveryAuthenticatorFactory; | ||
import org.keycloak.Config; | ||
import org.keycloak.common.Profile; | ||
import org.keycloak.provider.EnvironmentDependentProviderFactory; | ||
import org.keycloak.provider.ProviderConfigProperty; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public final class OrgsDomainHomeIdpDiscoveryAuthenticatorFactory extends AbstractHomeIdpDiscoveryAuthenticatorFactory implements EnvironmentDependentProviderFactory { | ||
private static final String PROVIDER_ID = "orgs-domain"; | ||
|
||
@Override | ||
public boolean isSupported(Config.Scope config) { | ||
return Profile.isFeatureEnabled(Profile.Feature.ORGANIZATION); | ||
} | ||
|
||
public OrgsDomainHomeIdpDiscoveryAuthenticatorFactory() { | ||
super(new DiscovererConfig() { | ||
@Override | ||
public List<ProviderConfigProperty> getProperties() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public String getProviderId() { | ||
return PROVIDER_ID; | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return PROVIDER_ID; | ||
} | ||
|
||
@Override | ||
public String getDisplayType() { | ||
return "Home IdP Discovery - Organization via Domain Hint"; | ||
} | ||
|
||
@Override | ||
public String getReferenceCategory() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getHelpText() { | ||
return "Redirects users to their organization's identity provider which will be discovered based on a domain hint"; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...keycloak/authentication/hidpd/discovery/orgs/email/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package de.sventorben.keycloak.authentication.hidpd.discovery.orgs.email; | ||
|
||
import de.sventorben.keycloak.authentication.hidpd.OperationalInfo; | ||
import de.sventorben.keycloak.authentication.hidpd.Users; | ||
import de.sventorben.keycloak.authentication.hidpd.discovery.email.EmailHomeIdpDiscoverer; | ||
import de.sventorben.keycloak.authentication.hidpd.discovery.spi.HomeIdpDiscoverer; | ||
import de.sventorben.keycloak.authentication.hidpd.discovery.spi.HomeIdpDiscovererFactory; | ||
import org.keycloak.Config; | ||
import org.keycloak.models.KeycloakSession; | ||
import org.keycloak.models.KeycloakSessionFactory; | ||
import org.keycloak.provider.ServerInfoAwareProviderFactory; | ||
|
||
import java.util.Map; | ||
|
||
public final class OrgsEmailHomeIdpDiscovererFactory implements HomeIdpDiscovererFactory, ServerInfoAwareProviderFactory { | ||
|
||
static final String PROVIDER_ID = "orgs-email"; | ||
|
||
@Override | ||
public HomeIdpDiscoverer create(KeycloakSession keycloakSession) { | ||
return new EmailHomeIdpDiscoverer(new Users(keycloakSession), new OrgsIdentityProviders()); | ||
} | ||
|
||
@Override | ||
public void init(Config.Scope scope) { | ||
|
||
} | ||
|
||
@Override | ||
public void postInit(KeycloakSessionFactory keycloakSessionFactory) { | ||
|
||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
|
||
@Override | ||
public String getId() { | ||
return PROVIDER_ID; | ||
} | ||
|
||
@Override | ||
public final Map<String, String> getOperationalInfo() { | ||
return OperationalInfo.get(); | ||
} | ||
} |
Oops, something went wrong.