Skip to content

Commit

Permalink
Fix forced PKCE
Browse files Browse the repository at this point in the history
  • Loading branch information
ch4mpy committed Feb 29, 2024
1 parent 781636a commit c241145
Show file tree
Hide file tree
Showing 39 changed files with 366 additions and 260 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.c4-soft.springaddons</groupId>
<artifactId>spring-addons</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<packaging>pom</packaging>
<name>spring-addons</name>
<description>Set of tools I find useful to work with Spring (mostly spring-security for OpenID)</description>
Expand Down
2 changes: 1 addition & 1 deletion release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## `7.x` Branch

### `7.6.1`
### `7.6.3`
- Spring Boot 3.2.3
- add `com.c4-soft.springaddons.oidc.client.pkce-forced` property. Default to `false`. When `true`, PKCE is used by clients for authorization-code flows, even by confidential clients
- move [the BFF tutorial to Baeldung](https://www.baeldung.com/spring-cloud-gateway-bff-oauth2). It is also refreshed and now contains sample implementations for React (Next.js) and Vue (Vite).
Expand Down
2 changes: 1 addition & 1 deletion samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons</groupId>
<artifactId>spring-addons</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<groupId>com.c4-soft.springaddons.samples</groupId>
Expand Down
2 changes: 1 addition & 1 deletion samples/tutorials/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples</groupId>
<artifactId>spring-addons-samples</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<groupId>com.c4-soft.springaddons.samples.tutorials</groupId>
Expand Down
2 changes: 1 addition & 1 deletion samples/tutorials/reactive-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples.tutorials</groupId>
<artifactId>tutorials</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>reactive-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion samples/tutorials/reactive-resource-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples.tutorials</groupId>
<artifactId>tutorials</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>reactive-resource-server</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples.tutorials</groupId>
<artifactId>tutorials</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>resource-server_multitenant_dynamic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples.tutorials</groupId>
<artifactId>tutorials</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>resource-server_with_additional-header</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples.tutorials</groupId>
<artifactId>tutorials</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>resource-server_with_introspection</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples.tutorials</groupId>
<artifactId>tutorials</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>resource-server_with_oauthentication</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples.tutorials</groupId>
<artifactId>tutorials</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>resource-server_with_specialized_oauthentication</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion samples/tutorials/resource-server_with_ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples.tutorials</groupId>
<artifactId>tutorials</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>resource-server_with_ui</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ com:
post-login-redirect-path: /ui/greet
post-logout-redirect-path: /ui/greet
multi-tenancy-enabled: true
pkce-forced: true
oauth2-logout:
cognito-confidential-user:
uri: https://spring-addons.auth.us-west-2.amazoncognito.com/logout
Expand All @@ -123,7 +124,7 @@ logging:
level:
org:
springframework:
security: INFO
security: DEBUG
boot: INFO

management:
Expand Down
2 changes: 1 addition & 1 deletion samples/tutorials/servlet-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples.tutorials</groupId>
<artifactId>tutorials</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>servlet-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion samples/tutorials/servlet-resource-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples.tutorials</groupId>
<artifactId>tutorials</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>servlet-resource-server</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion samples/webflux-introspecting-default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples</groupId>
<artifactId>spring-addons-samples</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion samples/webflux-introspecting-oauthentication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples</groupId>
<artifactId>spring-addons-samples</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion samples/webflux-jwt-default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples</groupId>
<artifactId>spring-addons-samples</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion samples/webflux-jwt-oauthentication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples</groupId>
<artifactId>spring-addons-samples</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion samples/webmvc-introspecting-default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples</groupId>
<artifactId>spring-addons-samples</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion samples/webmvc-introspecting-oauthentication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples</groupId>
<artifactId>spring-addons-samples</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion samples/webmvc-jwt-default-jpa-authorities/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples</groupId>
<artifactId>spring-addons-samples</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion samples/webmvc-jwt-default/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples</groupId>
<artifactId>spring-addons-samples</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion samples/webmvc-jwt-oauthentication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons.samples</groupId>
<artifactId>spring-addons-samples</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-addons-oauth2-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.c4-soft.springaddons</groupId>
<artifactId>spring-addons</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-addons-oauth2-test</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion spring-addons-oauth2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.c4-soft.springaddons</groupId>
<artifactId>spring-addons</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-addons-oauth2</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion spring-addons-starter-oidc-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.c4-soft.springaddons</groupId>
<artifactId>spring-addons</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-addons-starter-oidc-test</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion spring-addons-starter-oidc/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This project is a Spring Boot starter to use in addition to `spring-boot-starter

```xml
<properties>
<springaddons.version>7.6.1</springaddons.version>
<springaddons.version>7.6.3</springaddons.version>
</properties>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion spring-addons-starter-oidc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.c4-soft.springaddons</groupId>
<artifactId>spring-addons</artifactId>
<version>7.6.2-SNAPSHOT</version>
<version>7.6.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>spring-addons-starter-oidc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.c4_soft.springaddons.security.oidc.starter;

import java.util.Collection;
import java.util.function.Consumer;

import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest.Builder;

import com.c4_soft.springaddons.security.oidc.starter.properties.SpringAddonsOidcClientProperties.RequestParam;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class AdditionalParamsAuthorizationRequestCustomizer implements Consumer<OAuth2AuthorizationRequest.Builder> {
private final Collection<RequestParam> additionalParams;

@Override
public void accept(Builder t) {
t.additionalParameters(params -> {
for (var reqParam : additionalParams) {
params.put(reqParam.getName(), reqParam.getValue());
}
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.c4_soft.springaddons.security.oidc.starter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest;
import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest.Builder;

public class CompositeOAuth2AuthorizationRequestCustomizer implements Consumer<OAuth2AuthorizationRequest.Builder> {
private final List<Consumer<OAuth2AuthorizationRequest.Builder>> delegates;

public CompositeOAuth2AuthorizationRequestCustomizer(Consumer<OAuth2AuthorizationRequest.Builder>... customizers) {
delegates = new ArrayList<>(customizers.length + 3);
Collections.addAll(delegates, customizers);
}

@Override
public void accept(Builder t) {
for (var consumer : delegates) {
consumer.accept(t);
}
}

public CompositeOAuth2AuthorizationRequestCustomizer addCustomizer(Consumer<OAuth2AuthorizationRequest.Builder> customizer) {
this.delegates.add(customizer);
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
Expand Down Expand Up @@ -62,8 +63,8 @@
* <li>clientAuthorizePostProcessor: a {@link ClientAuthorizeExchangeSpecPostProcessor} post processor to fine tune access control from java
* configuration. It applies to all routes not listed in "permit-all" property configuration. Default requires users to be
* authenticated.</li>
* <li>clientHttpPostProcessor: a {@link ClientReactiveHttpSecurityPostProcessor} to override anything from above auto-configuration. It is called
* just before the security filter-chain is returned. Default is a no-op.</li>
* <li>clientHttpPostProcessor: a {@link ClientReactiveHttpSecurityPostProcessor} to override anything from above auto-configuration. It is
* called just before the security filter-chain is returned. Default is a no-op.</li>
* <li>authorizationRequestResolver: a {@link ServerOAuth2AuthorizationRequestResolver} to add custom parameters (from application
* properties) to authorization code request</li>
* </ul>
Expand Down Expand Up @@ -245,8 +246,9 @@ WebFilter csrfCookieWebFilter() {

@ConditionalOnMissingBean
@Bean
ServerOAuth2AuthorizationRequestResolver authorizationRequestResolver(ReactiveClientRegistrationRepository clientRegistrationRepository, SpringAddonsOidcProperties addonsProperties) {
return new SpringAddonsServerOAuth2AuthorizationRequestResolver(clientRegistrationRepository, addonsProperties.getClient());
ServerOAuth2AuthorizationRequestResolver authorizationRequestResolver(
OAuth2ClientProperties bootClientProperties, ReactiveClientRegistrationRepository clientRegistrationRepository, SpringAddonsOidcProperties addonsProperties) {
return new SpringAddonsServerOAuth2AuthorizationRequestResolver(bootClientProperties, clientRegistrationRepository, addonsProperties.getClient());
}

@ConditionalOnMissingBean
Expand Down
Loading

0 comments on commit c241145

Please sign in to comment.