我在两台tomcat
服务器上分别部署了spring web服务和业务层。 (如问题Spring WS separately deploy web service and bussiness layer中所述)。
业务层只是一个servlet容器,Web服务与它进行通信httpinvoker
。
我使用基于tomcat容器的身份验证与弹簧PreAuthenticatedAuthenticationProvider
和J2eePreAuthenticatedProcessingFilter
。这里我没有为客户端应用程序提供任何身份验证令牌。 (我的意思是我不是手动进行任何会话处理。它只由tomcat管理)
现在我想确保对业务层的请求来自经过身份验证的客户端。我发现的一件事是将我从Web服务的安全上下文获得的Authentication
对象作为请求参数SecurityContextHolder.getContext().getAuthentication()
传递给业务层。但是我没有办法验证Authentication
对象。那么在我的业务层实现安全性的方法上有什么想法吗?
答案 0 :(得分:3)
httpinvoker远程处理方式使用http客户端,默认情况下它将使用JDK中的普通HttpURLConnection
。使用哪种连接方式取决于HttpInvokerRequestExecutor
的实现,默认情况下为SimpleHttpInvokerRequestExecutor
。
现在您可以切换到使用Apache Commons HttpClient的其他实现之一。然后,您可以使用BASIC身份验证(或摘要)将用户名/密码传递给服务层(而不是Authentication
对象。
Spring Security已经为您提供了这个自定义实现,所以基本上您唯一需要做的就是(客户端)重新配置HttpInvokerProxyFactoryBean
。
<bean id="yourServiceProxy" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="httpInvokerRequestExecutor" ref="requestExecutor" />
</bean>
<bean id="requestExecutor" class="org.springframework.security.remoting.httpinvoker.AuthenticationSimpleHttpInvokerRequestExecutor"/>
另请参阅javadoc和Spring Security Reference Guide。该类可以在spring-security-remoting
依赖项中找到。在此依赖关系旁边,您需要将业务层配置为使用基本身份验证。