在服务器中启用csrf保护时,httpinvoker无法正常工作

时间:2015-03-25 10:26:16

标签: spring-mvc spring-security csrf spring-remoting httpinvoker

我有两个带弹簧安全保护的弹簧网络应用程序。这两个应用程序通过spring httpInovoker相互通信。访问控制工作正常。但是当我在<csrf/>标签httpinvoker返回403状态下的spring security中启用<http auto-config="true">时。 Stacktrace如下。但是相同的代码在没有csrf保护的情况下成功运行。请帮忙

org.springframework.remoting.RemoteAccessException: Could not access HTTP invoker remote service at [http://172.28.1.162:6060/ReporterRepository/ExposedLinkService.http]; nested exception is java.io.IOException: Did not receive successful HTTP response: status code = 403, status message = [Forbidden]

Spring security xml

<http auto-config="true">
    <intercept-url pattern="/home**" access="ROLE_ADMIN,ROLE_USER" />
            <intercept-url pattern="/admin**" access="ROLE_ADMIN" />
    <form-login 
        login-page="/loginuser" 
        default-target-url="/home" 
        authentication-failure-url="/loginuser?error" 
        username-parameter="username"
        password-parameter="password" />
    <logout logout-success-url="/loginuser?logout"  />
    <!-- enable csrf protection -->
    <csrf/>
</http>

<authentication-manager erase-credentials="false">
    <authentication-provider user-service-ref="myUserDetailsService" > 
    </authentication-provider>
</authentication-manager>

调用代码:

HttpInvokerProxyFactoryBean HttpinvokerFactory = new HttpInvokerProxyFactoryBean();
HttpinvokerFactory.setServiceInterface(ExposedLinkServiceInterface.class);
HttpinvokerFactory.setServiceUrl(ServiceUrl);
HttpinvokerFactory.setHttpInvokerRequestExecutor(( HttpInvokerRequestExecutor)ServerFramework.getInstance().getBean("httpInvokerRequestExecutor"));//Return the bean httpInvokerRequestExecutor
HttpinvokerFactory.afterPropertiesSet();

ExposedLinkServiceInterface exposedservice = (ExposedLinkServiceInterface) HttpinvokerFactory.getObject();                
List AvailabaleLinks= exposedservice.retrieveAllLinks();

1 个答案:

答案 0 :(得分:0)

我认为关键是为HttpInvoker URL创建一个单独的配置:

 <http pattern="/your-httpinvoker-path" create-session="stateless">
   <!-- security for httpinvoker without csrf protection -->
 </http>

 <http auto-config="true">
   <!-- same as before -->
 </http>