私は多くの同様の質問を見つけましたが、誰も私の問題を解決しませんでした。 私の問題はROLE_USER
の機能にアクセスできますROLE_ADMIN
@PreAuthorize注釈が動作しないスプリングセキュリティ
私のspring-security.xmlコードは以下のとおりです。私は<s:global-method-security pre-post-annotations="enabled"/>
私のコードを追加し
<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>
は、リソースが見つからないというエラーが表示され、私は自分のコードを削除すると正常に実行され、
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";
}
はい私が追加したとき、私は知っているが、
私のコードは、リソースが見つからないというエラーを示して、あなたはそれを修正する方法を知っていますか? – Raheelorg.springframework.web.context.ContextLoaderListenerクラスのリスナーインスタンスにコンテキスト初期化イベントを送信する例外];ネストされた例外はjava.lang.NoClassDefFoundErrorです:org/aopalliance/intercept/MethodInterceptor – Raheel
と私はspring security3.07を使用しています – Raheel