@Test public void shouldDoNothingWithNoRoleMapping() throws TechnicalException { IdentityProvider idp = new IdentityProvider(); idp.setId("my-idp"); idp.setOrganizationId("DEFAULT"); when(identityProviderRepository.findAll()).thenReturn(Collections.singleton(idp)); service.convertIDPRoleMapping(); verify(roleRepository, never()).findByScopeAndNameAndReferenceIdAndReferenceType(any(), any(), any(), any()); verify(identityProviderRepository, never()).update(any()); }
public void convertIDPRoleMapping() { try { Set<IdentityProvider> allIdps = identityProviderRepository.findAll(); logger.debug("{} Idp found", allIdps.size()); for (IdentityProvider idp : allIdps) { boolean idpHasBeenModified = false; Map<String, String[]> roleMappings = idp.getRoleMappings(); if (roleMappings != null) { logger.debug("Idp '{}' has {} roleMappings", idp.getId(), roleMappings.size()); for (Entry<String, String[]> entry : roleMappings.entrySet()) { String[] roles = entry.getValue(); if (roles != null) { logger.debug("Idp '{}' - RoleMapping with condition '{}' has {} roles", idp.getId(), entry.getKey(), roles.length); List<String> newRoles = new ArrayList<>(roles.length); boolean entryHasBeenModified = false; for (String role : roles) { String[] splittedRole = role.split(":"); if ("1".equals(splittedRole[0])) { Optional<Role> existingOrgaRoleWithSameName = roleRepository.findByScopeAndNameAndReferenceIdAndReferenceType(RoleScope.ORGANIZATION, splittedRole[1], "DEFAULT", RoleReferenceType.ORGANIZATION); if (existingOrgaRoleWithSameName.isPresent()) { newRoles.add("ORGANIZATION:" + splittedRole[1]); } newRoles.add("ENVIRONMENT:" + splittedRole[1]); entryHasBeenModified = true; } else if ("2".equals(splittedRole[0])) { newRoles.add("ENVIRONMENT:" + splittedRole[1]); entryHasBeenModified = true; } } if (entryHasBeenModified) { entry.setValue(newRoles.toArray(new String[newRoles.size()])); idpHasBeenModified = true; } } else { logger.debug("Idp '{}' - RoleMapping with condition '{}' has no roles", idp.getId(), entry.getKey()); } } } if (idpHasBeenModified) { identityProviderRepository.update(idp); logger.info("Idp '{}' has been updated", idp.getId()); } else { logger.info("Idp '{}' has not been updated", idp.getId()); } } } catch (TechnicalException ex) { logger.error("An error occurs while trying to retrieve all identity providers", ex); throw new TechnicalManagementException( "An error occurs while trying to retrieve identity providers", ex); } }
V3UpgraderService extends AbstractService { public void convertIDPRoleMapping() { try { Set<IdentityProvider> allIdps = identityProviderRepository.findAll(); logger.debug("{} Idp found", allIdps.size()); for (IdentityProvider idp : allIdps) { boolean idpHasBeenModified = false; Map<String, String[]> roleMappings = idp.getRoleMappings(); if (roleMappings != null) { logger.debug("Idp '{}' has {} roleMappings", idp.getId(), roleMappings.size()); for (Entry<String, String[]> entry : roleMappings.entrySet()) { String[] roles = entry.getValue(); if (roles != null) { logger.debug("Idp '{}' - RoleMapping with condition '{}' has {} roles", idp.getId(), entry.getKey(), roles.length); List<String> newRoles = new ArrayList<>(roles.length); boolean entryHasBeenModified = false; for (String role : roles) { String[] splittedRole = role.split(":"); if ("1".equals(splittedRole[0])) { Optional<Role> existingOrgaRoleWithSameName = roleRepository.findByScopeAndNameAndReferenceIdAndReferenceType(RoleScope.ORGANIZATION, splittedRole[1], "DEFAULT", RoleReferenceType.ORGANIZATION); if (existingOrgaRoleWithSameName.isPresent()) { newRoles.add("ORGANIZATION:" + splittedRole[1]); } newRoles.add("ENVIRONMENT:" + splittedRole[1]); entryHasBeenModified = true; } else if ("2".equals(splittedRole[0])) { newRoles.add("ENVIRONMENT:" + splittedRole[1]); entryHasBeenModified = true; } } if (entryHasBeenModified) { entry.setValue(newRoles.toArray(new String[newRoles.size()])); idpHasBeenModified = true; } } else { logger.debug("Idp '{}' - RoleMapping with condition '{}' has no roles", idp.getId(), entry.getKey()); } } } if (idpHasBeenModified) { identityProviderRepository.update(idp); logger.info("Idp '{}' has been updated", idp.getId()); } else { logger.info("Idp '{}' has not been updated", idp.getId()); } } } catch (TechnicalException ex) { logger.error("An error occurs while trying to retrieve all identity providers", ex); throw new TechnicalManagementException( "An error occurs while trying to retrieve identity providers", ex); } } }
V3UpgraderService extends AbstractService { public void convertIDPRoleMapping() { try { Set<IdentityProvider> allIdps = identityProviderRepository.findAll(); logger.debug("{} Idp found", allIdps.size()); for (IdentityProvider idp : allIdps) { boolean idpHasBeenModified = false; Map<String, String[]> roleMappings = idp.getRoleMappings(); if (roleMappings != null) { logger.debug("Idp '{}' has {} roleMappings", idp.getId(), roleMappings.size()); for (Entry<String, String[]> entry : roleMappings.entrySet()) { String[] roles = entry.getValue(); if (roles != null) { logger.debug("Idp '{}' - RoleMapping with condition '{}' has {} roles", idp.getId(), entry.getKey(), roles.length); List<String> newRoles = new ArrayList<>(roles.length); boolean entryHasBeenModified = false; for (String role : roles) { String[] splittedRole = role.split(":"); if ("1".equals(splittedRole[0])) { Optional<Role> existingOrgaRoleWithSameName = roleRepository.findByScopeAndNameAndReferenceIdAndReferenceType(RoleScope.ORGANIZATION, splittedRole[1], "DEFAULT", RoleReferenceType.ORGANIZATION); if (existingOrgaRoleWithSameName.isPresent()) { newRoles.add("ORGANIZATION:" + splittedRole[1]); } newRoles.add("ENVIRONMENT:" + splittedRole[1]); entryHasBeenModified = true; } else if ("2".equals(splittedRole[0])) { newRoles.add("ENVIRONMENT:" + splittedRole[1]); entryHasBeenModified = true; } } if (entryHasBeenModified) { entry.setValue(newRoles.toArray(new String[newRoles.size()])); idpHasBeenModified = true; } } else { logger.debug("Idp '{}' - RoleMapping with condition '{}' has no roles", idp.getId(), entry.getKey()); } } } if (idpHasBeenModified) { identityProviderRepository.update(idp); logger.info("Idp '{}' has been updated", idp.getId()); } else { logger.info("Idp '{}' has not been updated", idp.getId()); } } } catch (TechnicalException ex) { logger.error("An error occurs while trying to retrieve all identity providers", ex); throw new TechnicalManagementException( "An error occurs while trying to retrieve identity providers", ex); } }  }
V3UpgraderService extends AbstractService { public void convertIDPRoleMapping() { try { Set<IdentityProvider> allIdps = identityProviderRepository.findAll(); logger.debug("{} Idp found", allIdps.size()); for (IdentityProvider idp : allIdps) { boolean idpHasBeenModified = false; Map<String, String[]> roleMappings = idp.getRoleMappings(); if (roleMappings != null) { logger.debug("Idp '{}' has {} roleMappings", idp.getId(), roleMappings.size()); for (Entry<String, String[]> entry : roleMappings.entrySet()) { String[] roles = entry.getValue(); if (roles != null) { logger.debug("Idp '{}' - RoleMapping with condition '{}' has {} roles", idp.getId(), entry.getKey(), roles.length); List<String> newRoles = new ArrayList<>(roles.length); boolean entryHasBeenModified = false; for (String role : roles) { String[] splittedRole = role.split(":"); if ("1".equals(splittedRole[0])) { Optional<Role> existingOrgaRoleWithSameName = roleRepository.findByScopeAndNameAndReferenceIdAndReferenceType(RoleScope.ORGANIZATION, splittedRole[1], "DEFAULT", RoleReferenceType.ORGANIZATION); if (existingOrgaRoleWithSameName.isPresent()) { newRoles.add("ORGANIZATION:" + splittedRole[1]); } newRoles.add("ENVIRONMENT:" + splittedRole[1]); entryHasBeenModified = true; } else if ("2".equals(splittedRole[0])) { newRoles.add("ENVIRONMENT:" + splittedRole[1]); entryHasBeenModified = true; } } if (entryHasBeenModified) { entry.setValue(newRoles.toArray(new String[newRoles.size()])); idpHasBeenModified = true; } } else { logger.debug("Idp '{}' - RoleMapping with condition '{}' has no roles", idp.getId(), entry.getKey()); } } } if (idpHasBeenModified) { identityProviderRepository.update(idp); logger.info("Idp '{}' has been updated", idp.getId()); } else { logger.info("Idp '{}' has not been updated", idp.getId()); } } } catch (TechnicalException ex) { logger.error("An error occurs while trying to retrieve all identity providers", ex); throw new TechnicalManagementException( "An error occurs while trying to retrieve identity providers", ex); } }  void convertIDPRoleMapping(); void moveIdpPermission(); }
V3UpgraderService extends AbstractService { public void convertIDPRoleMapping() { try { Set<IdentityProvider> allIdps = identityProviderRepository.findAll(); logger.debug("{} Idp found", allIdps.size()); for (IdentityProvider idp : allIdps) { boolean idpHasBeenModified = false; Map<String, String[]> roleMappings = idp.getRoleMappings(); if (roleMappings != null) { logger.debug("Idp '{}' has {} roleMappings", idp.getId(), roleMappings.size()); for (Entry<String, String[]> entry : roleMappings.entrySet()) { String[] roles = entry.getValue(); if (roles != null) { logger.debug("Idp '{}' - RoleMapping with condition '{}' has {} roles", idp.getId(), entry.getKey(), roles.length); List<String> newRoles = new ArrayList<>(roles.length); boolean entryHasBeenModified = false; for (String role : roles) { String[] splittedRole = role.split(":"); if ("1".equals(splittedRole[0])) { Optional<Role> existingOrgaRoleWithSameName = roleRepository.findByScopeAndNameAndReferenceIdAndReferenceType(RoleScope.ORGANIZATION, splittedRole[1], "DEFAULT", RoleReferenceType.ORGANIZATION); if (existingOrgaRoleWithSameName.isPresent()) { newRoles.add("ORGANIZATION:" + splittedRole[1]); } newRoles.add("ENVIRONMENT:" + splittedRole[1]); entryHasBeenModified = true; } else if ("2".equals(splittedRole[0])) { newRoles.add("ENVIRONMENT:" + splittedRole[1]); entryHasBeenModified = true; } } if (entryHasBeenModified) { entry.setValue(newRoles.toArray(new String[newRoles.size()])); idpHasBeenModified = true; } } else { logger.debug("Idp '{}' - RoleMapping with condition '{}' has no roles", idp.getId(), entry.getKey()); } } } if (idpHasBeenModified) { identityProviderRepository.update(idp); logger.info("Idp '{}' has been updated", idp.getId()); } else { logger.info("Idp '{}' has not been updated", idp.getId()); } } } catch (TechnicalException ex) { logger.error("An error occurs while trying to retrieve all identity providers", ex); throw new TechnicalManagementException( "An error occurs while trying to retrieve identity providers", ex); } }  void convertIDPRoleMapping(); void moveIdpPermission();  }