Search in sources :

Example 6 with AuthUser

use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.

the class SecurityDelegating method doAuthenticationForOauth2.

public static String doAuthenticationForOauth2(String type, String name, String password) {
    AuthUser userInfo = getInstance().decisionProvider.validateUser(type, name, password);
    String authCode = TokenGenerator.generate();
    setTemporaryCacheValue(authCode, userInfo, 60);
    return authCode;
}
Also used : AuthUser(com.mendmix.common.model.AuthUser)

Example 7 with AuthUser

use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.

the class RequestHeaderBuilder method getHeaders.

public static Map<String, String> getHeaders() {
    Map<String, String> headers = CurrentRuntimeContext.getCustomHeaders();
    // 
    Map<String, String> appHeaders = null;
    if (headerProvider != null)
        appHeaders = headerProvider.headers();
    if (appHeaders != null && !appHeaders.isEmpty()) {
        headers.putAll(appHeaders);
    }
    if (!headers.containsKey(CustomRequestHeaders.HEADER_REQUEST_ID)) {
        headers.put(CustomRequestHeaders.HEADER_REQUEST_ID, TokenGenerator.generate());
    }
    if (!headers.containsKey(CustomRequestHeaders.HEADER_INVOKE_TOKEN)) {
        headers.put(CustomRequestHeaders.HEADER_INVOKE_TOKEN, TokenGenerator.generateWithSign());
    }
    headers.put(CustomRequestHeaders.HEADER_INVOKER_APP_ID, GlobalRuntimeContext.APPID);
    // 登录用户
    AuthUser currentUser = CurrentRuntimeContext.getCurrentUser();
    if (currentUser != null) {
        headers.put(CustomRequestHeaders.HEADER_AUTH_USER, currentUser.toEncodeString());
    }
    // 租户
    String tenantId = CurrentRuntimeContext.getTenantId(false);
    if (tenantId != null) {
        headers.put(CustomRequestHeaders.HEADER_TENANT_ID, tenantId);
    }
    String clientType = CurrentRuntimeContext.getClientType();
    if (clientType != null) {
        headers.put(CustomRequestHeaders.HEADER_CLIENT_TYPE, clientType);
    }
    return headers;
}
Also used : AuthUser(com.mendmix.common.model.AuthUser)

Example 8 with AuthUser

use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.

the class UserMockUtils method initMockContextIfOnCondition.

public static AuthUser initMockContextIfOnCondition() {
    AuthUser authUser = CurrentRuntimeContext.getCurrentUser();
    if (authUser == null && isEnabled()) {
        CurrentRuntimeContext.setClientType(ResourceUtils.getProperty("mendmix.mock.context.clientType"));
        CurrentRuntimeContext.setTenantId(ResourceUtils.getProperty("mendmix.mock.context.tenantId"));
        CurrentRuntimeContext.setSystemId(ResourceUtils.getProperty("mendmix.mock.context.systemId"));
        authUser = new AuthUser();
        authUser.setId(ResourceUtils.getProperty("mendmix.mock.context.user.id", "1"));
        authUser.setPrincipalType(ResourceUtils.getProperty("mendmix.mock.context.user.principalType", "staff"));
        authUser.setPrincipalId(ResourceUtils.getProperty("mendmix.mock.context.user.principalId", "1"));
        authUser.setName(ResourceUtils.getProperty("mendmix.mock.context.user.name", "mockuser"));
        authUser.setType(ResourceUtils.getProperty("mendmix.mock.context.user.type"));
        authUser.setDeptId(ResourceUtils.getProperty("mendmix.mock.context.user.deptId"));
        authUser.setPostId(ResourceUtils.getProperty("mendmix.mock.context.user.postId"));
        authUser.setAdmin(ResourceUtils.getBoolean("mendmix.mock.context.user.isAdmin"));
        CurrentRuntimeContext.setAuthUser(authUser);
    }
    return authUser;
}
Also used : AuthUser(com.mendmix.common.model.AuthUser)

Example 9 with AuthUser

use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.

the class CurrentRuntimeContext method addContextHeaders.

