Accept Converter in ReactiveJwtAuthenticationConverterAdapter

Currently, "ReactiveJwtAuthenticationConverterAdapter" takes
"JwtAuthenticationConverter" as its constructor argument. However,
this limits the usage of this adapter.
In this commit, widen the constructor to take "Converter<Jwt,
AbstractAuthenticationToken>" and allow this adapter to be used by
generic converters.
This commit is contained in:
Tadaya Tsuyukubo 2019-06-08 00:12:55 -07:00 committed by Josh Cummings
parent 1739ef8d3c
commit 3cb0975860
2 changed files with 4 additions and 3 deletions

View File

@ -30,9 +30,9 @@ import org.springframework.util.Assert;
* @since 5.1.1 * @since 5.1.1
*/ */
public class ReactiveJwtAuthenticationConverterAdapter implements Converter<Jwt, Mono<AbstractAuthenticationToken>> { public class ReactiveJwtAuthenticationConverterAdapter implements Converter<Jwt, Mono<AbstractAuthenticationToken>> {
private final JwtAuthenticationConverter delegate; private final Converter<Jwt, AbstractAuthenticationToken> delegate;
public ReactiveJwtAuthenticationConverterAdapter(JwtAuthenticationConverter delegate) { public ReactiveJwtAuthenticationConverterAdapter(Converter<Jwt, AbstractAuthenticationToken> delegate) {
Assert.notNull(delegate, "delegate cannot be null"); Assert.notNull(delegate, "delegate cannot be null");
this.delegate = delegate; this.delegate = delegate;
} }

View File

@ -25,6 +25,7 @@ import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.convert.converter.Converter;
import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority;
@ -39,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Josh Cummings * @author Josh Cummings
*/ */
public class ReactiveJwtAuthenticationConverterAdapterTests { public class ReactiveJwtAuthenticationConverterAdapterTests {
JwtAuthenticationConverter converter = new JwtAuthenticationConverter(); Converter<Jwt, AbstractAuthenticationToken> converter = new JwtAuthenticationConverter();
ReactiveJwtAuthenticationConverterAdapter jwtAuthenticationConverter = ReactiveJwtAuthenticationConverterAdapter jwtAuthenticationConverter =
new ReactiveJwtAuthenticationConverterAdapter(converter); new ReactiveJwtAuthenticationConverterAdapter(converter);