JHipster - How to add route to external microservices in application.yml

一笑奈何 提交于 2021-01-29 10:42:30

问题


I'm using Jhipster 5.5.0 to build a zuul gateway capable to route rest request to different microservices. Some of this microservices are developed in different languages, deployed and running on different server. Every microservices is protected via OIDC using the same keycloak server, under different realms.

Now I need to configure zuul route on application.yml properties file of my gateway app, to access this service by external rest client (customers) and using zuul for filtering request and keycloak as oidc token provider. Then I modify gateway application.yml adding the following zuul route to a sample external service (this type of configuration work well with another zuul gateway developed for another project without using jhipster):

    # zuul routing:
    zuul:
      ignored-services: "*"
      routes:
        # external endpoints
        myapi-v2-test:
          path: /my-api/mypackage/v2/add
          sensitiveHeaders: Cookie, Set-Cookie
          url: http://192.168.3.148:8080/server/rest/api/mypackage_2.0.0/add

When I try to test the call using a soap-ui client with Auth Bearer token in header, provided by the keycloak server using the jhipster realm (and client_id "web_app"), I always receive the response error code 403 - Forbidden for path "/my-api/mypackage/v2/add". What is the right way to configure the application.yml of the gateway app?

Thank in advance for any help.

I'm not using registry service (e.g Spring Cloud Eureka or Jhipster Registry).


回答1:


I post my solution in case someone have the same question. To solve my problem I added in OAuth2SsoConfiguration.java this line of code in configure(WebSecurity web) method:

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring()
            .
            .antMatchers("/my-api/**")
            .
    }

and the following in configure(HttpSecurity http):

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .
        .
    .and()
        .
        .antMatchers("/my-api/**").permitAll()
        .
        .
}


来源:https://stackoverflow.com/questions/52928022/jhipster-how-to-add-route-to-external-microservices-in-application-yml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!