它不能通过其前提传播到另一个进程(应用程序)。 看实施 SecurityContextPropagationChannelInterceptor 。它基于 ThreadStatePropagationChannelInterceptor 。再一次 的 线程状态 强> ,而不是通过网络到另一个进程。
SecurityContextPropagationChannelInterceptor
ThreadStatePropagationChannelInterceptor
由于没有一个通用的解决方案用于进程间 SecurityContext 转移,没有任何开箱即用的东西。
SecurityContext
我在另一个问题上回答你的问题( Spring Integration:SecurityContext传播 ),你应该转移 credential 仅通过HTTP作为标头。我甚至认为使用标准Apache做得更好 HTTPClient CredentialProvider (要么 BasicAuthorizationInterceptor 从Spring Framework 4.3.1)方法发送请求 Basic Authentication 头。真正通过网络使用Base64编码实现凭证的安全性。
credential
HTTPClient
CredentialProvider
BasicAuthorizationInterceptor
Basic Authentication
在接收方,你应该做类似的东西 https://github.com/spring-projects/spring-security/blob/master/web/src/main/java/org/springframework/security/web/authentication/www/BasicAuthenticationFilter.java#L224 :
byte[] base64Token = header.substring(6).getBytes("UTF-8"); byte[] decoded; try { decoded = Base64.decode(base64Token); } catch (IllegalArgumentException e) { throw new BadCredentialsException( "Failed to decode basic authentication token"); } String token = new String(decoded, getCredentialsCharset(request)); int delim = token.indexOf(":"); if (delim == -1) { throw new BadCredentialsException("Invalid basic authentication token"); } return new String[] { token.substring(0, delim), token.substring(delim + 1) };