我正在编写套接字服务器(没有web应用程序!)应用程序,并希望使用基于方法的安全性来处理我的ACL需求.我按照一个小教程,通过示例找到了弹簧安全性
到目前为止我配置:
<security:global-method-security pre-post-annotations="enabled">
<security:expression-handler ref="expressionHandler" />
</security:global-method-security>
<bean id="expressionHandler" class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler">
<property name="permissionEvaluator">
<bean id="permissionEvaluator" class="myPermissionEvaluator" />
</property>
</bean>
<security:authentication-manager id="authenticationmanager">
<security:authentication-provider ref="authenticationprovider" />
</security:authentication-manager>
<bean id="authenticationprovider" class="myAuthenticationProvider" />
Run Code Online (Sandbox Code Playgroud)
使用服务bean:
@Named
public class ChannelService {
@PreAuthorize("isAuthenticated() and hasPermission(#channel, 'CHANNEL_WRITE')")
public void writeMessage(Channel channel, String message) { ... }
}
Run Code Online (Sandbox Code Playgroud)
一切都编译,应用程序启动并正常工作,但没有访问控制.我的调试日志显示我的Evaluator永远不会被调用.
当我尝试使用@Secured注释类似的东西时,注释被评估并且访问被拒绝.但基于角色的简单安全性不足以满足我的要求.
EDIT 做了一些测试:当我只配置secure-annotations ="enabled"时,基于角色的安全性工作.当在ADDITION中配置pre-post-annotations ="enabled"时既不安全也不预授权.当我只配置预注释后,它仍然无法正常工作.
EDIT2
一些更多的测试:只有secured_annotations ="enabled",我的频道服务的调用一旦激活前后注释,就会通过Cglib2AopProxy直接调用到频道服务中.没有拦截器,没有代理,没有.
我变得有点绝望......
EDIT3
我在这里调试记录我的测试是spring-security的一部分
只有secure-annotations ="enabled"
2012-04-12 13:36:46,171 INFO [main] o.s.s.c.SpringSecurityCoreVersion - You are running with Spring Security …Run Code Online (Sandbox Code Playgroud)