gpt4 book ai didi

spring-security - Spring Security 不处理前/后注释

转载 作者:行者123 更新时间:2023-12-04 07:15:05 25 4
gpt4 key购买 nike

我正在尝试让前/后注释与 Web 应用程序一起使用,但由于某种原因,spring-security 没有发生任何事情。

网页.xml:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/rvaContext-business.xml
/WEB-INF/rvaContext-security.xml
</param-value>
</context-param>

<!-- Spring security filter -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>rva</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>rva</servlet-name>
<url-pattern>/rva/*</url-pattern>
</servlet-mapping>

rvaContext-security.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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.0.xsd">

<global-method-security pre-post-annotations="enabled"/>

<http use-expressions="true">
<form-login login-page="/login" />
<logout />
<remember-me />
</http>
...

登录 Controller 类:
@Controller
@RequestMapping("/login")
public class LoginController {

@RequestMapping(method = RequestMethod.GET)
public String login(ModelMap map){
map.addAttribute("title", "Login: AD Credentials");
return("login");
}

@RequestMapping("/secure")
@PreAuthorize("hasRole('ROLE_USER')")
public String secure(ModelMap map){
return("secure");
}
}

最佳答案

要在 Controller 上启用安全注释,您应该声明 <security:global-method-security .../>在声明 Controller 的上下文中,即 rva-servlet.xml .

关于spring-security - Spring Security 不处理前/后注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2524962/

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