Search in sources :

Example 1 with PwdDecryptException

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);
}
Also used : PwdDecryptException(io.kylin.mdx.insight.common.PwdDecryptException) ConnectionInfo(io.kylin.mdx.insight.core.meta.ConnectionInfo) SemanticException(io.kylin.mdx.insight.common.SemanticException)

Example 2 with PwdDecryptException

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);
    }
}
Also used : PwdDecryptException(io.kylin.mdx.insight.common.PwdDecryptException) Cipher(javax.crypto.Cipher) DecoderException(org.apache.commons.codec.DecoderException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PwdDecryptException(io.kylin.mdx.insight.common.PwdDecryptException)

Example 3 with PwdDecryptException

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());
}
Also used : PwdDecryptException(io.kylin.mdx.insight.common.PwdDecryptException) Test(org.junit.Test)

Example 4 with PwdDecryptException

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);
}
Also used : PwdDecryptException(io.kylin.mdx.insight.common.PwdDecryptException) DecoderException(org.apache.commons.codec.DecoderException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PwdDecryptException(io.kylin.mdx.insight.common.PwdDecryptException)

Example 5 with PwdDecryptException

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 + "'");
    }
}
Also used : DataSourceResolver(mondrian.spi.DataSourceResolver) JndiDataSourceResolver(mondrian.spi.impl.JndiDataSourceResolver) PwdDecryptException(io.kylin.mdx.insight.common.PwdDecryptException) Properties(java.util.Properties) MondrianProperties(mondrian.olap.MondrianProperties) PwdDecryptException(io.kylin.mdx.insight.common.PwdDecryptException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException)

Aggregations

PwdDecryptException (io.kylin.mdx.insight.common.PwdDecryptException)11 SemanticException (io.kylin.mdx.insight.common.SemanticException)6 UserInfo (io.kylin.mdx.insight.core.entity.UserInfo)3 ConnectionInfo (io.kylin.mdx.insight.core.meta.ConnectionInfo)3 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 DecoderException (org.apache.commons.codec.DecoderException)2 MdxException (io.kylin.mdx.core.MdxException)1 DatasetEntity (io.kylin.mdx.insight.core.entity.DatasetEntity)1 KylinGenericModel (io.kylin.mdx.insight.core.model.generic.KylinGenericModel)1 KylinUserInfo (io.kylin.mdx.insight.core.model.generic.KylinUserInfo)1 Execution (io.kylin.mdx.insight.core.support.Execution)1 DatasetChangedSource (io.kylin.mdx.insight.core.sync.DatasetEventObject.DatasetChangedSource)1 DatasetDTO (io.kylin.mdx.insight.server.bean.dto.DatasetDTO)1 ProjectDatasetDTO (io.kylin.mdx.insight.server.bean.dto.ProjectDatasetDTO)1 SimpleDatasetDTO (io.kylin.mdx.insight.server.bean.dto.SimpleDatasetDTO)1 DatasetIdVO (io.kylin.mdx.insight.server.bean.vo.DatasetIdVO)1 CalculateMeasureValidateException (io.kylin.mdx.insight.server.exception.CalculateMeasureValidateException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1