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;
}
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;
}
Aggregations