@Test public void testAzureWithRazNoServicePrincipals() { GeneralClusterConfigs generalClusterConfigs = new GeneralClusterConfigs(); generalClusterConfigs.setEnableRangerRaz(true); TemplatePreparationObject preparationObject = TemplatePreparationObject.Builder.builder() .withCloudPlatform(CloudPlatform.AZURE) .withServicePrincipals(Collections.emptyMap()) .withGeneralClusterConfigs(generalClusterConfigs) .build(); List<ApiClusterTemplateConfig> serviceConfigs = underTest.getRoleConfigs(RANGER_USERSYNC, preparationObject); assertEquals(3, serviceConfigs.size()); assertEquals("conf/ranger-ugsync-site.xml_role_safety_valve", serviceConfigs.get(0).getName()); assertEquals("<property><name>ranger.usersync.unix.backend</name><value>nss</value></property>", serviceConfigs.get(0).getValue()); assertEquals("ranger.usersync.group.based.role.assignment.rules", serviceConfigs.get(1).getName()); assertEquals("&ROLE_SYS_ADMIN:g:mockAdmin", serviceConfigs.get(1).getValue()); assertEquals("ranger_usersync_azure_user_mapping", serviceConfigs.get(2).getName()); assertEquals("", serviceConfigs.get(2).getValue()); }
@Override public List<ApiClusterTemplateConfig> getRoleConfigs(String roleType, TemplatePreparationObject source) { String adminGroup = virtualGroupService.getVirtualGroup(source.getVirtualGroupRequest(), UmsRight.RANGER_ADMIN.getRight()); if (CloudPlatform.AZURE.equals(source.getCloudPlatform()) && source.getGeneralClusterConfigs().isEnableRangerRaz() && source.getServicePrincipals() != null) { String servicePrincipals = getServicePrincipalsString(source); return List.of( config(ROLE_SAFETY_VALVE, ConfigUtils.getSafetyValveProperty(RANGER_USERSYNC_UNIX_BACKEND, "nss")), config(ROLE_ASSIGNMENT_RULES, "&ROLE_SYS_ADMIN:g:" + adminGroup), config(RANGER_USERSYNC_AZURE_MAPPING, servicePrincipals)); } else { return List.of( config(ROLE_SAFETY_VALVE, ConfigUtils.getSafetyValveProperty(RANGER_USERSYNC_UNIX_BACKEND, "nss")), config(ROLE_ASSIGNMENT_RULES, "&ROLE_SYS_ADMIN:g:" + adminGroup)); } }
RangerUserSyncRoleConfigProvider extends AbstractRoleConfigProvider { @Override public List<ApiClusterTemplateConfig> getRoleConfigs(String roleType, TemplatePreparationObject source) { String adminGroup = virtualGroupService.getVirtualGroup(source.getVirtualGroupRequest(), UmsRight.RANGER_ADMIN.getRight()); if (CloudPlatform.AZURE.equals(source.getCloudPlatform()) && source.getGeneralClusterConfigs().isEnableRangerRaz() && source.getServicePrincipals() != null) { String servicePrincipals = getServicePrincipalsString(source); return List.of( config(ROLE_SAFETY_VALVE, ConfigUtils.getSafetyValveProperty(RANGER_USERSYNC_UNIX_BACKEND, "nss")), config(ROLE_ASSIGNMENT_RULES, "&ROLE_SYS_ADMIN:g:" + adminGroup), config(RANGER_USERSYNC_AZURE_MAPPING, servicePrincipals)); } else { return List.of( config(ROLE_SAFETY_VALVE, ConfigUtils.getSafetyValveProperty(RANGER_USERSYNC_UNIX_BACKEND, "nss")), config(ROLE_ASSIGNMENT_RULES, "&ROLE_SYS_ADMIN:g:" + adminGroup)); } } }
RangerUserSyncRoleConfigProvider extends AbstractRoleConfigProvider { @Override public List<ApiClusterTemplateConfig> getRoleConfigs(String roleType, TemplatePreparationObject source) { String adminGroup = virtualGroupService.getVirtualGroup(source.getVirtualGroupRequest(), UmsRight.RANGER_ADMIN.getRight()); if (CloudPlatform.AZURE.equals(source.getCloudPlatform()) && source.getGeneralClusterConfigs().isEnableRangerRaz() && source.getServicePrincipals() != null) { String servicePrincipals = getServicePrincipalsString(source); return List.of( config(ROLE_SAFETY_VALVE, ConfigUtils.getSafetyValveProperty(RANGER_USERSYNC_UNIX_BACKEND, "nss")), config(ROLE_ASSIGNMENT_RULES, "&ROLE_SYS_ADMIN:g:" + adminGroup), config(RANGER_USERSYNC_AZURE_MAPPING, servicePrincipals)); } else { return List.of( config(ROLE_SAFETY_VALVE, ConfigUtils.getSafetyValveProperty(RANGER_USERSYNC_UNIX_BACKEND, "nss")), config(ROLE_ASSIGNMENT_RULES, "&ROLE_SYS_ADMIN:g:" + adminGroup)); } }  }
RangerUserSyncRoleConfigProvider extends AbstractRoleConfigProvider { @Override public List<ApiClusterTemplateConfig> getRoleConfigs(String roleType, TemplatePreparationObject source) { String adminGroup = virtualGroupService.getVirtualGroup(source.getVirtualGroupRequest(), UmsRight.RANGER_ADMIN.getRight()); if (CloudPlatform.AZURE.equals(source.getCloudPlatform()) && source.getGeneralClusterConfigs().isEnableRangerRaz() && source.getServicePrincipals() != null) { String servicePrincipals = getServicePrincipalsString(source); return List.of( config(ROLE_SAFETY_VALVE, ConfigUtils.getSafetyValveProperty(RANGER_USERSYNC_UNIX_BACKEND, "nss")), config(ROLE_ASSIGNMENT_RULES, "&ROLE_SYS_ADMIN:g:" + adminGroup), config(RANGER_USERSYNC_AZURE_MAPPING, servicePrincipals)); } else { return List.of( config(ROLE_SAFETY_VALVE, ConfigUtils.getSafetyValveProperty(RANGER_USERSYNC_UNIX_BACKEND, "nss")), config(ROLE_ASSIGNMENT_RULES, "&ROLE_SYS_ADMIN:g:" + adminGroup)); } }  @Override List<ApiClusterTemplateConfig> getRoleConfigs(String roleType, TemplatePreparationObject source); @Override String getServiceType(); @Override List<String> getRoleTypes(); @Override boolean isConfigurationNeeded(CmTemplateProcessor cmTemplateProcessor, TemplatePreparationObject source); }
RangerUserSyncRoleConfigProvider extends AbstractRoleConfigProvider { @Override public List<ApiClusterTemplateConfig> getRoleConfigs(String roleType, TemplatePreparationObject source) { String adminGroup = virtualGroupService.getVirtualGroup(source.getVirtualGroupRequest(), UmsRight.RANGER_ADMIN.getRight()); if (CloudPlatform.AZURE.equals(source.getCloudPlatform()) && source.getGeneralClusterConfigs().isEnableRangerRaz() && source.getServicePrincipals() != null) { String servicePrincipals = getServicePrincipalsString(source); return List.of( config(ROLE_SAFETY_VALVE, ConfigUtils.getSafetyValveProperty(RANGER_USERSYNC_UNIX_BACKEND, "nss")), config(ROLE_ASSIGNMENT_RULES, "&ROLE_SYS_ADMIN:g:" + adminGroup), config(RANGER_USERSYNC_AZURE_MAPPING, servicePrincipals)); } else { return List.of( config(ROLE_SAFETY_VALVE, ConfigUtils.getSafetyValveProperty(RANGER_USERSYNC_UNIX_BACKEND, "nss")), config(ROLE_ASSIGNMENT_RULES, "&ROLE_SYS_ADMIN:g:" + adminGroup)); } }  @Override List<ApiClusterTemplateConfig> getRoleConfigs(String roleType, TemplatePreparationObject source); @Override String getServiceType(); @Override List<String> getRoleTypes(); @Override boolean isConfigurationNeeded(CmTemplateProcessor cmTemplateProcessor, TemplatePreparationObject source);  }