我發現了許多類似的問題,但沒有解決我的問題。 我的問題是ROLE_USER
可以訪問的功能ROLE_ADMIN
@PreAuthorize註解不起作用彈簧安全
我的spring-security.xml代碼如下。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:s="http://www.springframework.org/schema/security"
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">
<s:http auto-config="true" use-expressions="true">
<s:intercept-url pattern="/index.jsp" access="permitAll" />
<s:intercept-url pattern="/welcome*" access="hasRole('ROLE_USER')" />
<s:intercept-url pattern="/helloadmin*" access="hasRole('ROLE_ADMIN')" />
<s:form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<s:logout logout-success-url="/logout" />
</s:http>
<s:authentication-manager>
<s:authentication-provider>
<s:user-service>
<s:user name="asif" password="123456" authorities="ROLE_USER,ROLE_ADMIN" />
<s:user name="raheel" password="123456" authorities="ROLE_USER" />
</s:user-service>
</s:authentication-provider>
</s:authentication-manager>
當我添加<s:global-method-security pre-post-annotations="enabled"/>
我的代碼顯示了資源未找到錯誤,當我刪除我的代碼成功執行,但ROLE_USER
可以訪問ROLE_ADMIN
功能
我的控制器功能。
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value="/delete", method = RequestMethod.GET)
public String DeleteAll(ModelMap model, Principal principal) {
org.springframework.security.core.userdetails.User activeUser = (org.springframework.security.core.userdetails.User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
System.out.println("Active user is "+activeUser.getUsername()+"Authorities are "+activeUser.getAuthorities());
return "deleteUsers";
}
是的,我知道,但是當我添加
我的代碼顯示資源沒有發現錯誤,你知道如何解決它? – Raheel 2012-08-07 09:27:13將異常發送上下文初始化事件給類的監聽器實例org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanDefinitionStoreException:異常解析來自ServletContext資源的XML文檔異常[/WEB-INF/spring-security.xml ]。嵌套異常是java.lang.NoClassDefFoundError:org/aopalliance/intercept/MethodInterceptor – Raheel 2012-08-08 04:29:20
和我正在使用spring security3.07 – Raheel 2012-08-08 05:16:07