Search in sources :

Example 16 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class MultiRouteDataSource method determineTargetDataSource.

protected DataSource determineTargetDataSource() {
    String lookupKey = currentDataSourceKey();
    DataSource dataSource = targetDataSources.get(lookupKey);
    if (dataSource == null) {
        throw new JeesuiteBaseException("Cannot determine target DataSource for lookup key [" + lookupKey + "]");
    }
    return dataSource;
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) AbstractDataSource(org.springframework.jdbc.datasource.AbstractDataSource) DataSource(javax.sql.DataSource)

Example 17 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class SensitiveOperProtectHandler method onInterceptor.

@Override
public Object onInterceptor(InvocationVals invocation) throws Throwable {
    Object[] objects = invocation.getArgs();
    MappedStatement ms = (MappedStatement) objects[0];
    if (ms.getSqlCommandType().equals(SqlCommandType.DELETE)) {
        throw new JeesuiteBaseException(4003, "当前已开启敏感操作保护");
    }
    return null;
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) MappedStatement(org.apache.ibatis.mapping.MappedStatement)

Example 18 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException 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 (!dataProfileMappings.containsKey(table.getName())) {
        return originWhere;
    }
    Set<String> fieldNames;
    Expression newExpression = originWhere;
    String column;
    String[] values;
    Map<String, String> columnMapping = dataProfileMappings.get(table.getName());
    fieldNames = columnMapping.keySet();
    for (String fieldName : fieldNames) {
        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.containsKey(fieldName))
                continue;
            column = columnMapping.get(fieldName);
            if (orgPropName != null && orgPropName.equalsIgnoreCase(fieldName)) {
                AuthUser currentUser = CurrentRuntimeContext.getCurrentUser();
                if (currentUser == null || StringUtils.isBlank(currentUser.getDeptId())) {
                    throw new JeesuiteBaseException("无法获取当前用户部门");
                }
                values = dataMapping.get(fieldName);
                if (MatchPolicy.exact.name().equals(values[0])) {
                    values = new String[] { currentUser.getDeptId() };
                } else {
                    values = new String[] { currentUser.getDeptId() + QUERY_FUZZY_CHAR };
                }
            } else {
                values = dataMapping.get(fieldName);
            }
        }
        // 如果某个匹配字段为空直接返回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);
    }
    return newExpression;
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) Expression(net.sf.jsqlparser.expression.Expression) 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) AuthUser(com.jeesuite.common.model.AuthUser) EqualsTo(net.sf.jsqlparser.expression.operators.relational.EqualsTo) StringValue(net.sf.jsqlparser.expression.StringValue)

Example 19 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class RsaSignUtils method decrypt.

public static String decrypt(PrivateKey key, byte[] encodedText) {
    ByteArrayOutputStream out = null;
    try {
        Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
        cipher.init(Cipher.DECRYPT_MODE, key);
        int inputLen = encodedText.length;
        if (inputLen <= MAX_DECRYPT_BLOCK) {
            return new String(cipher.doFinal(encodedText), StandardCharsets.UTF_8);
        }
        out = new ByteArrayOutputStream();
        int offSet = 0;
        byte[] cache;
        int i = 0;
        // 对数据分段解密
        while (inputLen - offSet > 0) {
            if (inputLen - offSet > MAX_DECRYPT_BLOCK) {
                cache = cipher.doFinal(encodedText, offSet, MAX_DECRYPT_BLOCK);
            } else {
                cache = cipher.doFinal(encodedText, offSet, inputLen - offSet);
            }
            out.write(cache, 0, cache.length);
            i++;
            offSet = i * MAX_DECRYPT_BLOCK;
        }
        return new String(out.toByteArray(), StandardCharsets.UTF_8);
    } catch (NoSuchAlgorithmException e) {
        throw new JeesuiteBaseException(4003, "无此解密算法");
    } catch (NoSuchPaddingException e) {
        e.printStackTrace();
        return null;
    } catch (InvalidKeyException e) {
        throw new JeesuiteBaseException(4003, "解密私钥非法,请检查");
    } catch (IllegalBlockSizeException e) {
        throw new JeesuiteBaseException(4003, "密文长度非法");
    } catch (BadPaddingException e) {
        throw new JeesuiteBaseException(4003, "密文数据已损坏");
    } finally {
        try {
            if (out != null)
                out.close();
        } catch (Exception e2) {
        }
    }
}
Also used : JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Cipher(javax.crypto.Cipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BadPaddingException(javax.crypto.BadPaddingException) InvalidKeyException(java.security.InvalidKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) SignatureException(java.security.SignatureException) BadPaddingException(javax.crypto.BadPaddingException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 20 with JeesuiteBaseException

use of com.jeesuite.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class GenericApiRequest method get.

public static String get(String url, Map<String, Object> parameters) {
    HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
    if (parameters != null) {
        for (String key : parameters.keySet()) {
            urlBuilder.addQueryParameter(key, parameters.get(key).toString());
        }
    }
    okhttp3.Request.Builder requestBuilder = new Request.Builder().url(urlBuilder.build());
    try {
        Response response = httpClient.newCall(requestBuilder.build()).execute();
        if (response.isSuccessful()) {
            return response.body().string();
        }
        String message = response.message();
        if (StringUtils.isBlank(message)) {
            message = HttpStatus.valueOf(response.code()).getReasonPhrase();
        }
        if (logger.isDebugEnabled())
            logger.debug("call_remote_api_error ->url:{},code:{},message:{}", url, response.code(), message);
        throw new JeesuiteBaseException(response.code(), message);
    } catch (Exception e) {
        logger.error("调用远程服务失败[" + url + "]", e);
        throw new JeesuiteBaseException("系统繁忙,稍后再试[004]");
    }
}
Also used : Response(okhttp3.Response) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException) Request(okhttp3.Request) HttpUrl(okhttp3.HttpUrl) JeesuiteBaseException(com.jeesuite.common.JeesuiteBaseException)

Aggregations

JeesuiteBaseException (com.jeesuite.common.JeesuiteBaseException)41 IOException (java.io.IOException)14 Request (okhttp3.Request)7 CosServiceException (com.qcloud.cos.exception.CosServiceException)4 CObjectMetadata (com.jeesuite.cos.CObjectMetadata)3 InputStream (java.io.InputStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 SignatureException (java.security.SignatureException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CUploadResult (com.jeesuite.cos.CUploadResult)2 WrapperResponseEntity (com.jeesuite.springweb.model.WrapperResponseEntity)2 COSObject (com.qcloud.cos.model.COSObject)2 ObjectMetadata (com.qcloud.cos.model.ObjectMetadata)2 QiniuException (com.qiniu.common.QiniuException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2