【发布时间】:2012-03-22 19:18:59
【问题描述】:
这里是问题的描述。我正在使用 GWT 开发一个 Web 应用程序。我已经使用以下代码成功地将 spring security 与 gwt 集成以实现身份验证功能。现在我想在我的 Web 应用程序中使用 spring “方法安全性”。所以我按照http://static.springsource.org/spring-security/site/docs/3.1.x/reference/ns-config.html 中所说的做了,
-
只需在上面提到的应用程序上下文文件中添加
<global-method-security secured-annotations="enabled"/>。<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>
<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>
请注意,我刚刚声明了 gwt-servlet 而不是 spring 调度程序 servlet。
但是,这种配置似乎不起作用。事实上,任何角色都可以拥有访问该功能的权限。 很奇怪。 希望您的回答!
【问题讨论】:
标签: gwt spring-security