修改Spring Social默认提交地址

 1 package cn.coreqi.social.config;
 2 
 3 import org.springframework.social.security.SocialAuthenticationFilter;
 4 import org.springframework.social.security.SpringSocialConfigurer;
 5 
 6 public class CoreqiSpringSocialConfig extends SpringSocialConfigurer {
 7 
 8     @Override
 9     protected <T> T postProcess(T object) {
10         SocialAuthenticationFilter filter = (SocialAuthenticationFilter)super.postProcess(object);
11         filter.setFilterProcessesUrl("/coreqi/auth");
12         return (T) filter;
13     }
14 }

 1 package cn.coreqi.social.config;
 2 
 3 import org.springframework.beans.factory.annotation.Autowired;
 4 import org.springframework.context.annotation.Bean;
 5 import org.springframework.context.annotation.Configuration;
 6 import org.springframework.security.crypto.encrypt.Encryptors;
 7 import org.springframework.social.config.annotation.EnableSocial;
 8 import org.springframework.social.config.annotation.SocialConfigurerAdapter;
 9 import org.springframework.social.connect.ConnectionFactoryLocator;
10 import org.springframework.social.connect.UsersConnectionRepository;
11 import org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository;
12 import org.springframework.social.security.SpringSocialConfigurer;
13 
14 import javax.sql.DataSource;
15 
16 @Configuration
17 @EnableSocial
18 public class SocialConfig extends SocialConfigurerAdapter {
19 
20     @Autowired
21     private DataSource dataSource;
22 
23     /**
24      *
25      * @param connectionFactoryLocator  作用是去根据条件去查找应该用那个connectionFactory,因为系统中可能有很多的connectionFactory。
26      * @return
27      */
28     @Override
29     public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
30         //第三个参数的作用是把插入到数据库的数据进行加解密
31         JdbcUsersConnectionRepository jdbcUsersConnectionRepository = new JdbcUsersConnectionRepository(dataSource,connectionFactoryLocator, Encryptors.noOpText());
32         //jdbcUsersConnectionRepository.setTablePrefix(); //设置数据表的前缀
33         return jdbcUsersConnectionRepository;
34     }
35 
36     /**
37      * 声明后还需要加在SpringSecurity过滤器链上
38      * @return
39      */
40     @Bean
41     public SpringSocialConfigurer coreqiSocialSecurityConfig(){
42         return new CoreqiSpringSocialConfig();
43     }
44 }

⒊在SpringSecurity Config方法上添加过滤器链

posted @ 2019-04-01 22:48  SpringCore  阅读(531)  评论(0编辑  收藏  举报