Skip to content

Commit

Permalink
feat: Adjust Organization support to latest upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sventorben committed Jun 10, 2024
1 parent 22695bf commit 5022bab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

final class OrgsDomainDiscoverer implements HomeIdpDiscoverer {

Expand All @@ -29,10 +30,9 @@ public List<IdentityProviderModel> discoverForUser(AuthenticationFlowContext con

OrganizationModel org = orgProvider.getByDomainName(domain);
if (org != null) {
IdentityProviderModel idp = org.getIdentityProvider();
if (idp != null) {
return Collections.singletonList(idp);
}
return org.getIdentityProviders()
.filter(IdentityProviderModel::isEnabled)
.collect(Collectors.toList());
}
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import de.sventorben.keycloak.authentication.hidpd.discovery.email.IdentityProviders;
import org.keycloak.authentication.AuthenticationFlowContext;
import org.keycloak.models.IdentityProviderModel;
import org.keycloak.models.OrganizationDomainModel;
import org.keycloak.models.OrganizationModel;
import org.keycloak.models.UserModel;
import org.keycloak.organization.OrganizationProvider;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

final class OrgsIdentityProviders implements IdentityProviders {

Expand All @@ -22,11 +24,10 @@ public List<IdentityProviderModel> candidatesForHomeIdp(AuthenticationFlowContex
}
if (orgProvider.isEnabled()) {
OrganizationModel org = orgProvider.getByMember(user);
if (org != null) {
IdentityProviderModel orgIdp = org.getIdentityProvider();
if (orgIdp != null) {
return Collections.singletonList(orgIdp);
}
if (org != null && org.isEnabled()) {
return org.getIdentityProviders()
.filter(IdentityProviderModel::isEnabled)
.collect(Collectors.toList());
}
} else {
// TODO: Log a warning
Expand All @@ -39,18 +40,21 @@ public List<IdentityProviderModel> withMatchingDomain(AuthenticationFlowContext
OrganizationProvider orgProvider = context.getSession().getProvider(OrganizationProvider.class);
if (orgProvider.isEnabled()) {
OrganizationModel org = orgProvider.getByDomainName(domain.getRawValue());
if (org != null) {
IdentityProviderModel orgIdp = org.getIdentityProvider();
if (orgIdp != null) {
List<IdentityProviderModel> result = new ArrayList<>(candidates);
result.add(orgIdp);
return result;
if (org != null && org.isEnabled()) {
boolean verified = org.getDomains()
.filter(it -> domain.getRawValue().equalsIgnoreCase(it.getName()))
.anyMatch(OrganizationDomainModel::getVerified);
if (verified) {
return org.getIdentityProviders()
.filter(IdentityProviderModel::isEnabled)
// TODO: Filter based on domain - should only be one
.collect(Collectors.toList());
}
}
} else {
// TODO: Log a warning
}
return candidates;
return Collections.emptyList();
}

}

0 comments on commit 5022bab

Please sign in to comment.