gpt4 book ai didi

spring-security - Spring 安全 : Getting error "The server understood the request but refuses to authorize it"

转载 作者:行者123 更新时间:2023-12-03 14:57:03 27 4
gpt4 key购买 nike

使用 Spring Security 运行应用程序时,我在所有浏览器上都遇到以下错误:

"The server understood the request but refuses to authorize it"



我尝试在“spring-security.xml”文件中将角色从“ROLE_ADMIN”更改为“ROLE_USER”。

下面是“spring-security.xml”
<http auto-config="true">
<intercept-url pattern ="/admin" access = "hasRole('ROLE-USER')"/>
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name = "abc" password = "xyz" authorities="hasRole('ROLE-USER')" />
</user-service>
</authentication-provider>
</authentication-manager>

下面是 SpringController 类:
@Controller
public class SpringController {



@RequestMapping(value = "/")
public String homePage() {
return "HomePage";
}
@RequestMapping(value="/admin", method=RequestMethod.GET)
public String loginPage() {
return "login";
}

HomePage.jsp 和 login.jsp 页面已加载属性,但在 login.jsp 上传递凭据后出现错误:

HTTP Status 403 – Forbidden


Type: Status Report

Message: Access is denied

Description: The server understood the request but refuses to authorize it.


Apache Tomcat/7.0.90

最佳答案

403 是一个非常通用的错误代码。我遇到了同样的问题,但在进行了一些更改后,我能够使其正常工作。仍然不确定问题是密码加密还是表单登录标签的配置。

<security:http auto-config="true"  >
<security:intercept-url pattern="/login*" access="isAnonymous()" />
<security:intercept-url pattern="/**" access="isAuthenticated()"/>
<security:form-login login-page="/login" login-processing-url="/login-user" authentication-failure-url="/login?error=true" />
<security:csrf disabled="true" />
<security:logout logout-success-url="/" />
</security:http>

<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="admin" password="{noop}admin" authorities="ROLE_USER" />
</security:user-service>
</security:authentication-provider >

</security:authentication-manager>

忽略标签中的 security: 前缀。

密码前面的 {noop} 确保我没有对密码使用任何加密。

Controller 显示登录 JSP
@Controller
@RequestMapping("/login")
public class LoginController {

@RequestMapping(value = { "/", "" }, method = { RequestMethod.GET})
public String login(HttpServletRequest request) {
System.out.println("LoginController.login() "+request.getRequestURI());
return "login";
}

}

表单操作
<form name='loginForm' action="login-user" method='POST'>

关于spring-security - Spring 安全 : Getting error "The server understood the request but refuses to authorize it",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51351675/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com