⒈java
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 }
⒉spring
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方法上添加過濾器鏈sql