Skip to content

Commit

Permalink
KNOX-2982 - Having one disabled one enabled identity-assertion provid…
Browse files Browse the repository at this point in the history
…er in knoxsso doesn't work (#832)
  • Loading branch information
zeroflag authored Jan 16, 2024
1 parent bb6719f commit 16daa62
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.knox.gateway.descriptor.ResourceDescriptor;
import org.apache.knox.gateway.topology.Provider;
import org.apache.knox.gateway.topology.Service;
import org.apache.knox.gateway.topology.Topology;
import org.apache.knox.gateway.topology.Version;

import java.net.URISyntaxException;
Expand Down Expand Up @@ -82,7 +83,9 @@ protected void addAuthenticationFilter( DeploymentContext context, Service servi
protected void addIdentityAssertionFilter( DeploymentContext context, Service service, ResourceDescriptor resource) {
if( topologyContainsProviderType( context, "authentication" ) ||
topologyContainsProviderType( context, "federation" ) ) {
context.contributeFilter( service, resource, "identity-assertion", null, null );
Topology topology = context.getTopology();
Provider activeProvider = topology.getProvider("identity-assertion", null);
context.contributeFilter(service, resource, "identity-assertion", activeProvider != null ? activeProvider.getName() : null, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ public Provider getProvider( String role, String name ) {
provider = nameMap.get( name );
}
else {
provider = (Provider) nameMap.values().toArray()[0];
provider = nameMap.values().stream()
.filter(Provider::isEnabled)
.findFirst()
.orElse((Provider) nameMap.values().toArray()[0]);
}
}
return provider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ public void testNullApplications() {
assertEquals(t1, t2);
}

@Test
public void testGettingMultipleProvidersReturnsTheFirstEnabled() {
Topology topology = new Topology();

Provider disabledProvider = new Provider();
disabledProvider.setRole("identity-assertion");
disabledProvider.setName("disabled_prov");
disabledProvider.setEnabled(false);
topology.addProvider(disabledProvider);

Provider enabledProvider = new Provider();
enabledProvider.setName("enabled_prov");
enabledProvider.setRole("identity-assertion");
enabledProvider.setEnabled(true);
topology.addProvider(enabledProvider);

assertEquals("enabled_prov", topology.getProvider("identity-assertion", null).getName());
}

@Test
public void testEmptyTopologiesWithSameName() {
final String name = "tName";
Expand Down

0 comments on commit 16daa62

Please sign in to comment.