私は、異なるURLパターンに対して2つの異なるセキュリティ設定を定義しようとしています。その1つはフォームログインを使用し、もう1つは基本認証を使用します。Springセキュリティによる基本認証とフォームベースの認証Javaconfig
私が探している解決策は、http://meera-subbarao.blogspot.co.uk/2010/11/spring-security-combining-basic-and.htmlで説明したものと似ていますが、私はjavaの設定を使ってやりたいと思います。
ありがとうございます。
これは私が現在持っている設定です。
@Configuration
@EnableWebSecurity
public class AppSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserService userService;
@Override
protected void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userService);
}
@Override
public void configure(WebSecurity web) throws Exception {
// Ignore any request that starts with "/resources/".
web.ignoring().antMatchers("/resources/**");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeUrls().antMatchers("/", "/index", "/user/**", "/about").permitAll()
.antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and().formLogin()
.loginUrl("/login")
.failureUrl("/login-error")
.loginProcessingUrl("/security_check")
.usernameParameter("j_username").passwordParameter("j_password")
.permitAll();
http.logout().logoutUrl("/logout");
http.rememberMe().rememberMeServices(rememberMeServices()).key("password");
}
@Bean
public RememberMeServices rememberMeServices() {
TokenBasedRememberMeServices rememberMeServices = new TokenBasedRememberMeServices("password", userService);
rememberMeServices.setCookieName("cookieName");
rememberMeServices.setParameter("rememberMe");
return rememberMeServices;
}
}
どのような結果が表示されますか? – Taylor
現在、私はちょうどこのフォーム認証を持っており、/ api/*のようなURLパターンに基本認証を追加する方法を見つけることができません –