0

我有两个使用 Spring Security 保护的 Spring Web 应用程序。这两个应用程序通过spring httpInvoker相互通信。访问控制工作正常。但是当我在 标签 httpinvoker return 403 status<csrf/>下启用 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]

弹簧安全 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();
4

1 回答 1

0

我认为这里的关键是为 HttpInvoker URL(s) 创建一个单独的配置:

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

 <http auto-config="true">
   <!-- same as before -->
 </http>
于 2015-03-25T13:03:32.907 回答