-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: Improve service-to-service communication #6450
Comments
Looks good to me, I also had the need for a |
I have wanted to do #2 for such a long time and there are many quirks with it. As with JWT you don't have a OAuth Context, you basically have to read headers from the servlet request, but as soon as you do a Feign client request to another microservice it opens a separate Hystrix thread and you lose the "context". So definitly an advanced topic here. The simple workaround is to pass the header in the feignclient like that:
But this is not optimal. |
In my blog post on securing microservices, I used a package com.example;
import com.stormpath.sdk.servlet.http.Resolver;
import com.stormpath.zuul.account.ForwardedAccountHeaderFilter;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ForwardedAccountRequestInterceptor implements RequestInterceptor {
private static final Logger LOGGER = LoggerFactory.getLogger(ForwardedAccountRequestInterceptor.class);
private final Resolver<String> valueResolver;
public ForwardedAccountRequestInterceptor(Resolver<String> accountStringResolver) {
this.valueResolver = accountStringResolver;
}
@Override
public void apply(RequestTemplate template) {
if (template.headers().containsKey(ForwardedAccountHeaderFilter.DEFAULT_HEADER_NAME)) {
LOGGER.warn("The X-Forwarded-User has been already set");
} else {
LOGGER.debug("Constructing Header {} for Account", ForwardedAccountHeaderFilter.DEFAULT_HEADER_NAME);
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
template.header(ForwardedAccountHeaderFilter.DEFAULT_HEADER_NAME, valueResolver.get(request, response));
}
}
} |
@PierreBesson @mraible there's a getCurrentUserJWT method that you can use to get the JWT and put it in a Feign interceptor. |
Wow @mraible Thanks a lot ! This code should be in the default setup generated by JHipster !
I had known that this hystrix property was required but didn't know you could set it like that. IMO, this should be documented on our website. Also we need to better document the different timeouts. There are many kinds of timeout that must be taken into account when doing microservices:
|
Similarly, I have used |
-> @xetys would you be OK to close it? We just have too much work at the moment |
hmm...I just had also almost no time the last weeks...I would love to do this soon, if that's oks |
Can someone please guide me or share any resource on how to achieve microservice to microservice calls. I have 3 microservices where sometime I need to call each other as well as a call to gateway to get user-details. I am so lost I m using jhipster with jwt Looking for jhipster + FeignClient. I don't want to hard code any url or IP addresses.. I want to get host and ip using Eureka also want to avoid JWT for inter-service calls. Even anyone can share some links to read that would be very helpful Regards, |
@abhisheksharma85 : |
As UAA is out of beta and more oauth2 support is coming to microservice, I would like to propose some enhancements on the current state:
AuthorizedFeignClient
annotations to https://github.com/jhipster/jhipster/ to reduce generated codeAuthorizedFeignClient
toAuthorizedServiceFeignClient
for consistencyAuthorizedUserFeignClient
for JWT secured microservices, as it makes sense here tooOAuth2RestTemplate
, as I had cases where I needed RestTemplates over feign clientsjhipster service-client
with both, Feign and RestTemplate supportedI would like to know if there is interest in these improvements. Possibly something for Hacktoberfest?
The text was updated successfully, but these errors were encountered: