|
@@ -17,30 +17,50 @@ package org.springframework.security.oauth2.jwt;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
-import java.util.Collection;
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
import org.springframework.security.oauth2.core.DelegatingOAuth2TokenValidator;
|
|
import org.springframework.security.oauth2.core.DelegatingOAuth2TokenValidator;
|
|
import org.springframework.security.oauth2.core.OAuth2TokenValidator;
|
|
import org.springframework.security.oauth2.core.OAuth2TokenValidator;
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * Provides factory methods for creating {@code OAuth2TokenValidator<Jwt>}
|
|
* @author Josh Cummings
|
|
* @author Josh Cummings
|
|
|
|
+ * @author Rob Winch
|
|
* @since 5.1
|
|
* @since 5.1
|
|
*/
|
|
*/
|
|
public final class JwtValidators {
|
|
public final class JwtValidators {
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Create a {@link Jwt} Validator that contains all standard validators as well as
|
|
|
|
- * any supplied in the parameter list.
|
|
|
|
- *
|
|
|
|
- * @param jwtValidators - additional validators to include in the delegating validator
|
|
|
|
|
|
+ * <p>
|
|
|
|
+ * Create a {@link Jwt} Validator that contains all standard validators when an issuer is known.
|
|
|
|
+ * </p>
|
|
|
|
+ * <p>
|
|
|
|
+ * User's wanting to leverage the defaults plus additional validation can add the result of this
|
|
|
|
+ * method to {@code DelegatingOAuth2TokenValidator} along with the additional validators.
|
|
|
|
+ * </p>
|
|
|
|
+ * @param issuer the issuer
|
|
* @return - a delegating validator containing all standard validators as well as any supplied
|
|
* @return - a delegating validator containing all standard validators as well as any supplied
|
|
*/
|
|
*/
|
|
- public static OAuth2TokenValidator<Jwt> createDelegatingJwtValidator(OAuth2TokenValidator<Jwt>... jwtValidators) {
|
|
|
|
- Collection<OAuth2TokenValidator<Jwt>> validators = new ArrayList<>();
|
|
|
|
|
|
+ public static OAuth2TokenValidator<Jwt> createDefaultWithIssuer(String issuer) {
|
|
|
|
+ List<OAuth2TokenValidator<Jwt>> validators = new ArrayList<>();
|
|
validators.add(new JwtTimestampValidator());
|
|
validators.add(new JwtTimestampValidator());
|
|
- validators.addAll(Arrays.asList(jwtValidators));
|
|
|
|
|
|
+ validators.add(new JwtIssuerValidator(issuer));
|
|
return new DelegatingOAuth2TokenValidator<>(validators);
|
|
return new DelegatingOAuth2TokenValidator<>(validators);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * <p>
|
|
|
|
+ * Create a {@link Jwt} Validator that contains all standard validators.
|
|
|
|
+ * </p>
|
|
|
|
+ * <p>
|
|
|
|
+ * User's wanting to leverage the defaults plus additional validation can add the result of this
|
|
|
|
+ * method to {@code DelegatingOAuth2TokenValidator} along with the additional validators.
|
|
|
|
+ * </p>
|
|
|
|
+ * @return - a delegating validator containing all standard validators as well as any supplied
|
|
|
|
+ */
|
|
|
|
+ public static OAuth2TokenValidator<Jwt> createDefault() {
|
|
|
|
+ return new DelegatingOAuth2TokenValidator<>(Arrays.asList(new JwtTimestampValidator()));
|
|
|
|
+ }
|
|
|
|
+
|
|
private JwtValidators() {}
|
|
private JwtValidators() {}
|
|
}
|
|
}
|