public static void addContextHeaders(Map<String, String> headers) {
    String headerVal;
    for (String headerName : contextHeaders) {
        if (!headers.containsKey(headerName))
            continue;
        headerVal = headers.get(headerName);
        if (headerVal != null) {
            setContextVal(headerName, headerVal);
        }
    }
    // 
    if (headers.containsKey(CustomRequestHeaders.HEADER_AUTH_USER)) {
        headerVal = headers.get(CustomRequestHeaders.HEADER_AUTH_USER);
        AuthUser user = AuthUser.decode(headerVal);
        if (user != null) {
            ThreadLocalContext.set(CustomRequestHeaders.HEADER_AUTH_USER, user);
        }
    }
}
Also used : AuthUser(com.mendmix.common.model.AuthUser)

Example 10 with AuthUser

use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.

the class SqlRewriteHandler method handleTableDataPermission.

private Expression handleTableDataPermission(Expression originWhere, Table table, Map<String, String[]> dataMapping, boolean sharddingTenant) {
    if (!dataPermMappings.containsKey(table.getName())) {
        return originWhere;
    }
    Set<String> fieldNames;
    Expression newExpression = originWhere;
    String column;
    String[] values;
    Map<String, String> columnMapping = dataPermMappings.get(table.getName());
    fieldNames = columnMapping.keySet();
    boolean withSoftDelete = false;
    boolean withPermiCondition = false;
    for (String fieldName : fieldNames) {
        if (fieldName.equals(softDeletePropName)) {
            withSoftDelete = true;
            continue;
        }
        if (sharddingTenant && fieldName.equals(tenantPropName)) {
            column = tenantColumnName;
            String currentTenantId = CurrentRuntimeContext.getTenantId();
            if (currentTenantId == null)
                throw new JeesuiteBaseException("无法获取当前租户ID");
            values = new String[] { currentTenantId };
        } else {
            if (dataMapping == null || !dataMapping.containsKey(fieldName))
                continue;
            column = columnMapping.get(fieldName);
            values = dataMapping.get(fieldName);
            // 
            if (!withPermiCondition)
                withPermiCondition = true;
        }
        // 如果某个匹配字段为空直接返回null,不在查询数据库
        if (values == null || values.length == 0) {
            EqualsTo equalsTo = new EqualsTo();
            equalsTo.setLeftExpression(new Column(table, column));
            equalsTo.setRightExpression(new StringValue("_PERMISSION_NOT_MATCH_"));
            return equalsTo;
        }
        newExpression = handleColumnDataPermCondition(table, newExpression, column, values);
    }
    // 当前创建人
    if (withPermiCondition && ownerColumnName != null) {
        AuthUser currentUser = CurrentRuntimeContext.getCurrentUser();
        if (currentUser != null) {
            EqualsTo equalsTo = new EqualsTo();
            equalsTo.setLeftExpression(new Column(table, ownerColumnName));
            // TODO 需要按ID匹配否则出现同名
            equalsTo.setRightExpression(new StringValue(currentUser.getName()));
            // 
            newExpression = newExpression == null ? equalsTo : new OrExpression(new Parenthesis(newExpression), equalsTo);
        }
    }
    // 软删除
    if (withSoftDelete) {
        EqualsTo equalsTo = new EqualsTo();
        equalsTo.setLeftExpression(new Column(table, softDeleteColumnName));
        equalsTo.setRightExpression(new StringValue(softDeleteFalseValue));
        newExpression = newExpression == null ? equalsTo : new AndExpression(new Parenthesis(newExpression), equalsTo);
    }
    return newExpression;
}
Also used : AuthUser(com.mendmix.common.model.AuthUser) OrExpression(net.sf.jsqlparser.expression.operators.conditional.OrExpression) Parenthesis(net.sf.jsqlparser.expression.Parenthesis) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) Expression(net.sf.jsqlparser.expression.Expression) OrExpression(net.sf.jsqlparser.expression.operators.conditional.OrExpression) BinaryExpression(net.sf.jsqlparser.expression.BinaryExpression) LikeExpression(net.sf.jsqlparser.expression.operators.relational.LikeExpression) InExpression(net.sf.jsqlparser.expression.operators.relational.InExpression) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) Column(net.sf.jsqlparser.schema.Column) EqualsTo(net.sf.jsqlparser.expression.operators.relational.EqualsTo) StringValue(net.sf.jsqlparser.expression.StringValue)

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