1

I would like to call a REST web service from my client application using FEIGN and SEEDSTACK. The web service, which is developed with SEEDSATCK too, is configured with the following authentication method: "filters: [ authcBasic ]"

How to configure or program the client to get the authentication right? How to pass the USER and PASSWORD information?

client FEIGNAPI class:

@FeignApi
public interface neosdServer {

    @RequestLine("GET /file/getfilesprop")
    List<NeosdFile> getfilesprop();

    @RequestLine("GET /file/getfiles")
    List<String> getfiles();
}

client APPLICATION.YAML

feign:
  endpoints:
    neosdClient.interfaces.rest.neosdServer: 
      baseUrl: http://localhost:8080
      encoder: feign.jackson.JacksonEncoder
      decoder: feign.jackson.JacksonDecoder

server APPLICATION.YAML

  web:
    urls:
      -
        pattern: /file/getfiles
        filters: [ authcBasic, 'roles[read]' ]   
KatteStone
  • 11
  • 1
  • 3

1 Answers1

2

The current SeedStack integration doesn't support configuring interceptors on feign builders for now. Instead, to do authentication you can specify a header in your Feign interface with the @Headers annotation (example for basic authentication):

@FeignApi
@Headers({"Authorization: Basic {credentials}"})
public interface neosdServer {

    @RequestLine("GET /file/getfilesprop")
    List<NeosdFile> getfilesprop(@Param("credentials") String credentials);

    @RequestLine("GET /file/getfiles")
    List<String> getfiles(@Param("credentials") String credentials);
}

Note that @Headers can also be used on individual methods.

You will then have to pass the credentials as method parameter. An example implementation, with credentials coming from your application configuration, coudl be:

public class MyClass {
    @Configuration("myApp.credentials.user")
    private String username;
    @Configuration("myApp.credentials.password")
    private String password;
    @Inject
    private NeoSdClient client;

    public void myMethod() {
        List<String> files = client.getFiles(encodeCredentials());
    }

    private String encodeCredentials() {
        return BaseEncoding
                .base64()
                .encode((username + ":" + password)
                        .getBytes(Charsets.UTF_8));
    }
}

I created an issue on the Feign add-on repository to track the implementation of interceptor support: https://github.com/seedstack/feign-addon/issues/4.

Adrien LAUER
  • 444
  • 2
  • 7