春天不是强制执行法的安全注解 [英] spring not enforcing method security annotations
问题描述
我有些失去了什么,为什么春天是不是我的服务接口上强制执行@Secured(ROLE_USER)。我的控制器使用注释成立。
我的服务界面的例子
公共接口MyServiceManager { @Secured(ROLE_USER)
公共无效删除(INT CID); @RolesAllowed({ROLE_USER})
公开联系getContact(INT的ContactID);
}
我的安全上下文:
<全球方法的安全性保护的注解已启用= JSR250的注解=已启用>
< /全球方法安全>< HTTP自动配置=真正的>
<拦截的URL模式=/安全/ **访问=ROLE_SUPERVISOR/>
<拦截的URL模式=/ **的addContact访问=IS_AUTHENTICATED_REMEMBERED/>
<拦截的URL模式=/ **访问=IS_AUTHENTICATED_ANONYMOUSLY/><并发会话控制最大的会话=1
异常如果-最大超标=真/>
<形式登录的login-page =/ login.jsp的认证失败-URL =?/ login.jsp的login_error = 1/>
<注销注销-成功-URL =/ welcome.do注销-URL =/注销/>
< / HTTP>
<身份验证提供者>
<密码-CN codeR哈希=MD5/>
<使用者服务>
<使用者名称=棒密码=a564de63c2d0da68cf47586ee05984d7当局=ROLE_SUPERVISOR,ROLE_USER,ROLE_TELLER/>
< /用户服务>
< /认证供应商>
你有语句
<全球方法的安全性保护的注解=已启用JSR250的注解=已启用/>
相同的配置文件中所定义的MyServiceManager豆一中?我有同样的问题,直到我打开调试的org.springframework,并注意到春季安全只适用于同一个文件,其中全球方法的安全性是在中定义的。
I'm some what lost as to why spring isn't enforcing the @Secured("ROLE_USER") on my service interface. My controllers are established using annotations.
An example of my service Interface
public interface MyServiceManager {
@Secured("ROLE_USER")
public void delete(int cid);
@RolesAllowed({"ROLE_USER"})
public Contact getContact(int contactId);
}
my security-context:
<global-method-security secured-annotations="enabled" jsr250-annotations="enabled">
</global-method-security>
<http auto-config="true" >
<intercept-url pattern="/secure/**" access="ROLE_SUPERVISOR" />
<intercept-url pattern="/addcontact**" access="IS_AUTHENTICATED_REMEMBERED" />
<intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<concurrent-session-control max-sessions="1"
exception-if-maximum-exceeded="true"/>
<form-login login-page="/login.jsp" authentication-failure-url="/login.jsp?login_error=1"/>
<logout logout-success-url="/welcome.do" logout-url="/logout"/>
</http>
<authentication-provider>
<password-encoder hash="md5"/>
<user-service>
<user name="rod" password="a564de63c2d0da68cf47586ee05984d7" authorities="ROLE_SUPERVISOR, ROLE_USER, ROLE_TELLER" />
</user-service>
</authentication-provider>
Do you have the statement
<global-method-security secured-annotations="enabled" jsr250-annotations="enabled" />
in the same configuration file as the one you defined the MyServiceManager bean? I had the same problem until I turned on debug for org.springframework, and noticed that spring security was only applied on the same file as the ones where global-method-security was defined in.
这篇关于春天不是强制执行法的安全注解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!