JHipster: forbidden error when trying to access microservice from gateway
<p>I'm following these recommendations: <a href="https://jhipster.github.io/microservices-architecture/" rel="nofollow">https://jhipster.github.io/microservices-architecture/</a> to organize the architecture of my microservices applications.</p>

<p>I have a setting with some microservices to be accessed by a gateway. I've already put the same secret (jhipster.security.authentication.jwt.secret) for all components (gateway, microservices and registry).</p>

<p>But, when I try to consume a microservice from the gateway, by the following way, I always receive a Access Denied Message (Forbidden 403):</p>

<pre><code>@FeignClient(value = "storageservice")
public interface StorageServiceClient {
    @RequestMapping(method = RequestMethod.GET, value = "api/applications")
    ResponseEntity&lt;List&lt;ApplicationDTO&gt;&gt; getApplications();
}
</code></pre>

<p>I'm testing by this way (in my Gateway):</p>

<pre><code>@RestController
@RequestMapping("/api")
public class StorageServiceTest {

@Inject
private DiscoveryClient discoveryClient;

@Inject
private RestTemplate template;

@Inject
private SecurityConfiguration security;

@Inject
private StorageServiceClient storageServiceClient;


@Inject
private AuthenticationManager authenticationManager;

@RequestMapping(value = "/apps",
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity&lt;List&lt;ApplicationDTO&gt;&gt; getApplications(){
    ResponseEntity&lt;List&lt;ApplicationDTO&gt;&gt; apps = storageServiceClient.getApplications();
    Stream.of(apps).forEach(System.out::println);
    return apps;
}
}
</code></pre>

<p>The interest thing is that I've tested the direct access to the microservice (via postman) and the routed access by the gateway and either have worked well. But, specifically in this case when I try to consume the microservice data from gateway via API, I receive the 403 error. </p>

<p>In my microservice I have the configuration (in MicroServiceConfiguration class ".antMatchers("/api/**").authenticated()"). But in all the cases, when I'm testing via Postman, I'm always passing a valid JWT Token. But only in this specific case it doesn't works... I even tried to use a @Header annotation in my "StorageServiceClient" but it didn't any effect. </p>

<p>*********** EDITED ***********:</p>

<p>I've solved the authentication issue by creating a RequestInterceptor like that:</p>

<pre><code>@Configuration
public class FeignConfig {

@Inject
private JHipsterProperties properties;

@Bean
public RequestInterceptor requestTokenBearerInterceptor() {
    return requestTemplate -&gt; {
        String token = Jwts.builder().
                setSubject("admin")
                .claim("auth", "admin")
                .signWith(SignatureAlgorithm.HS512, properties.getSecurity().getAuthentication().getJwt().getSecret())
                .compact();
        requestTemplate.header("Authorization", "Bearer " + token);
    };
}}
</code></pre>