authentication feign header java spring

How to add a request interceptor to a feign client?

I want every time when I make a request through feign client, to set a specific header with my authenticated user.

This is my filter from which I get the authentication and set it to the spring security context:

public class PerformanceApplication {
public Filter requestDetailsFilter() {
return new RequestDetailsFilter();
public static void main(String[] args) {, args);
private class RequestDetailsFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
String userName = ((HttpServletRequest)servletRequest).getHeader("Z-User-Details");
String pass = ((HttpServletRequest)servletRequest).getHeader("X-User-Details");
if (pass != null)
pass = decrypt(pass);
SecurityContext secure = new SecurityContextImpl(); token = new UsernamePasswordAuthenticationToken(userName, pass);
secure. setAuthentication(token);
filterChain.doFilter(servletRequest, servletResponse);
public void destroy() {
private String decrypt(String str) {
try {
Cipher dcipher = new NullCipher();
// Decode base64 to get bytes
byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
// Decrypt
byte[] utf8 = dcipher.doFinal(dec);
// Decode using utf-8
return new String(utf8, "UTF8");
} catch (javax.crypto.BadPaddingException e) {
} catch (IllegalBlockSizeException e) {
} catch (UnsupportedEncodingException e) {
} catch ( e) {
return null;

This is my feign client:

public interface EmailClient {
@RequestMapping(value = "/api/email/send", method = RequestMethod.POST)
void sendEmail(@RequestBody Email email);

And here I have a request interceptor:

public class FeignRequestInterceptor implements RequestInterceptor {
private String headerValue;
public FeignRequestInterceptor() {
public FeignRequestInterceptor(String username, String password) {
this(username, password, ISO_8859_1);
public FeignRequestInterceptor(String username, String password, Charset charset) {
checkNotNull(username, "username");
checkNotNull(password, "password");
this.headerValue = "Basic " + base64encode((username + ":" + password).getBytes(charset));
private static String base64encode(byte[] bytes) {
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(bytes);
public void apply(RequestTemplate requestTemplate) {
requestTemplate.header("Authorization", headerValue);

I don’t know how to configure this interceptor to my client and how to set the header with the username and password. How can I accomplish that ?