package com.jwipc.api.interceptor;

import com.dtflys.forest.http.ForestRequest;
import com.dtflys.forest.interceptor.Interceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Base64;


/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@Component
public class OAInterceptor implements Interceptor<String> {
    @Value("${sys.oa-user}")
    private String user;
    @Value("${sys.oa-pass}")
    private String pass;

    @Override
    public boolean beforeExecute(ForestRequest request) {
        final String encodeToString = Base64.getEncoder().encodeToString((user + ":" + pass).getBytes());
        String authHeader = "Basic " + encodeToString;
        request.addHeader("Authorization", authHeader);
        return true;
    }
}
