-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
185 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Authn/Authz Util |
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,23 @@ | ||
name: fts-auth | ||
|
||
services: | ||
keycloak: | ||
image: quay.io/keycloak/keycloak:25.0.6 | ||
command: [ "start-dev" ] | ||
environment: | ||
KEYCLOAK_ADMIN: admin | ||
KEYCLOAK_ADMIN_PASSWORD: admin | ||
ports: | ||
- "8080:8080" | ||
networks: [ "clinical-domain", "research-domain", "trust-center" ] | ||
|
||
networks: | ||
clinical-domain: | ||
external: true | ||
name: fts-test_clinical-domain | ||
research-domain: | ||
external: true | ||
name: fts-test_research-domain | ||
trust-center: | ||
external: true | ||
name: fts-test_trust-center |
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,31 @@ | ||
server: | ||
port: 9090 | ||
|
||
projects: | ||
directory: "../.github/test/cd-agent/projects" | ||
|
||
security: | ||
auth: | ||
oauth2: | ||
issuer: http://localhost:8080/realms/master | ||
|
||
spring: | ||
security: | ||
oauth2: | ||
client: | ||
registration: | ||
agent: | ||
authorizationGrantType: client_credentials | ||
clientId: fts/cd-agent | ||
clientSecret: eA4xj1zFxsVYZGdLah9KnkcmHYDBjojr | ||
provider: keycloak | ||
provider: | ||
keycloak: | ||
issuer-uri: http://localhost:8080/realms/master | ||
|
||
test: | ||
webclient: | ||
default: | ||
auth: | ||
oauth2: | ||
registration: agent |
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
35 changes: 35 additions & 0 deletions
35
util/src/main/java/care/smith/fts/util/auth/HttpClientOAuth2Auth.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,35 @@ | ||
package care.smith.fts.util.auth; | ||
|
||
import care.smith.fts.util.auth.HttpClientOAuth2Auth.Config; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.security.oauth2.client.ReactiveOAuth2AuthorizedClientManager; | ||
import org.springframework.security.oauth2.client.web.reactive.function.client.ServerOAuth2AuthorizedClientExchangeFilterFunction; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.client.WebClient.Builder; | ||
|
||
/** OAuth2 Authentication using oauth2 client credentials flow. */ | ||
@Slf4j | ||
@Component | ||
@ConditionalOnBean(ReactiveOAuth2AuthorizedClientManager.class) | ||
public class HttpClientOAuth2Auth implements HttpClientAuth<Config> { | ||
|
||
private final ReactiveOAuth2AuthorizedClientManager clientManager; | ||
|
||
public HttpClientOAuth2Auth(ReactiveOAuth2AuthorizedClientManager clientManager) { | ||
this.clientManager = clientManager; | ||
} | ||
|
||
public record Config(String registration) {} | ||
|
||
@Override | ||
public void configure(Config config, Builder builder) { | ||
log.debug( | ||
"Configuring oauth2 client, registration '{}', clientManager: {}", | ||
config.registration(), | ||
clientManager); | ||
var filter = new ServerOAuth2AuthorizedClientExchangeFilterFunction(clientManager); | ||
filter.setDefaultClientRegistrationId(config.registration()); | ||
builder.filter(filter); | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
util/src/main/java/care/smith/fts/util/auth/HttpServerOAuth2Auth.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,33 @@ | ||
package care.smith.fts.util.auth; | ||
|
||
import static org.springframework.security.oauth2.jwt.ReactiveJwtDecoders.fromIssuerLocation; | ||
|
||
import care.smith.fts.util.auth.HttpServerAuthConfig.Endpoint; | ||
import org.springframework.security.config.web.server.ServerHttpSecurity; | ||
import org.springframework.security.core.userdetails.ReactiveUserDetailsService; | ||
|
||
public record HttpServerOAuth2Auth(String issuer) implements HttpServerAuthMethod { | ||
|
||
@Override | ||
public ServerHttpSecurity configure(ServerHttpSecurity http) { | ||
return http.oauth2ResourceServer( | ||
oauth2 -> oauth2.jwt(jwt -> jwt.jwtDecoder(fromIssuerLocation(issuer)))); | ||
} | ||
|
||
@Override | ||
public ServerHttpSecurity filter(Endpoint endpoint, ServerHttpSecurity http) { | ||
return http.authorizeExchange( | ||
exchange -> exchange.pathMatchers(endpoint.path()).hasAuthority(endpoint.role())); | ||
} | ||
|
||
@Override | ||
public ReactiveUserDetailsService configureUsers() { | ||
// Since it's client credentials, we don't configure users explicitly here. | ||
return null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "OAuth2"; | ||
} | ||
} |
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