use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.
the class HttpRequestEntity method useContext.
public HttpRequestEntity useContext() {
if (!getHeaders().containsKey(CustomRequestHeaders.HEADER_INVOKE_TOKEN)) {
header(CustomRequestHeaders.HEADER_INVOKE_TOKEN, TokenGenerator.generateWithSign());
}
AuthUser currentUser;
if (!headers.containsKey(CustomRequestHeaders.HEADER_AUTH_USER) && (currentUser = CurrentRuntimeContext.getCurrentUser()) != null) {
header(CustomRequestHeaders.HEADER_AUTH_USER, currentUser.toEncodeString());
}
String systemId = CurrentRuntimeContext.getSystemId();
if (systemId != null) {
header(CustomRequestHeaders.HEADER_SYSTEM_ID, systemId);
}
String tenantId = CurrentRuntimeContext.getTenantId(false);
if (tenantId != null) {
header(CustomRequestHeaders.HEADER_TENANT_ID, tenantId);
}
header(CustomRequestHeaders.HEADER_RESP_KEEP, Boolean.TRUE.toString());
return this;
}
use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.
the class RequestLogBuilder method requestLogMessage.
public static String requestLogMessage(String uri, String method, Object parameters, Object body) {
StringBuilder builder = new StringBuilder();
builder.append("\n-----------request start-----------\n");
builder.append("uri :").append(uri).append("\n");
builder.append("method :").append(method).append("\n");
if (parameters != null) {
builder.append("parameters :").append(parameters).append("\n");
}
String tenantId = CurrentRuntimeContext.getTenantId(false);
if (tenantId != null)
builder.append("tenantId :").append(tenantId).append("\n");
AuthUser currentUser = CurrentRuntimeContext.getCurrentUser();
if (currentUser != null)
builder.append("currentUser :").append(currentUser.getName()).append("\n");
if (body != null) {
String bodyString;
if (body instanceof byte[]) {
byte[] bodyBytes = (byte[]) body;
if (bodyBytes.length > 1024)
bodyBytes = Arrays.copyOf(bodyBytes, 1024);
bodyString = new String(bodyBytes);
} else if (body instanceof String) {
bodyString = body.toString();
} else {
bodyString = JsonUtils.toJson(body);
}
builder.append("body :").append(bodyString).append("\n");
}
builder.append("-----------request end-----------\n");
return builder.toString();
}
use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.
the class CacheHandler method genarateQueryCacheKey.
/**
* 生成查询缓存key
* @param cacheInfo
* @param param
* @return
*/
@SuppressWarnings("unchecked")
public static String genarateQueryCacheKey(InvocationVals invocationVal, String keyPattern, Object param) {
String text;
try {
Object[] args;
if (param instanceof Map) {
Map<String, Object> map = (Map<String, Object>) param;
if (map.containsKey(STR_PARAM + "1")) {
args = new String[map.size() / 2];
for (int i = 0; i < args.length; i++) {
args[i] = CacheKeyUtils.objcetToString(map.get(STR_PARAM + (i + 1)));
}
} else {
args = new String[] { CacheKeyUtils.objcetToString(map) };
}
} else if (param instanceof BaseEntity) {
Serializable id = ((BaseEntity) param).getId();
if (id != null && !"0".equals(id.toString())) {
args = new String[] { (((BaseEntity) param).getId()).toString() };
} else {
args = new String[] { CacheKeyUtils.objcetToString(param) };
}
} else if (param instanceof Object[]) {
args = (Object[]) param;
} else if (param == null) {
args = new Object[0];
} else {
args = new String[] { CacheKeyUtils.objcetToString(param) };
}
text = StringUtils.join(args, GlobalConstants.UNDER_LINE);
} catch (Exception e) {
text = JsonUtils.toJson(param);
e.printStackTrace();
}
if (text.length() > 64)
text = DigestUtils.md5(text);
String key = String.format(keyPattern, text);
QueryCacheMethodMetadata methodMetadata = invocationVal.getQueryMethodMetadata();
if (methodMetadata == null || methodMetadata.isPk || methodMetadata.uniqueIndex) {
return key;
}
StringBuilder sb = new StringBuilder(key);
String tenantId = CurrentRuntimeContext.getTenantId();
if (tenantId != null) {
sb.append(GlobalConstants.AT).append(tenantId);
}
AuthUser currentUser;
if (invocationVal.isDynaDataPermEnabled() && (currentUser = CurrentRuntimeContext.getCurrentUser()) != null) {
sb.append(GlobalConstants.AT).append(currentUser.getId());
}
return sb.toString();
}
use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.
the class LogMessageFormat method buildLogTail.
public static String buildLogTail(String actionKey) {
StringBuilder builder = new StringBuilder();
builder.append("[");
if (actionKey != null) {
builder.append("<actionKey:").append(actionKey).append(">");
}
String systemId = CurrentRuntimeContext.getSystemId();
if (systemId != null)
builder.append("<systemId:").append(systemId).append(">");
String tenantId = CurrentRuntimeContext.getTenantId(false);
if (tenantId != null)
builder.append("<tenantId:").append(tenantId).append(">");
AuthUser currentUser = CurrentRuntimeContext.getCurrentUser();
if (currentUser != null)
builder.append("<currentUser:").append(currentUser.getName()).append(">");
builder.append("]");
return builder.toString();
}
use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.
the class GlobalHeaderHanlder method process.
@Override
public Builder process(ServerWebExchange exchange, BizSystemModule module, Builder requestBuilder) {
HttpHeaders headers = exchange.getRequest().getHeaders();
Builder reqBuilder = requestBuilder == null ? exchange.getRequest().mutate() : requestBuilder;
if (!headers.containsKey(CustomRequestHeaders.HEADER_REQUEST_ID)) {
reqBuilder.header(CustomRequestHeaders.HEADER_REQUEST_ID, TokenGenerator.generate());
}
reqBuilder.header(CustomRequestHeaders.HEADER_INVOKER_IS_GATEWAY, Boolean.TRUE.toString());
//
RequestHeaderBuilder.getHeaders().forEach((k, v) -> {
reqBuilder.header(k, v);
});
//
Boolean trustedRequest = ThreadLocalContext.get(GatewayConstants.CONTEXT_TRUSTED_REQUEST);
if (trustedRequest == null || !trustedRequest) {
// 一些token禁止前端传入
if (headers.containsKey(CustomRequestHeaders.HEADER_IGNORE_TENANT)) {
reqBuilder.headers(httpHeaders -> httpHeaders.remove(CustomRequestHeaders.HEADER_IGNORE_TENANT));
}
if (headers.containsKey(CustomRequestHeaders.HEADER_AUTH_USER)) {
reqBuilder.headers(httpHeaders -> httpHeaders.remove(CustomRequestHeaders.HEADER_AUTH_USER));
AuthUser currentUser = CurrentRuntimeContext.getCurrentUser();
if (currentUser != null) {
reqBuilder.header(CustomRequestHeaders.HEADER_AUTH_USER, currentUser.toEncodeString());
}
}
}
return reqBuilder;
}
Aggregations