-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 #37760 from michalvavrik/feature/oidc-event-for-en…
…dpoint-not-available Fire OIDC security event when OIDC server not available
- Loading branch information
Showing
6 changed files
with
191 additions
and
17 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
44 changes: 44 additions & 0 deletions
44
integration-tests/oidc-wiremock/src/main/java/io/quarkus/it/keycloak/OidcEventObserver.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 io.quarkus.it.keycloak; | ||
|
||
import static io.quarkus.oidc.SecurityEvent.AUTH_SERVER_URL; | ||
|
||
import java.util.Set; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import jakarta.enterprise.event.Observes; | ||
import jakarta.inject.Singleton; | ||
|
||
import io.quarkus.oidc.SecurityEvent; | ||
|
||
@Singleton | ||
public class OidcEventObserver { | ||
|
||
private final Set<String> unavailableAuthServerUrls = ConcurrentHashMap.newKeySet(); | ||
private final Set<String> availableAuthServerUrls = ConcurrentHashMap.newKeySet(); | ||
|
||
void observe(@Observes SecurityEvent event) { | ||
if (event.getEventType() == SecurityEvent.Type.OIDC_SERVER_NOT_AVAILABLE) { | ||
String authServerUrl = dropTrailingSlash((String) event.getEventProperties().get(AUTH_SERVER_URL)); | ||
unavailableAuthServerUrls.add(authServerUrl); | ||
} else if (event.getEventType() == SecurityEvent.Type.OIDC_SERVER_AVAILABLE) { | ||
String authServerUrl = (String) event.getEventProperties().get(AUTH_SERVER_URL); | ||
availableAuthServerUrls.add(authServerUrl); | ||
} | ||
} | ||
|
||
public static String dropTrailingSlash(String authServerUrl) { | ||
if (authServerUrl.endsWith("/")) { | ||
// drop ending slash as these auth server urls are same in principle | ||
return authServerUrl.substring(0, authServerUrl.length() - 1); | ||
} | ||
return authServerUrl; | ||
} | ||
|
||
Set<String> getUnavailableAuthServerUrls() { | ||
return unavailableAuthServerUrls; | ||
} | ||
|
||
Set<String> getAvailableAuthServerUrls() { | ||
return availableAuthServerUrls; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
integration-tests/oidc-wiremock/src/main/java/io/quarkus/it/keycloak/OidcEventResource.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,49 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import static io.quarkus.it.keycloak.OidcEventObserver.dropTrailingSlash; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import io.quarkus.oidc.runtime.OidcConfig; | ||
|
||
@Path("/oidc-event") | ||
public class OidcEventResource { | ||
|
||
private final OidcEventObserver oidcEventObserver; | ||
private final String expectedAuthServerUrl; | ||
|
||
public OidcEventResource(OidcEventObserver oidcEventObserver, OidcConfig oidcConfig) { | ||
this.expectedAuthServerUrl = dropTrailingSlash(oidcConfig.defaultTenant.authServerUrl.get()); | ||
this.oidcEventObserver = oidcEventObserver; | ||
} | ||
|
||
@Path("/unavailable-auth-server-urls") | ||
@GET | ||
public String unavailableAuthServerUrls() { | ||
return oidcEventObserver | ||
.getUnavailableAuthServerUrls() | ||
.stream() | ||
.sorted(String::compareTo) | ||
.collect(Collectors.joining("-")); | ||
} | ||
|
||
@Path("/available-auth-server-urls") | ||
@GET | ||
public String availableAuthServerUrls() { | ||
return oidcEventObserver | ||
.getAvailableAuthServerUrls() | ||
.stream() | ||
.sorted(String::compareTo) | ||
.collect(Collectors.joining("-")); | ||
} | ||
|
||
@GET | ||
@Path("/expected-auth-server-url") | ||
public String getExpectedAuthServerUrl() { | ||
return expectedAuthServerUrl; | ||
} | ||
|
||
} |
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