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;
}
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;
}
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;
}
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) {
}
}
}
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]");
}
}
Aggregations