Skip to content

Commit

Permalink
✨ 提供了 OAuth2AuthorizationObjectMapperCustomizer 类,方便用户扩展 OAuth2Author…
Browse files Browse the repository at this point in the history
…ization 的序列化逻辑
  • Loading branch information
Hccake committed Apr 24, 2023
1 parent 556f843 commit 395aff0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.ballcat.springsecurity.oauth2.server.authorization;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
* 用于序列化 OAuth2Authorization 的专用 ObjectMapper 定制器
*
* @author hccake
*/
@FunctionalInterface
public interface OAuth2AuthorizationObjectMapperCustomizer {

void customize(ObjectMapper objectMapper);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import com.hccake.ballcat.common.security.userdetails.User;
import com.hccake.ballcat.common.security.util.PasswordUtils;
import lombok.RequiredArgsConstructor;
import org.ballcat.springsecurity.oauth2.server.authorization.OAuth2AuthorizationObjectMapperCustomizer;
import org.ballcat.springsecurity.oauth2.server.authorization.config.OAuth2AuthorizationServerConfigurerAdapter;
import org.ballcat.springsecurity.oauth2.server.authorization.config.customizer.OAuth2AuthorizationServerConfigurerCustomizer;
import org.ballcat.springsecurity.oauth2.server.authorization.config.configurer.OAuth2AuthorizationServerExtensionConfigurer;
import org.ballcat.springsecurity.oauth2.server.authorization.properties.OAuth2AuthorizationServerProperties;
import org.ballcat.springsecurity.oauth2.server.authorization.token.BallcatOAuth2TokenCustomizer;
import org.ballcat.springsecurity.oauth2.server.authorization.web.authentication.OAuth2TokenRevocationResponseHandler;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationEventPublisher;
Expand Down Expand Up @@ -81,7 +83,8 @@ public RegisteredClientRepository registeredClientRepository(JdbcTemplate jdbcTe
@Bean
@ConditionalOnMissingBean
public OAuth2AuthorizationService authorizationService(JdbcTemplate jdbcTemplate,
RegisteredClientRepository registeredClientRepository) {
RegisteredClientRepository registeredClientRepository,
ObjectProvider<OAuth2AuthorizationObjectMapperCustomizer> objectMapperCustomizerObjectProvider) {
JdbcOAuth2AuthorizationService oAuth2AuthorizationService = new JdbcOAuth2AuthorizationService(jdbcTemplate,
registeredClientRepository);

Expand All @@ -99,6 +102,10 @@ public OAuth2AuthorizationService authorizationService(JdbcTemplate jdbcTemplate

// You will need to write the Mixin for your class so Jackson can marshall it.
objectMapper.addMixIn(User.class, UserMixin.class);

// 定制 objectMapper
objectMapperCustomizerObjectProvider.ifAvailable(customizer -> customizer.customize(objectMapper));

rowMapper.setObjectMapper(objectMapper);

oAuth2AuthorizationService.setAuthorizationRowMapper(rowMapper);
Expand Down

0 comments on commit 395aff0

Please sign in to comment.