Search in sources :

Example 1 with AuthUser

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;
}
Also used : AuthUser(com.mendmix.common.model.AuthUser)

Example 2 with AuthUser

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();
}
Also used : AuthUser(com.mendmix.common.model.AuthUser)

Example 3 with AuthUser

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();
}
Also used : Serializable(java.io.Serializable) BaseEntity(com.mendmix.mybatis.core.BaseEntity) AuthUser(com.mendmix.common.model.AuthUser) Map(java.util.Map) HashMap(java.util.HashMap) MybatisHanlerInitException(com.mendmix.mybatis.exception.MybatisHanlerInitException)

Example 4 with AuthUser

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();
}
Also used : AuthUser(com.mendmix.common.model.AuthUser)

Example 5 with AuthUser

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;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) RequestHeaderBuilder(com.mendmix.springweb.client.RequestHeaderBuilder) Builder(org.springframework.http.server.reactive.ServerHttpRequest.Builder) AuthUser(com.mendmix.common.model.AuthUser)

Aggregations

AuthUser (com.mendmix.common.model.AuthUser)13 JeesuiteBaseException (com.mendmix.common.JeesuiteBaseException)1 BaseEntity (com.mendmix.mybatis.core.BaseEntity)1 MybatisHanlerInitException (com.mendmix.mybatis.exception.MybatisHanlerInitException)1 RequestHeaderBuilder (com.mendmix.springweb.client.RequestHeaderBuilder)1 Serializable (java.io.Serializable)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BinaryExpression (net.sf.jsqlparser.expression.BinaryExpression)1 Expression (net.sf.jsqlparser.expression.Expression)1 Parenthesis (net.sf.jsqlparser.expression.Parenthesis)1 StringValue (net.sf.jsqlparser.expression.StringValue)1 AndExpression (net.sf.jsqlparser.expression.operators.conditional.AndExpression)1 OrExpression (net.sf.jsqlparser.expression.operators.conditional.OrExpression)1 EqualsTo (net.sf.jsqlparser.expression.operators.relational.EqualsTo)1 InExpression (net.sf.jsqlparser.expression.operators.relational.InExpression)1 LikeExpression (net.sf.jsqlparser.expression.operators.relational.LikeExpression)1 Column (net.sf.jsqlparser.schema.Column)1 Before (org.junit.Before)1