All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.macrocloud.kernel.context.props.BaseContextProperties Maven / Gradle / Ivy

package org.macrocloud.kernel.context.props;

import lombok.Getter;
import lombok.Setter;
import org.macrocloud.kernel.launch.constant.TokenConstant;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Headers 配置
 *
 * @author macro
 */
@Getter
@Setter
@ConfigurationProperties(BaseContextProperties.PREFIX)
public class BaseContextProperties {
	/**
	 * 配置前缀
	 */
	public static final String PREFIX = "kernel.context";
	/**
	 * 上下文传递的 headers 信息
	 */
	private Headers headers = new Headers();

	@Getter
	@Setter
	public static class Headers {
		/**
		 * 请求id,默认:Macro-RequestId
		 */
		private String requestId = "Macro-RequestId";
		/**
		 * 用于 聚合层 向调用层传递用户信息 的请求头,默认:Macro-AccountId
		 */
		private String accountId = "Macro-AccountId";
		/**
		 * 用于 聚合层 向调用层传递租户id 的请求头,默认:Macro-TenantId
		 */
		private String tenantId = "Macro-TenantId";
		/**
		 * 自定义 RestTemplate 和 Feign 透传到下层的 Headers 名称列表
		 */
		private List allowed = Arrays.asList("X-Real-IP", "x-forwarded-for", "authorization", "Authorization",
				TokenConstant.HEADER.toLowerCase(), TokenConstant.HEADER);
	}

	/**
	 * 获取跨服务的请求头
	 *
	 * @return 请求头列表
	 */
	public List getCrossHeaders() {
		List headerList = new ArrayList<>();
		headerList.add(headers.getRequestId());
		headerList.add(headers.getAccountId());
		headerList.add(headers.getTenantId());
		headerList.addAll(headers.getAllowed());
		return headerList;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy