Java 发布到登录处理url时Get 405方法不允许(Spring安全)
我尝试使用Postman测试Spring安全配置中的登录处理url集:Java 发布到登录处理url时Get 405方法不允许(Spring安全),java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,我尝试使用Postman测试Spring安全配置中的登录处理url集: @Override public void configure(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers("/", "/list") .access("hasRole('USER') or hasRole('ADMIN') or hasRole('DBA')")
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/", "/list")
.access("hasRole('USER') or hasRole('ADMIN') or hasRole('DBA')")
.antMatchers("/newuser/**", "/delete-user-*")
.access("hasRole('ADMIN')")
.antMatchers("/edit-user-*")
.access("hasRole('ADMIN') or hasRole('DBA')")
.and()
.formLogin()
.loginProcessingUrl("/login-processing")
.usernameParameter("ssoId")
.passwordParameter("password")
.and()
.rememberMe()
.rememberMeParameter("remember-me")
.tokenRepository(persistentTokenRepository)
.tokenValiditySeconds(86400)
.and()
.csrf()
.and()
.exceptionHandling()
.accessDeniedPage("/Access_Denied");
}
当我访问default/login
时,我得到以下信息:
<html>
<head>
<title>Login Page</title>
</head>
<body onload='document.f.ssoId.focus();'>
<h3>Login with Username and Password</h3>
<form name='f' action='/login-processing' method='POST'>
<table>
<tr>
<td>User:</td>
<td>
<input type='text' name='ssoId' value=''>
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<input type='password' name='password'/>
</td>
</tr>
<tr>
<td>
<input type='checkbox' name='remember-me'/>
</td>
<td>Remember me on this computer.</td>
</tr>
<tr>
<td colspan='2'>
<input name="submit" type="submit" value="Login"/>
</td>
</tr>
<input name="_csrf" type="hidden" value="26d11d4c-1477-41e7-9639-abe2f4ca114e" />
</table>
</form>
</body>
</html>
{
"timestamp": 1498962411086,
"status": 405,
"error": "Method Not Allowed",
"exception": "org.springframework.web.HttpRequestMethodNotSupportedException",
"message": "Request method 'POST' not supported",
"path": "/login-processing"
}
为什么
/login processing
可以从/login
访问,但邮差无法访问?请将contextPath添加到表单操作:${contextPath}/login processing
,您可以使用JSTL请将contextPath添加到表单操作:${contextPath}/登录处理
,您可以使用JSTL