我正在使用Spring Boot和Spring安全性来构建rest
应用程序。在登录模块中,我希望我的代码从Post正文读取客户端发送的用户名和密码。但是我的代码仅从网址中读取,例如Get
请求。
我试图向邮递员发出请求。将方法设置为Post
。当我在请求参数字段中设置用户名和密码时。我得到了“ 200 ok”,但是当我在Post请求中将参数作为json发送时,我得到了401 unauthorized
。我需要进行哪些配置更改?
我的Spring安全配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.
authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/login").permitAll()
.antMatchers("/registration").permitAll()
.antMatchers("/admin/**").hasAuthority("Admin")
.antMatchers("/db").hasAuthority("DBA")
.antMatchers("/user").hasAuthority("USER").anyRequest()
.authenticated().and().csrf().disable().formLogin()
.loginPage("/login")
.failureHandler(customFailureHandler)
.successHandler(customSuccessHandler)
.usernameParameter("username")
.passwordParameter("password")
.and().logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/").and().exceptionHandling().authenticationEntryPoint(authenticationEntryPoint)
.accessDeniedPage("/access-denied");
}