【发布时间】:2018-02-13 06:19:16
【问题描述】:
我尝试基于 Spring security 配置进行 Java 注释。我在遵循教程并提供了代码后执行此操作,
@Configuration
@EnableWebSecurity
// need to change this to the security directory
@ComponentScan("")
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private RestAuthenticationEntryPoint restAuthenticationEntryPoint;
@Autowired
private MySavedRequestAwareAuthenticationSuccessHandler authenticationSuccessHandler;
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.inMemoryAuthentication()
.withUser("temporary").password("temporary").roles("ADMIN")
.and()
.withUser("user").password("userPass").roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.exceptionHandling()
.authenticationEntryPoint(restAuthenticationEntryPoint)
.and()
.authorizeRequests()
.antMatchers("/api/foos").authenticated()
.and()
.formLogin()
.successHandler(authenticationSuccessHandler)
.failureHandler(new SimpleUrlAuthenticationFailureHandler())
.and()
.logout();
}
@Bean
public MySavedRequestAwareAuthenticationSuccessHandler mySuccessHandler() {
return new MySavedRequestAwareAuthenticationSuccessHandler();
}
@Bean
public SimpleUrlAuthenticationFailureHandler myFailureHandler() {
return new SimpleUrlAuthenticationFailureHandler();
}
}
我工作的项目的API 基地,
public static final String API_BASE = "/*";
例如,我执行cURL 之类的请求,
curl -X GET http://localhost:8080/rest/wallet/wallets | json
我不确定代码中的 .antMatchers("/api/foos").authenticated() 行。例如,foos 来自哪里,我是否需要将其更改为 .antMatchers("/foos").authenticated()?
【问题讨论】:
标签: java spring spring-mvc spring-security