Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic Authentication service called By Zuul

I'm Zuul as edge server. so all request pass by this edge server. I have a micro-service A. all web services of A are protected by Basic Authentication. How can we call the services of A b passing by Zuul proxy? Should I add header for messages?

like image 282
youssef Liouene Avatar asked Apr 25 '26 01:04

youssef Liouene


2 Answers

This is my Zuul filter:

public class BasicAuthorizationHeaderFilter extends ZuulFilter {


@Override
public String filterType() {
    return "pre";
}

@Override
public int filterOrder() {
    return 10;
}

@Override
public boolean shouldFilter() {
    return true;
}

@Override
public Object run() {

    RequestContext ctx = RequestContext.getCurrentContext();
    ctx.getRequest().getRequestURL();
    ctx.addZuulRequestHeader("Authorization", "Basic " + Utils.getBase64Credentials("user", "Token"));
    return null;
}

}
like image 72
youssef Liouene Avatar answered Apr 29 '26 22:04

youssef Liouene


Ideally the requester would have the token in the request.
If you want to have Zuul add the authentication token then you can create a ZuulFilter and use:

context.addZuulRequestHeader("Authorization", "base64encodedTokenHere");

Doing this would give open access to the services - which may not be wise.

like image 43
ianc Avatar answered Apr 29 '26 23:04

ianc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!