feign oauth2

0

hystrix:
  command:
    default:
      execution:
        isolation:
          strategy: SEMAPHORE

	@Bean
	@ConditionalOnMissingBean
	public RequestInterceptor feignRequestInterceptor() {
		
		return new RequestInterceptor() {

//			private final String BEARER_TOKEN_TYPE = "Bearer";
			private final String AUTHORIZATION_HEADER = "Authorization";

			@Override
			public void apply(RequestTemplate requestTemplate) {
				final RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
				if (requestAttributes != null) {
					final HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
					final String token = request.getHeader(AUTHORIZATION_HEADER);
					requestTemplate.header(AUTHORIZATION_HEADER, new String[] { token });
				}
			}

//			@Override
//			public void apply(RequestTemplate requestTemplate) {
//				final SecurityContext securityContext = SecurityContextHolder.getContext();
//				final Authentication authentication = securityContext.getAuthentication();
//				if (authentication != null && authentication.getDetails() instanceof OAuth2AuthenticationDetails) {
//					final OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails();
//					requestTemplate.header(AUTHORIZATION_HEADER, String.format("%s %s", BEARER_TOKEN_TYPE, details.getTokenValue()));
//				}
//			}
			
		};
	}