春季安全访问被拒绝 403 后发布
2022-09-03 00:11:13
我已经尝试了其他帖子中的几乎所有内容,与我的问题无关。
如果我尝试通过GET恢复我的URL(例如:path/users/edit/1),一切正常,我被重定向到用户编辑页面,但是如果我尝试通过POST访问此页面,弹簧安全性会拒绝我访问该页面。
这两种方法都映射在我的控制器类中。
@RequestMapping(value="/users/edit/{id}", method={RequestMethod.POST,RequestMethod.GET})
public ModelAndView login(ModelAndView model, @PathVariable("id") int id ) {
model.addObject("user", this.userService.getUserById(id));
model.setViewName("/users/add"); //add.jsp
return model;
}
我使用的表单发布
<f:form method="post" action="/users/edit/${user.id}">
<button type="submit">Edit</button>
</f:form>
弹簧安全.xml
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<!-- enable use-expressions -->
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/secure**" access="hasAnyRole('ROLE_USER','ROLE_ADMIN')" />
<intercept-url pattern="/secure/users**" access="hasAnyRole('ROLE_USER','ROLE_ADMIN')" />
<!-- access denied page -->
<access-denied-handler error-page="/denied" />
<form-login
login-page="/home"
default-target-url="/secure"
authentication-failure-url="/home?error"
username-parameter="inputEmail"
password-parameter="inputPassword" />
<logout logout-success-url="/home?logout" />
<!-- enable csrf protection -->
<csrf/>
</http>
<!-- Select users and user_roles from database -->
<authentication-manager>
<authentication-provider>
<password-encoder hash="md5" />
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query=
"SELECT login, senha, ativo
FROM usuarios
WHERE login = ?"
authorities-by-username-query=
"SELECT u.login, r.role
FROM usuarios_roles r, usuarios u
WHERE u.id = r.usuario_id
AND u.login = ?" />
</authentication-provider>
</authentication-manager>