【发布时间】:2016-02-01 16:31:27
【问题描述】:
我尝试使用 angular $http 和 spring WebSecurityConfigurerAdapter 从网站进行授权,这是我的代码:
Java部分:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private static final Logger LOGGER = Logger.getLogger(SecurityConfig.class);
@Autowired
private UserDetailsService customUserDetailsService;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// auth.inMemoryAuthentication().withUser("user").password("12345").roles("USER");
auth.userDetailsService(customUserDetailsService);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
CsrfTokenResponseHeaderBindingFilter bindingFilter = new CsrfTokenResponseHeaderBindingFilter();
http.addFilterAfter(bindingFilter, CsrfFilter.class);
http.authorizeRequests().antMatchers("/", "/home").permitAll()
.anyRequest().authenticated().and().formLogin().defaultSuccessUrl("/")
.loginProcessingUrl("/authenticate").usernameParameter("username").passwordParameter("password")
.successHandler(new AjaxAuthenticationSuccessHandler(new SavedRequestAwareAuthenticationSuccessHandler()))
.loginPage("/login/existinguser").and().httpBasic().and().logout().logoutUrl("/logout")
.logoutSuccessUrl("/login/existinguser").permitAll();
if ("true".equals(System.getProperty("httpsOnly"))) {
LOGGER.info("launching the application in HTTPS-only mode");
http.requiresChannel().anyRequest().requiresSecure();
}
}
}
JS部分:
$scope.login = function (username, password) {
var postData = 'username='+username+'&password='+password;
$http({
method: 'POST',
url: '/authenticate',
data: postData,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"X-Login-Ajax-call": 'true'
}
})
.then(function(response) {
if (response.data == 'ok') {
debugger;
window.location.replace('/');
}
else {
debugger;
}
});
};
问题是我收到错误:
POST http://localhost:8080/authenticate 404 (Not Found)
有人可以说我需要做什么才能让它发挥作用吗?
【问题讨论】:
-
我做了tomcat配置,不需要名字。是的,我有这方面的控制器,只是不确定这是因为映射。感觉就像
/authenticate没有映射。 -
是的,我有控制器
标签: java angularjs spring spring-security