Skip to content

Commit 718b099

Browse files
committed
Updates OAuth2ResourceServer configuration tests
Refactores collapsed imports
1 parent e7f93f2 commit 718b099

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

config/src/test/java/org/springframework/security/config/annotation/web/configurers/oauth2/server/resource/OAuth2ResourceServerConfigurerTests.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.time.Instant;
2828
import java.time.ZoneId;
2929
import java.util.Base64;
30-
import java.util.Collection;
3130
import java.util.Collections;
3231
import java.util.Map;
3332
import java.util.stream.Collectors;
@@ -1484,12 +1483,11 @@ protected void configure(HttpSecurity http) throws Exception {
14841483
}
14851484

14861485
Converter<Jwt, AbstractAuthenticationToken> getJwtAuthenticationConverter() {
1487-
return new JwtAuthenticationConverter() {
1488-
@Override
1489-
protected Collection<GrantedAuthority> extractAuthorities(Jwt jwt) {
1490-
return Collections.singletonList(new SimpleGrantedAuthority("message:read"));
1491-
}
1492-
};
1486+
JwtAuthenticationConverter converter = new JwtAuthenticationConverter();
1487+
converter.setJwtGrantedAuthoritiesConverter(jwt ->
1488+
Collections.singletonList(new SimpleGrantedAuthority("message:read"))
1489+
);
1490+
return converter;
14931491
}
14941492
}
14951493

config/src/test/java/org/springframework/security/config/web/server/OAuth2ResourceServerSpecTests.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.security.spec.RSAPublicKeySpec;
2626
import java.time.Instant;
2727
import java.util.Base64;
28-
import java.util.Collection;
2928
import java.util.Collections;
3029
import java.util.Optional;
3130
import java.util.stream.Collectors;
@@ -56,7 +55,6 @@
5655
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
5756
import org.springframework.security.config.test.SpringTestRule;
5857
import org.springframework.security.core.Authentication;
59-
import org.springframework.security.core.GrantedAuthority;
6058
import org.springframework.security.core.authority.SimpleGrantedAuthority;
6159
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
6260
import org.springframework.security.oauth2.core.OAuth2Error;
@@ -556,13 +554,12 @@ SecurityWebFilterChain springSecurity(ServerHttpSecurity http) throws Exception
556554

557555
@Bean
558556
Converter<Jwt, Mono<AbstractAuthenticationToken>> jwtAuthenticationConverter() {
559-
JwtAuthenticationConverter converter = new JwtAuthenticationConverter() {
560-
@Override
561-
protected Collection<GrantedAuthority> extractAuthorities(Jwt jwt) {
557+
558+
JwtAuthenticationConverter converter = new JwtAuthenticationConverter();
559+
converter.setJwtGrantedAuthoritiesConverter(jwt -> {
562560
String[] claims = ((String) jwt.getClaims().get("scope")).split(" ");
563561
return Stream.of(claims).map(SimpleGrantedAuthority::new).collect(Collectors.toList());
564-
}
565-
};
562+
});
566563

567564
return new ReactiveJwtAuthenticationConverterAdapter(converter);
568565
}

0 commit comments

Comments
 (0)