Hi all,
I have the following problem with Feign / Spring Boot.
First I had built an page where the users are logged in. The logindata will send from Angular to my SpringBoot Tomcat. With that logindata, I logged in a WebService and that WebService generate the needed data.
At the moment my servercode includes my credentials hardcodet. With this credentials I ask the Webservice and he answered me. Thats ok. But my feign-client established the authorisation during he startet. And I cant set new credential during runtime. So I always use the harcodet credentials.
@Data
@Configuration
public class MyFeignClient {
public String user = "name";
public String password = "passwort";
@Bean({"mybean"})
public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
return new BasicAuthRequestInterceptor( user, password );
}
}
@Component
@FeignClient(name = "service", configuration = MyFeignClient.class, url = "http://middleware:8080/web/rest/")
public interface ArticleDataService {
@GetMapping(path = "")
List<ArticleData> getAllArticleData();
}
Comment From: ryanjbaxter
So you want to change the credentials while the app is running?
Comment From: RayBausch
Yes, I want it.
Comment From: eacdy
@RayBausch Here goes the demo you want. https://gitee.com/itmuch/spring-cloud-yes/blob/master/ms-consumer-sample/src/main/java/com/itmuch/yes/consumer/feign/config/KeycloakRequestInterceptor.java
B.T.W, if you use thread isolation , you must write a hystrix concurrent strategy. otherwise you will never get the ThreadLocal context.
The hystrix concurrent strategy demo code is here: https://gitee.com/itmuch/spring-cloud-yes/tree/master/ms-consumer-sample/src/main/java/com/itmuch/yes/consumer/hystrix/request, I hope it helps.
Comment From: RayBausch
Hallo eacd,
thank you for answering. That's an intresting solution. But unfortunatly the middleware where I asked didn't use keycloak.
Thanks Ray
Comment From: ryanjbaxter
Why doesnt using the configuration server and refresh work for you?
Comment From: eacdy
@RayBausch The point is not keycloak, but the code below:
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
Since you get the request, you can put your dynamic username/password into the request , and use the code above to get username/password .
Comment From: spring-projects-issues
Closing due to age of the question. If you would like us to look at this issue, please comment and we will look at re-opening the issue.