Search in sources :

Example 1 with XXRangerMasterKey

use of org.apache.ranger.entity.XXRangerMasterKey in project ranger by apache.

the class RangerMasterKey method saveEncryptedMK.

private String saveEncryptedMK(String encryptedMasterKey, DaoManager daoManager) {
    if (logger.isDebugEnabled()) {
        logger.debug("==> RangerMasterKey.saveEncryptedMK()");
    }
    XXRangerMasterKey xxRangerMasterKey = new XXRangerMasterKey();
    xxRangerMasterKey.setCipher(MK_CIPHER);
    xxRangerMasterKey.setBitLength(MK_KeySize);
    xxRangerMasterKey.setMasterKey(encryptedMasterKey);
    try {
        if (daoManager != null) {
            RangerMasterKeyDao rangerKMSDao = new RangerMasterKeyDao(daoManager);
            if (rangerKMSDao.getAllCount() < 1) {
                XXRangerMasterKey rangerMasterKey = rangerKMSDao.create(xxRangerMasterKey);
                if (logger.isDebugEnabled()) {
                    logger.debug("<== RangerMasterKey.saveEncryptedMK()");
                }
                return rangerMasterKey.getId().toString();
            }
        }
    } catch (Exception e) {
        logger.error("Error while saving master key in Database!!! ", e);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== RangerMasterKey.saveEncryptedMK()");
    }
    return null;
}
Also used : XXRangerMasterKey(org.apache.ranger.entity.XXRangerMasterKey) RangerMasterKeyDao(org.apache.ranger.kms.dao.RangerMasterKeyDao) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with XXRangerMasterKey

use of org.apache.ranger.entity.XXRangerMasterKey in project ranger by apache.

the class RangerMasterKey method getEncryptedMK.

private List getEncryptedMK() {
    if (logger.isDebugEnabled()) {
        logger.debug("==> RangerMasterKey.getEncryptedMK()");
    }
    try {
        if (daoManager != null) {
            ArrayList ret = new ArrayList<>();
            RangerMasterKeyDao rangerKMSDao = new RangerMasterKeyDao(daoManager);
            List<XXRangerMasterKey> lstRangerMasterKey = rangerKMSDao.getAll();
            if (lstRangerMasterKey.size() < 1) {
                throw new Exception("No Master Key exists");
            } else if (lstRangerMasterKey.size() > 1) {
                throw new Exception("More than one Master Key exists");
            } else {
                XXRangerMasterKey rangerMasterKey = rangerKMSDao.getById(lstRangerMasterKey.get(0).getId());
                String masterKeyStr = rangerMasterKey.getMasterKey();
                if (masterKeyStr.contains(",")) {
                    getPasswordParam(masterKeyStr);
                    ret.add(Base64.decode(password));
                    ret.add(masterKeyStr);
                } else {
                    ret.add(Base64.decode(masterKeyStr));
                }
                if (logger.isDebugEnabled()) {
                    logger.debug("<== RangerMasterKey.getEncryptedMK()");
                }
                return ret;
            }
        }
    } catch (Exception e) {
        logger.error("Unable to retrieve Master Key from the database!!!", e);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("<== RangerMasterKey.getEncryptedMK()");
    }
    return null;
}
Also used : XXRangerMasterKey(org.apache.ranger.entity.XXRangerMasterKey) RangerMasterKeyDao(org.apache.ranger.kms.dao.RangerMasterKeyDao) ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 XXRangerMasterKey (org.apache.ranger.entity.XXRangerMasterKey)2 RangerMasterKeyDao (org.apache.ranger.kms.dao.RangerMasterKeyDao)2 ArrayList (java.util.ArrayList)1