我正在調查很長一個問題,我有我的網絡應用程序管理員註冊和登錄使用傳統方法與用戶名和密碼和常規用戶註冊並使用他們的Facebook帳戶登錄。春季安全和春季社交在不同的登錄頁面
這兩個登錄表單位於不同的頁面;不過,我希望這兩個基於同一個應用程序的Spring Security。
我有一個與此相關的幾個問題:
1)我想,而另一個在不同的頁面設置用戶登錄社交形式的着陸頁。爲了做到這一點,我如下配置了HttpRequest,但着陸頁未啓動。
2)我應該配置兩個HttpSecurity,一個用於傳統登錄,一個用於社交登錄? (當前配置不起作用)
3)我想定義兩個權限,一個用於管理員ROLE_ADMIN,另一個用於常規用戶ROLE_USER。我如何爲使用他們的soaicl賬戶登錄的用戶定義一個ROLE?
這裏是我的HttpSecurity配置
@Configuration
@EnableWebSecurity
public class SecurityConfig{
@Autowired
private ApplicationContext context;
@Autowired
private DataSource dataSource;
@Autowired
public void registerAuthentication(AuthenticationManagerBuilder auth)
throws Exception {
auth.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery(
"select username, password, enabled from Account where username = ?")
.authoritiesByUsernameQuery(
"select username, authority from Account where username = ?")
.passwordEncoder(passwordEncoder());
}
@Bean
public UserIdSource userIdSource() {
return new AuthenticationNameUserIdSource();
}
@Bean
public PasswordEncoder passwordEncoder() {
return NoOpPasswordEncoder.getInstance();
}
@Bean
public TextEncryptor textEncryptor() {
return Encryptors.noOpText();
}
@Configuration
@Order(2)
public static class BizSecurityConfigurationAdapter extends
WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginPage("/admin")
.loginProcessingUrl("/admin/authenticate")
.failureUrl("/admin?param.error=bad_credentials")
.defaultSuccessUrl("/admin/home")
.and()
.authorizeRequests()
.antMatchers("/","/admin", "/resources/**",
"/auth/**", "/signin/**", "/signup/**", "/disconnect/**").permitAll()
.antMatchers("/**").authenticated()
.antMatchers("/**").hasRole("ADMIN")
.and()
.rememberMe();
}
@Bean
public SocialUserDetailsService socialUsersDetailService() {
return new SimpleSocialUsersDetailService(userDetailsService());
}
}
@Configuration
@Order(1)
public static class UserSecurityConfigurerAdapter extends
WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin()
.loginPage("/")
.loginProcessingUrl("/authenticate")
.failureUrl("/?param.error=bad_credentials")
.defaultSuccessUrl("/user/profile")
.permitAll()
.and()
.logout()
.logoutUrl("/")
.deleteCookies("JSESSIONID")
.and()
.authorizeRequests()
.antMatchers("/", "/user","/admin","/login", "/admin/**",
"/resources/**", "/auth/**", "/signin/**",
"/signup/**", "/disconnect/**").permitAll()
.antMatchers("/user/**").hasRole("USER").and().rememberMe()
.and().apply(new SpringSocialConfigurer());
}
@Bean
public SocialUserDetailsService socialUsersDetailService() {
return new SimpleSocialUsersDetailService(userDetailsService());
}
}
}
感謝您的回答。我讀到了另一種通過使用過濾器SpringSocialConfigurer實現此方法的方法。如何在這種情況下設置角色,或者我不需要它? –