Spring Security 不处理前/后注释 [英] Spring Security not processing pre/post annotations

查看:29
本文介绍了Spring Security 不处理前/后注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to get pre/post annotations working with a web application, but for some reason nothing is happening with spring-security.

web.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:

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
@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");
    }
}

推荐答案

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

To enable secuity annotations on the controllers you should declare <security:global-method-security .../> in the context where controllers are declared, that is in rva-servlet.xml.

这篇关于Spring Security 不处理前/后注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