use of io.kylin.mdx.insight.common.PwdDecryptException in project mdx-kylin by Kyligence.
the class DatasetController method checkPermission.
private boolean checkPermission(HttpServletRequest httpServletRequest, String project) throws SemanticException {
if (SemanticConfig.getInstance().isConvertorMock()) {
return true;
}
String basicAuth;
basicAuth = httpServletRequest.getHeader(SemanticConstants.BASIC_AUTH_HEADER_KEY);
if (basicAuth == null) {
try {
basicAuth = datasetService.getUserPwd(authService.getCurrentUser());
} catch (PwdDecryptException e) {
throw new SemanticException(e);
}
}
String userAccessInfo = SemanticAdapter.INSTANCE.getAccessInfo(new ConnectionInfo(basicAuth, project));
return KylinPermission.GLOBAL_ADMIN.name().equalsIgnoreCase(userAccessInfo) || KylinPermission.ADMINISTRATION.name().equalsIgnoreCase(userAccessInfo);
}
use of io.kylin.mdx.insight.common.PwdDecryptException in project mdx-kylin by Kyligence.
the class AESWithECBEncryptor method decrypt.
private static byte[] decrypt(byte[] data) throws PwdDecryptException {
try {
Cipher cipher = Cipher.getInstance(AESWithECBEncryptor.DEFAULT_CIPHER_ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, AESWithECBEncryptor.KEY);
return cipher.doFinal(data);
} catch (Exception ex) {
throw new PwdDecryptException("Password Decryption error", ex);
}
}
use of io.kylin.mdx.insight.common.PwdDecryptException in project mdx-kylin by Kyligence.
the class AESWithECBEncryptorTest method testPwdDecryptException.
@Test
public void testPwdDecryptException() {
PwdDecryptException pwdDecryptException1 = new PwdDecryptException();
PwdDecryptException pwdDecryptException2 = new PwdDecryptException(new Throwable());
}
use of io.kylin.mdx.insight.common.PwdDecryptException in project mdx-kylin by Kyligence.
the class AESWithECBEncryptor method decrypt.
public static String decrypt(String cipherHexText) throws PwdDecryptException {
byte[] cipherBytes;
try {
cipherBytes = Hex.decodeHex(cipherHexText);
} catch (Exception e) {
throw new PwdDecryptException("Password decodeHex error", e);
}
byte[] clearBytes = decrypt(cipherBytes);
return new String(clearBytes, StandardCharsets.UTF_8);
}
use of io.kylin.mdx.insight.common.PwdDecryptException in project mdx-kylin by Kyligence.
the class DefaultDataServicesProvider method createDataSource.
/**
* Creates a JDBC data source from the JDBC credentials contained within a
* set of mondrian connection properties.
*
* <p>This method is package-level so that it can be called from the
* RolapConnectionTest unit test.
*
* @param dataSource Anonymous data source from user, or null
* @param connectInfo Mondrian connection properties
* @param buf Into which method writes a description of the JDBC credentials
* @return Data source
*/
@Override
public DataSource createDataSource(DataSource dataSource, Util.PropertyList connectInfo, StringBuilder buf) {
assert buf != null;
final String jdbcConnectString = connectInfo.get(RolapConnectionProperties.Jdbc.name());
final String jdbcUser = connectInfo.get(RolapConnectionProperties.JdbcUser.name());
final String jdbcPassword = connectInfo.get(RolapConnectionProperties.JdbcPassword.name());
String decryptPwd = "";
try {
decryptPwd = AESWithECBEncryptor.decrypt(jdbcPassword);
} catch (PwdDecryptException e) {
// TODO
}
final String dataSourceName = connectInfo.get(RolapConnectionProperties.DataSource.name());
final String ssl = connectInfo.get(RolapConnectionProperties.ssl.name());
if (dataSource != null) {
appendKeyValue(buf, "Anonymous data source", dataSource);
appendKeyValue(buf, RolapConnectionProperties.JdbcUser.name(), jdbcUser);
dataSource = new UserPasswordDataSource(dataSource, jdbcUser, decryptPwd);
return dataSource;
} else if (jdbcConnectString != null) {
// Get connection through own pooling datasource
appendKeyValue(buf, RolapConnectionProperties.Jdbc.name(), jdbcConnectString);
appendKeyValue(buf, RolapConnectionProperties.JdbcUser.name(), jdbcUser);
String jdbcDrivers = connectInfo.get(RolapConnectionProperties.JdbcDrivers.name());
String jdbcDelegate = connectInfo.get(RolapConnectionProperties.JdbcDelegate.name());
if (jdbcDrivers != null) {
RolapUtil.loadDrivers(jdbcDrivers);
}
// TODO: MDX Service 不需要加载 mysql oracle 等依赖
// final String jdbcDriversProp = MondrianProperties.instance().JdbcDrivers.get();
// RolapUtil.loadDrivers(jdbcDriversProp);
Properties jdbcProperties = RolapConnection.getJdbcProperties(connectInfo);
if (jdbcUser != null) {
jdbcProperties.put("user", jdbcUser);
}
jdbcProperties.put("password", decryptPwd);
if (jdbcDelegate != null) {
jdbcProperties.put("EXECUTE_AS_USER_ID", jdbcDelegate);
}
// MDX-Service 支持使用 http 连接 kylin
if (ssl != null) {
jdbcProperties.put("ssl", ssl);
}
jdbcProperties.put("timeZone", MondrianProperties.instance().JDBCTimeZone.get());
// JDBC connections are dumb beasts, so we assume they're not
// pooled. Therefore the default is true.
final boolean poolNeeded = connectInfo.get(RolapConnectionProperties.PoolNeeded.name(), "true").equalsIgnoreCase("true");
if (!poolNeeded) {
// Connection is already pooled; don't pool it again.
return new DriverManagerDataSource(jdbcConnectString, jdbcProperties);
}
return RolapConnectionPool.instance().getDriverManagerPoolingDataSource(jdbcConnectString, jdbcProperties, jdbcConnectString.toLowerCase().contains("mysql"));
} else if (dataSourceName != null) {
appendKeyValue(buf, RolapConnectionProperties.DataSource.name(), dataSourceName);
appendKeyValue(buf, RolapConnectionProperties.JdbcUser.name(), jdbcUser);
// Data sources are fairly smart, so we assume they look after
// their own pooling. Therefore the default is false.
final boolean poolNeeded = connectInfo.get(RolapConnectionProperties.PoolNeeded.name(), "false").equalsIgnoreCase("true");
// Get connection from datasource.
DataSourceResolver dataSourceResolver = getDataSourceResolver();
try {
dataSource = dataSourceResolver.lookup(dataSourceName);
} catch (Exception e) {
throw Util.newInternal(e, "Error while looking up data source (" + dataSourceName + ")");
}
if (poolNeeded) {
dataSource = RolapConnectionPool.instance().getDataSourcePoolingDataSource(dataSource, dataSourceName, jdbcUser, decryptPwd);
} else {
dataSource = new UserPasswordDataSource(dataSource, jdbcUser, decryptPwd);
}
return dataSource;
} else {
throw Util.newInternal("Connect string '" + connectInfo + "' must contain either '" + RolapConnectionProperties.Jdbc + "' or '" + RolapConnectionProperties.DataSource + "'");
}
}
Aggregations