我尝试使用角度$http
春季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'没有映射。 – Edgar
是的,我有控制器 – Edgar