Spring Security MethodSecurityInterceptor

时间:2011-08-01 09:17:48

标签: security methods spring-security

我在tomcat6上运行了一个Java应用程序。 我正在使用spring 3.0.4和spring security 3.0.5。

保护我的dao方法的访问权限我想使用spring security MethodSecurityInterceptor。但是这个实际上并没有“拦截”访问权。

配置如下:

<bean id="securityInterceptor" class="org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor"> 

    <property name="authenticationManager"> 
        <ref bean="authenticationManager"/> 
    </property> 

    <property name="accessDecisionManager"> 
        <ref bean="accessDecisionManager"/> 
    </property> 

    <property name="securityMetadataSource">
        <value> 
            com.xkst.dao.InvoiceDao.*=ROLE_ADMIN
            com.xkst.dao.UserDao.*=ROLE_ADMIN
        </value>
    </property> 
</bean>

根据配置,UserDao的任何方法的每次访问都应该被截获一个受控制的。

富客户端Java应用程序可以访问要保护的方法。为了使服务可用于客户端,我使用spring HttpInvokerServiceExporter

不直接导出dao类。导出一个服务类,为客户端提供单点访问。

在客户端,我有这个clientContext.xml文件引用服务器上的导出服务。

在客户端代码中,我只需加载上下文并从中选择导出的bean

public class SecurityTest {
public static void main(String[] args) {


    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("clientContext.xml");
    EntityServiceInterface serverService = (EntityServiceInterface) ctx.getBean("entityServiceInterface");

    List<UserEntity> users = serverService.performGetAllUsers();
    for(UserEntity user : users) {
        System.out.println(user.getUserName());
    }

}

这里我可以在我的客户端上调用'serverService'的任何方法,该方法应该由'MethodSecurityInterceptor'保护而不进行身份验证。我可以查询我的'UserDao'中的所有数据。

我真的不知道缺少的链接是什么。

authenticationManageraccessDecisionManager也已配置。服务器启动时没有错误消息。它甚至记录了“安全方法”的创建,如:

2011-08-01 10:38:48,675  INFO MethodDefinitionMap:75 - Adding secure method [public java.util.List com.xkst.dao.UserDao.findAll()] with attributes [[ROLE_ADMIN]]

那么我做错了什么?

0 个答案:

没有答案