use of org.apache.ranger.entity.XXServiceConfigMap in project ranger by apache.
the class RangerServiceService method getConfigsWithDecryptedPassword.
public Map<String, String> getConfigsWithDecryptedPassword(RangerService service) throws IOException {
Map<String, String> configs = service.getConfigs();
String pwd = configs.get(ServiceDBStore.CONFIG_KEY_PASSWORD);
if (!stringUtil.isEmpty(pwd) && ServiceDBStore.HIDDEN_PASSWORD_STR.equalsIgnoreCase(pwd)) {
XXServiceConfigMap pwdConfig = daoMgr.getXXServiceConfigMap().findByServiceAndConfigKey(service.getId(), ServiceDBStore.CONFIG_KEY_PASSWORD);
if (pwdConfig != null) {
String encryptedPwd = pwdConfig.getConfigvalue();
String decryptedPwd = "";
String[] crypt_algo_array = null;
if (encryptedPwd.contains(",")) {
crypt_algo_array = encryptedPwd.split(",");
}
if (crypt_algo_array != null && crypt_algo_array.length > 1) {
String cryptAlgo = null;
String encryptKey = null;
String salt = null;
int iterationCount = 0;
cryptAlgo = crypt_algo_array[0];
encryptKey = crypt_algo_array[1];
salt = crypt_algo_array[2];
iterationCount = Integer.parseInt(crypt_algo_array[3]);
String paddingString = cryptAlgo + "," + encryptKey + "," + salt + "," + iterationCount;
decryptedPwd = PasswordUtils.decryptPassword(encryptedPwd);
if (StringUtils.equalsIgnoreCase(paddingString + "," + PasswordUtils.encryptPassword(paddingString + "," + decryptedPwd), encryptedPwd)) {
configs.put(ServiceDBStore.CONFIG_KEY_PASSWORD, encryptedPwd);
}
} else {
encryptedPwd = pwdConfig.getConfigvalue();
decryptedPwd = PasswordUtils.decryptPassword(encryptedPwd);
if (StringUtils.equalsIgnoreCase(PasswordUtils.encryptPassword(decryptedPwd), encryptedPwd)) {
configs.put(ServiceDBStore.CONFIG_KEY_PASSWORD, encryptedPwd);
}
}
}
}
return configs;
}
use of org.apache.ranger.entity.XXServiceConfigMap in project ranger by apache.
the class RangerServiceWithAssignedIdService method populateViewBean.
@Override
protected RangerService populateViewBean(XXServiceWithAssignedId xService) {
RangerService vService = super.populateViewBean(xService);
HashMap<String, String> configs = new HashMap<String, String>();
List<XXServiceConfigMap> svcConfigMapList = daoMgr.getXXServiceConfigMap().findByServiceId(xService.getId());
for (XXServiceConfigMap svcConfMap : svcConfigMapList) {
configs.put(svcConfMap.getConfigkey(), svcConfMap.getConfigvalue());
}
vService.setConfigs(configs);
return vService;
}
use of org.apache.ranger.entity.XXServiceConfigMap in project ranger by apache.
the class ServiceDBStore method createService.
@Override
public RangerService createService(RangerService service) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceDBStore.createService(" + service + ")");
}
if (service == null) {
throw restErrorUtil.createRESTException("Service object cannot be null.", MessageEnums.ERROR_CREATING_OBJECT);
}
boolean createDefaultPolicy = true;
Map<String, String> configs = service.getConfigs();
Map<String, String> validConfigs = validateRequiredConfigParams(service, configs);
if (validConfigs == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ConfigParams cannot be null, ServiceDBStore.createService(" + service + ")");
}
throw restErrorUtil.createRESTException("ConfigParams cannot be null.", MessageEnums.ERROR_CREATING_OBJECT);
}
// While creating, value of version should be 1.
service.setVersion(Long.valueOf(1));
service.setTagVersion(Long.valueOf(1));
if (populateExistingBaseFields) {
svcServiceWithAssignedId.setPopulateExistingBaseFields(true);
daoMgr.getXXService().setIdentityInsert(true);
service = svcServiceWithAssignedId.create(service);
daoMgr.getXXService().setIdentityInsert(false);
daoMgr.getXXService().updateSequence();
svcServiceWithAssignedId.setPopulateExistingBaseFields(false);
createDefaultPolicy = false;
} else {
service = svcService.create(service);
}
XXService xCreatedService = daoMgr.getXXService().getById(service.getId());
VXUser vXUser = null;
XXServiceConfigMapDao xConfMapDao = daoMgr.getXXServiceConfigMap();
for (Entry<String, String> configMap : validConfigs.entrySet()) {
String configKey = configMap.getKey();
String configValue = configMap.getValue();
if (StringUtils.equalsIgnoreCase(configKey, "username")) {
String userName = stringUtil.getValidUserName(configValue);
XXUser xxUser = daoMgr.getXXUser().findByUserName(userName);
if (xxUser != null) {
vXUser = xUserService.populateViewBean(xxUser);
} else {
UserSessionBase usb = ContextUtil.getCurrentUserSession();
if (usb != null && !usb.isUserAdmin() && !usb.isSpnegoEnabled()) {
throw restErrorUtil.createRESTException("User does not exist with given username: [" + userName + "] please use existing user", MessageEnums.OPER_NO_PERMISSION);
}
vXUser = xUserMgr.createServiceConfigUser(userName);
}
}
if (StringUtils.equalsIgnoreCase(configKey, CONFIG_KEY_PASSWORD)) {
String cryptConfigString = CRYPT_ALGO + "," + ENCRYPT_KEY + "," + SALT + "," + ITERATION_COUNT + "," + configValue;
String encryptedPwd = PasswordUtils.encryptPassword(cryptConfigString);
encryptedPwd = CRYPT_ALGO + "," + ENCRYPT_KEY + "," + SALT + "," + ITERATION_COUNT + "," + encryptedPwd;
String decryptedPwd = PasswordUtils.decryptPassword(encryptedPwd);
if (StringUtils.equals(decryptedPwd, configValue)) {
configValue = encryptedPwd;
}
}
XXServiceConfigMap xConfMap = new XXServiceConfigMap();
xConfMap = rangerAuditFields.populateAuditFields(xConfMap, xCreatedService);
xConfMap.setServiceId(xCreatedService.getId());
xConfMap.setConfigkey(configKey);
xConfMap.setConfigvalue(configValue);
xConfMapDao.create(xConfMap);
}
if (LOG.isDebugEnabled()) {
LOG.debug("vXUser:[" + vXUser + "]");
}
RangerService createdService = svcService.getPopulatedViewObject(xCreatedService);
if (createdService == null) {
throw restErrorUtil.createRESTException("Could not create service - Internal error ", MessageEnums.ERROR_CREATING_OBJECT);
}
dataHistService.createObjectDataHistory(createdService, RangerDataHistService.ACTION_CREATE);
List<XXTrxLog> trxLogList = svcService.getTransactionLog(createdService, RangerServiceService.OPERATION_CREATE_CONTEXT);
bizUtil.createTrxLog(trxLogList);
if (createDefaultPolicy) {
createDefaultPolicies(createdService);
}
return createdService;
}
use of org.apache.ranger.entity.XXServiceConfigMap in project ranger by apache.
the class RangerServiceService method populateViewBean.
@Override
protected RangerService populateViewBean(XXService xService) {
RangerService vService = super.populateViewBean(xService);
HashMap<String, String> configs = new HashMap<String, String>();
List<XXServiceConfigMap> svcConfigMapList = daoMgr.getXXServiceConfigMap().findByServiceId(xService.getId());
for (XXServiceConfigMap svcConfMap : svcConfigMapList) {
String configValue = svcConfMap.getConfigvalue();
if (StringUtils.equalsIgnoreCase(svcConfMap.getConfigkey(), ServiceDBStore.CONFIG_KEY_PASSWORD)) {
configValue = ServiceDBStore.HIDDEN_PASSWORD_STR;
}
configs.put(svcConfMap.getConfigkey(), configValue);
}
vService.setConfigs(configs);
return vService;
}
use of org.apache.ranger.entity.XXServiceConfigMap in project ranger by apache.
the class TestRangerServiceService method test4GetPopulatedViewObject.
@Test
public void test4GetPopulatedViewObject() {
XXServiceConfigMapDao xServiceConfigMapDao = Mockito.mock(XXServiceConfigMapDao.class);
XXPortalUserDao xPortalUserDao = Mockito.mock(XXPortalUserDao.class);
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXService xService = xService();
String name = "fdfdfds";
List<XXServiceConfigMap> svcConfigMapList = new ArrayList<XXServiceConfigMap>();
XXServiceConfigMap xConfMap = new XXServiceConfigMap();
xConfMap.setAddedByUserId(null);
xConfMap.setConfigkey(name);
xConfMap.setConfigvalue(name);
xConfMap.setCreateTime(new Date());
xConfMap.setServiceId(null);
xConfMap.setUpdatedByUserId(null);
xConfMap.setUpdateTime(new Date());
svcConfigMapList.add(xConfMap);
XXPortalUser tUser = new XXPortalUser();
tUser.setAddedByUserId(userId);
tUser.setCreateTime(new Date());
tUser.setEmailAddress("test@gmail.com");
tUser.setFirstName(name);
tUser.setId(userId);
tUser.setLastName(name);
XXServiceDef xServiceDef = new XXServiceDef();
xServiceDef.setAddedByUserId(userId);
xServiceDef.setCreateTime(new Date());
xServiceDef.setDescription("test");
xServiceDef.setGuid("1427365526516_835_0");
xServiceDef.setId(userId);
XXServiceVersionInfoDao xServiceVersionInfoDao = Mockito.mock(XXServiceVersionInfoDao.class);
XXServiceVersionInfo serviceVersionInfo = new XXServiceVersionInfo();
serviceVersionInfo.setServiceId(xService.getId());
serviceVersionInfo.setPolicyVersion(xService.getPolicyVersion());
serviceVersionInfo.setPolicyUpdateTime(xService.getPolicyUpdateTime());
serviceVersionInfo.setTagVersion(xService.getTagVersion());
serviceVersionInfo.setTagUpdateTime(xService.getTagUpdateTime());
Mockito.when(daoManager.getXXServiceVersionInfo()).thenReturn(xServiceVersionInfoDao);
Mockito.when(xServiceVersionInfoDao.findByServiceId(xService.getId())).thenReturn(serviceVersionInfo);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(xPortalUserDao);
Mockito.when(xPortalUserDao.getById(userId)).thenReturn(tUser);
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn(xServiceDef);
Mockito.when(daoManager.getXXServiceConfigMap()).thenReturn(xServiceConfigMapDao);
Mockito.when(xServiceConfigMapDao.findByServiceId(xService.getId())).thenReturn(svcConfigMapList);
RangerService dbService = serviceService.getPopulatedViewObject(xService);
Assert.assertNotNull(dbService);
Assert.assertEquals(userId, dbService.getId());
Assert.assertEquals(xService.getAddedByUserId(), dbService.getId());
Assert.assertEquals(xService.getId(), dbService.getId());
Assert.assertEquals(xService.getDescription(), dbService.getDescription());
Assert.assertEquals(xService.getGuid(), dbService.getGuid());
Assert.assertEquals(xService.getName(), dbService.getName());
Assert.assertEquals(xService.getPolicyUpdateTime(), dbService.getPolicyUpdateTime());
Assert.assertEquals(xService.getPolicyVersion(), dbService.getPolicyVersion());
Assert.assertEquals(xService.getVersion(), dbService.getVersion());
Mockito.verify(daoManager).getXXServiceDef();
Mockito.verify(daoManager).getXXServiceConfigMap();
}
Aggregations