use of org.springframework.security.oauth2.server.authorization.OAuth2TokenCustomizer in project spring-authorization-server by spring-projects.
the class OAuth2ConfigurerUtils method getTokenGenerator.
@SuppressWarnings("unchecked")
static <B extends HttpSecurityBuilder<B>> OAuth2TokenGenerator<? extends OAuth2Token> getTokenGenerator(B builder) {
OAuth2TokenGenerator<? extends OAuth2Token> tokenGenerator = builder.getSharedObject(OAuth2TokenGenerator.class);
if (tokenGenerator == null) {
tokenGenerator = getOptionalBean(builder, OAuth2TokenGenerator.class);
if (tokenGenerator == null) {
JwtGenerator jwtGenerator = getJwtGenerator(builder);
OAuth2AccessTokenGenerator accessTokenGenerator = new OAuth2AccessTokenGenerator();
OAuth2TokenCustomizer<OAuth2TokenClaimsContext> accessTokenCustomizer = getAccessTokenCustomizer(builder);
if (accessTokenCustomizer != null) {
accessTokenGenerator.setAccessTokenCustomizer(accessTokenCustomizer);
}
OAuth2RefreshTokenGenerator refreshTokenGenerator = new OAuth2RefreshTokenGenerator();
if (jwtGenerator != null) {
tokenGenerator = new DelegatingOAuth2TokenGenerator(jwtGenerator, accessTokenGenerator, refreshTokenGenerator);
} else {
tokenGenerator = new DelegatingOAuth2TokenGenerator(accessTokenGenerator, refreshTokenGenerator);
}
}
builder.setSharedObject(OAuth2TokenGenerator.class, tokenGenerator);
}
return tokenGenerator;
}
use of org.springframework.security.oauth2.server.authorization.OAuth2TokenCustomizer in project best-cloud by shanzhaozhen.
the class AuthorizationServerConfig method addCustomOAuth2ResourceOwnerPasswordAuthenticationProvider.
/**
* 基于默认授权服务器设置中追加 password 模式
* @param http
*/
private void addCustomOAuth2ResourceOwnerPasswordAuthenticationProvider(HttpSecurity http) {
AuthenticationManager authenticationManager = http.getSharedObject(AuthenticationManager.class);
// 弃用JwtEncoder和关联的类以准备在0.3.0发布中删除(请参阅gh-594)。
// 该0.3.0版本将使用Spring Security 5.6JwtEncoder中引入的。
JwtEncoder jwtEncoder = OAuth2ConfigurerUtils.getJwtEncoder(http);
OAuth2TokenCustomizer<JwtEncodingContext> jwtCustomizer = OAuth2ConfigurerUtils.getJwtCustomizer(http);
OAuth2ResourceOwnerPasswordAuthenticationProvider resourceOwnerPasswordAuthenticationProvider = new OAuth2ResourceOwnerPasswordAuthenticationProvider(authenticationManager, OAuth2ConfigurerUtils.getAuthorizationService(http), jwtEncoder);
if (jwtCustomizer != null) {
resourceOwnerPasswordAuthenticationProvider.setJwtCustomizer(jwtCustomizer);
}
http.authenticationProvider(resourceOwnerPasswordAuthenticationProvider);
}
use of org.springframework.security.oauth2.server.authorization.OAuth2TokenCustomizer in project spring-authorization-server by spring-projects.
the class OAuth2ConfigurerUtils method getJwtGenerator.
private static <B extends HttpSecurityBuilder<B>> JwtGenerator getJwtGenerator(B builder) {
JwtGenerator jwtGenerator = builder.getSharedObject(JwtGenerator.class);
if (jwtGenerator == null) {
JwtEncoder jwtEncoder = getJwtEncoder(builder);
if (jwtEncoder != null) {
jwtGenerator = new JwtGenerator(jwtEncoder);
OAuth2TokenCustomizer<JwtEncodingContext> jwtCustomizer = getJwtCustomizer(builder);
if (jwtCustomizer != null) {
jwtGenerator.setJwtCustomizer(jwtCustomizer);
}
builder.setSharedObject(JwtGenerator.class, jwtGenerator);
}
}
return jwtGenerator;
}
Aggregations