Spring 启动社交禁用 ConnectController
Spring Boot Social disable ConnectController
我正在使用 Spring Boot Social 通过 SpringSocialConfigurer
进行 OAuth 身份验证,并且所有与第 3 方 OAuth 提供商的 OAuth 身份验证都通过 /auth/providerId
路径。
一切正常,但我注意到 ConnectController
也在我的应用程序中显示和配置:
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.connect(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[error],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2ErrorCallback(java.lang.String,java.lang.String,java.lang.String,java.lang.String,org.springframework.web.context.request.NativeWebRequest)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnections(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(java.lang.String,org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[oauth_token],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth1Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[code],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}/{providerUserId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnection(java.lang.String,java.lang.String,org.springframework.web.context.request.NativeWebRequest)
我觉得我不需要ConnectController
。有什么方法可以禁用它吗?
更新:
这是我当前的 SocialConfig
@Configuration
@EnableSocial
public class SocialConfig extends SocialConfigurerAdapter {
@Autowired
private UserService userService;
@Autowired
private SocialUserService socialUserService;
@Autowired
private TextEncryptor textEncryptor;
@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
Neo4jUsersConnectionRepository connectionRepository = new Neo4jUsersConnectionRepository(userService, socialUserService,
(SocialAuthenticationServiceLocator) connectionFactoryLocator, textEncryptor);
connectionRepository.setConnectionSignUp(new UserConnectionSignUp(userService));
return connectionRepository;
}
@Bean
public SocialUserDetailsService socialUserDetailsService() {
return new DBSocialUserDetailService(userService);
}
}
正在添加
@SpringBootApplication(exclude = SocialWebAutoConfiguration.class)
给我解决了。
更新
我需要创建以下 class 才能正常工作。
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.social.UserIdSource;
import org.springframework.social.config.annotation.ConnectionFactoryConfigurer;
import org.springframework.social.config.annotation.EnableSocial;
import org.springframework.social.config.annotation.SocialConfigurer;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository;
import javax.inject.Inject;
import javax.sql.DataSource;
@Configuration
@EnableSocial
public class MySocialConfig implements SocialConfigurer {
@Inject
private DataSource dataSource;
//
// SocialConfigurer implementation methods
//
@Override
public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
}
@Override
public UserIdSource getUserIdSource() {
return new UserIdSource() {
@Override
public String getUserId() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
throw new IllegalStateException("Unable to get a ConnectionRepository: no user signed in");
}
return authentication.getName();
}
};
}
@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
return new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator, Encryptors.noOpText());
}
}
我正在使用 Spring Boot Social 通过 SpringSocialConfigurer
进行 OAuth 身份验证,并且所有与第 3 方 OAuth 提供商的 OAuth 身份验证都通过 /auth/providerId
路径。
一切正常,但我注意到 ConnectController
也在我的应用程序中显示和配置:
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.connect(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[error],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2ErrorCallback(java.lang.String,java.lang.String,java.lang.String,java.lang.String,org.springframework.web.context.request.NativeWebRequest)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnections(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(java.lang.String,org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[oauth_token],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth1Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[code],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
2015-05-02 12:02:47 [main] INFO o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}/{providerUserId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnection(java.lang.String,java.lang.String,org.springframework.web.context.request.NativeWebRequest)
我觉得我不需要ConnectController
。有什么方法可以禁用它吗?
更新:
这是我当前的 SocialConfig
@Configuration
@EnableSocial
public class SocialConfig extends SocialConfigurerAdapter {
@Autowired
private UserService userService;
@Autowired
private SocialUserService socialUserService;
@Autowired
private TextEncryptor textEncryptor;
@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
Neo4jUsersConnectionRepository connectionRepository = new Neo4jUsersConnectionRepository(userService, socialUserService,
(SocialAuthenticationServiceLocator) connectionFactoryLocator, textEncryptor);
connectionRepository.setConnectionSignUp(new UserConnectionSignUp(userService));
return connectionRepository;
}
@Bean
public SocialUserDetailsService socialUserDetailsService() {
return new DBSocialUserDetailService(userService);
}
}
正在添加
@SpringBootApplication(exclude = SocialWebAutoConfiguration.class)
给我解决了。
更新
我需要创建以下 class 才能正常工作。
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.social.UserIdSource;
import org.springframework.social.config.annotation.ConnectionFactoryConfigurer;
import org.springframework.social.config.annotation.EnableSocial;
import org.springframework.social.config.annotation.SocialConfigurer;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository;
import javax.inject.Inject;
import javax.sql.DataSource;
@Configuration
@EnableSocial
public class MySocialConfig implements SocialConfigurer {
@Inject
private DataSource dataSource;
//
// SocialConfigurer implementation methods
//
@Override
public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
}
@Override
public UserIdSource getUserIdSource() {
return new UserIdSource() {
@Override
public String getUserId() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
throw new IllegalStateException("Unable to get a ConnectionRepository: no user signed in");
}
return authentication.getName();
}
};
}
@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
return new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator, Encryptors.noOpText());
}
}