這裏是對問題的描述。我正在用GWT開發一個Web應用程序。我用以下代碼成功地將spring security和gwt結合起來用於身份驗證功能。現在我想在我的web應用程序中使用spring的「方法安全性」。所以我做了什麼,它說在http://static.springsource.org/spring-security/site/docs/3.1.x/reference/ns-config.html,春季安全方法授權不起作用
只需添加在上面mentionned應用程序上下文文件
<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」),我該怎麼CONTROLE訪問
然後我在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。
但是,似乎這種配置不起作用。事實上,任何角色都可以擁有訪問該功能的權限。 很奇怪。 希望你的回答!
謝謝,作爲第一條評論,我已經完成了<! - <全局方法安全性pre-post-annotations =「enabled /> - >, – lhuang 2012-03-19 15:36:29
謝謝,第一條評論,我已經完成了<! - - >然後,第二個評論看起來非常有趣,我剛剛閱讀了文檔。我應該提供背景,因爲我在GWT中集成了GWT的spring安全性,我在web.xml中聲明瞭gwt-servlet而不是dispatcherServlet;因此,如果方法安全性應該與dispatherServlet一起工作,那麼缺少DispatcherServlet聲明會導致此功能失效問題。那麼你的想法是什麼? –
lhuang
2012-03-19 15:49:19
對不起,我沒有權利爲您的答案投票,但它確實有幫助 – lhuang 2012-03-19 15:51:39