Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » REST with authentication
REST with authentication [message #1842526] Tue, 22 June 2021 08:56 Go to next message
Faruk Caglar is currently offline Faruk CaglarFriend
Messages: 33
Registered: August 2019
Member
Hi,

within our scout application (scout 11) we need to use an external REST service with authentication (HTTP Basic Auth) . The technical documentation says, that the client helper class is used to specify the URL as well as additional properties used to build up the connection (like authentication). But we haven't found how to support the credentials within the class.

I would appreciate any suggestion. Thanks

[Updated on: Tue, 22 June 2021 09:07]

Report message to a moderator

Re: REST with authentication [message #1842527 is a reply to message #1842526] Tue, 22 June 2021 09:23 Go to previous messageGo to next message
Paolo Bazzi is currently offline Paolo BazziFriend
Messages: 33
Registered: January 2017
Location: Switzerland
Member
Faruk Caglar wrote on Tue, 22 June 2021 08:56
Hi,
within our scout application (scout 11) we need to use an external REST service with authentication (HTTP Basic Auth) . The technical documentation says, that the client helper class is used to specify the URL as well as additional properties used to build up the connection (like authentication). But we haven't found how to support the credentials within the class.


You need to add a request filter within your client helper:

  @Override
  protected List<ClientRequestFilter> getRequestFiltersToRegister() {
    List<ClientRequestFilter> filters = super.getRequestFiltersToRegister();
    filters.add(BEANS.get(MyAuthenticationClientRequestFilter.class));
    return filters;
  }


Which may be implemented like this:

@Bean
public class MyAuthenticationClientRequestFilter implements ClientRequestFilter {

  public static final String HTTP_BASIC_AUTH_NAME = "Basic";
  public static final Charset HTTP_BASIC_AUTH_CHARSET = StandardCharsets.ISO_8859_1;

  @Override
  public void filter(ClientRequestContext requestContext) throws IOException {
    if (requestContext.getHeaders().get(HttpHeaders.AUTHORIZATION) != null) {
      return;
    }

    String authHeader = createBasicAuthHeader();
    if (authHeader == null) {
      return;
    }
    requestContext.getHeaders().putSingle(HttpHeaders.AUTHORIZATION, authHeader);
  }

  protected String createBasicAuthHeader() {
    String userpass =  // get by property / config / hardCode
    if (userpass == null) {
      return null;
    }
    return HTTP_BASIC_AUTH_NAME + " " + Base64Utility.encode(userpass.getBytes(HTTP_BASIC_AUTH_CHARSET));
  }
}


Regards,
Paolo


Eclipse Scout Homepage | Documentation | GitHub
Re: REST with authentication [message #1842537 is a reply to message #1842527] Tue, 22 June 2021 15:24 Go to previous message
Faruk Caglar is currently offline Faruk CaglarFriend
Messages: 33
Registered: August 2019
Member
great. Thanks Paolo
Previous Topic:How to register a listener to datachange on Form or Page
Next Topic:Does someone know how to add a custom to logger MDC
Goto Forum:
  


Current Time: Tue Jul 16 10:31:24 GMT 2024

Powered by FUDForum. Page generated in 0.03358 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top