Gwt Spring安全方法授权不工作

Gwt Spring安全方法授权不工作,gwt,spring-security,Gwt,Spring Security,下面是问题的描述。我正在用GWT开发一个web应用程序。我已经成功地将spring security与gwt集成在一起,使用以下代码实现身份验证功能。现在我想在我的web应用程序中使用spring的“方法安全性”。所以我照上面说的做了 只需在上述应用程序上下文文件中添加 <http> <http-basic/> <intercept-url pattern="/**" access=""/> <form-login /> &

下面是问题的描述。我正在用GWT开发一个web应用程序。我已经成功地将spring security与gwt集成在一起,使用以下代码实现身份验证功能。现在我想在我的web应用程序中使用spring的“方法安全性”。所以我照上面说的做了

  • 只需在上述应用程序上下文文件中添加

     <http>
      <http-basic/>
    
      <intercept-url pattern="/**" access=""/>
    
      <form-login />
      <logout />
     </http> 
    
      <authentication-manager>
        <authentication-provider>
          <user-service>
            <user name="jimis" password="jimispassword" authorities="ROLE_USER,ROLE_ADMIN" />
            <user name="bob" password="bobspassword" authorities="ROLE_ADMIN" />
          </user-service>
        </authentication-provider>
      </authentication-manager>
    
      **<global-method-security secured-annotations="enabled"/>** 
    
    
    **** 
    
  • 然后在函数上方添加注释@Secured(“ROLE_ADMIN”),以控制访问

然后,我在web.xml中添加应用程序上下文声明,如下所示:

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
              http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5"
         xmlns="http://java.sun.com/xml/ns/javaee">

 <!-- Default page to serve -->

  <welcome-file-list>
    <welcome-file>App.html</welcome-file>
  </welcome-file-list>
  <session-config>
    <session-timeout>10</session-timeout> <!-- in minutes -->
  </session-config>

App.html
10

上下文配置位置
/WEB-INF/applicationContext-security.xml
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
org.springframework.web.context.ContextLoaderListener

应用服务
com.google.gwt.app.example.server.AppServiceImpl
应用服务
/app/appService.rpc
注意,我刚刚声明了gwt servlet,而不是spring dispatcher servlet

然而,这种配置似乎不起作用。事实上,任何角色都有权访问该函数。 很奇怪。
希望你的答案

使用一个包含两个属性的
全局方法安全性
元素

如果您正在这样做的话,还可以阅读关于使用方法安全性和web控制器的问题(您还会发现这里讨论的相同问题)


您报告的日志消息不是错误,也不重要,除非您在表达式中使用了
hasPermission()

谢谢,第一条评论,我已经做了,谢谢,第一条评论,我已经做了,然后,第二条评论看起来很有趣,我刚刚读了文档。我应该给出背景,因为我将spring安全性与GWT集成在一起,在web.xml中,我声明了GWTServlet而不是dispatcherServlet;因此,如果方法安全性应该与DispatcherServlet一起工作,那么缺少DispatcherServlet声明将导致此dis函数问题。那么你的想法是什么呢?很抱歉,我没有权利投票支持你的答案,但这确实很有帮助。你应该编辑你的问题,提供更多关于你试图保护的bean实例的定义位置等信息。无论您使用的是GWT还是其他什么都不应该是相关的。如果需要,可以在非web应用程序中使用方法安全性。我询问了有关“您试图保护的bean实例是在哪里定义的”的信息。从您的配置来看,您似乎没有保护SpringBean,因此它不起作用。如果您试图保护的对象没有被Spring管理,那么Spring AOP(安全性所依赖的方法)将不会有任何效果。如果是这种情况,则只有在使用aspectj时,Spring安全性才会起作用。
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
      /WEB-INF/applicationContext-security.xml
  </param-value>
  </context-param>

  <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>appService</servlet-name>
    <servlet-class>com.google.gwt.app.example.server.AppServiceImpl</servlet-class>
  </servlet>
  <servlet-mapping>
     <servlet-name>appService</servlet-name>
     <url-pattern>/app/appService.rpc</url-pattern>
  </servlet-mapping>

</web-app>