use of io.gravitee.repository.management.model.IdentityProvider in project gravitee-management-rest-api by gravitee-io.
the class V3UpgraderServiceTest method shouldUpdateIdentityProvidersWithOrganizationRole.
@Test
public void shouldUpdateIdentityProvidersWithOrganizationRole() throws TechnicalException {
String[] roles = { "1:ADMIN", "2:USER" };
Map<String, String[]> roleMappings = new HashMap<>();
roleMappings.put("KEY", roles);
IdentityProvider idp = new IdentityProvider();
idp.setId("my-idp");
idp.setRoleMappings(roleMappings);
idp.setOrganizationId("DEFAULT");
when(identityProviderRepository.findAll()).thenReturn(Collections.singleton(idp));
when(roleRepository.findByScopeAndNameAndReferenceIdAndReferenceType(RoleScope.ORGANIZATION, "ADMIN", "DEFAULT", RoleReferenceType.ORGANIZATION)).thenReturn(Optional.of(new Role()));
service.convertIDPRoleMapping();
ArgumentCaptor<IdentityProvider> idpCaptor = ArgumentCaptor.forClass(IdentityProvider.class);
verify(roleRepository, times(1)).findByScopeAndNameAndReferenceIdAndReferenceType(any(), any(), any(), any());
verify(identityProviderRepository).update(idpCaptor.capture());
IdentityProvider updatedIdp = idpCaptor.getValue();
String[] newRoles = updatedIdp.getRoleMappings().get("KEY");
assertEquals(3, newRoles.length);
assertTrue(newRoles[0].equals("ORGANIZATION:ADMIN") || newRoles[0].equals("ENVIRONMENT:ADMIN") || newRoles[0].equals("ENVIRONMENT:USER"));
assertTrue(newRoles[1].equals("ORGANIZATION:ADMIN") || newRoles[1].equals("ENVIRONMENT:ADMIN") || newRoles[1].equals("ENVIRONMENT:USER"));
assertTrue(newRoles[2].equals("ORGANIZATION:ADMIN") || newRoles[2].equals("ENVIRONMENT:ADMIN") || newRoles[2].equals("ENVIRONMENT:USER"));
}
use of io.gravitee.repository.management.model.IdentityProvider in project gravitee-management-rest-api by gravitee-io.
the class V3UpgraderServiceTest method shouldDoNothingWithNoRoleMapping.
@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());
}
use of io.gravitee.repository.management.model.IdentityProvider in project gravitee-management-rest-api by gravitee-io.
the class V3UpgraderServiceTest method shouldUpdateIdentityProvidersWithoutOrganizationRole.
@Test
public void shouldUpdateIdentityProvidersWithoutOrganizationRole() throws TechnicalException {
String[] roles = { "1:ADMIN", "2:USER" };
Map<String, String[]> roleMappings = new HashMap<>();
roleMappings.put("KEY", roles);
IdentityProvider idp = new IdentityProvider();
idp.setId("my-idp");
idp.setRoleMappings(roleMappings);
idp.setOrganizationId("DEFAULT");
when(identityProviderRepository.findAll()).thenReturn(Collections.singleton(idp));
when(roleRepository.findByScopeAndNameAndReferenceIdAndReferenceType(RoleScope.ORGANIZATION, "ADMIN", "DEFAULT", RoleReferenceType.ORGANIZATION)).thenReturn(Optional.empty());
service.convertIDPRoleMapping();
ArgumentCaptor<IdentityProvider> idpCaptor = ArgumentCaptor.forClass(IdentityProvider.class);
verify(roleRepository, times(1)).findByScopeAndNameAndReferenceIdAndReferenceType(any(), any(), any(), any());
verify(identityProviderRepository).update(idpCaptor.capture());
IdentityProvider updatedIdp = idpCaptor.getValue();
String[] newRoles = updatedIdp.getRoleMappings().get("KEY");
assertEquals(2, newRoles.length);
assertTrue(newRoles[0].equals("ENVIRONMENT:ADMIN") || newRoles[0].equals("ENVIRONMENT:USER"));
assertTrue(newRoles[1].equals("ENVIRONMENT:ADMIN") || newRoles[1].equals("ENVIRONMENT:USER"));
}
use of io.gravitee.repository.management.model.IdentityProvider in project gravitee-management-rest-api by gravitee-io.
the class IdentityProviderServiceImpl method findById.
@Override
public IdentityProviderEntity findById(String id) {
try {
LOGGER.debug("Find identity provider by ID: {}", id);
Optional<IdentityProvider> identityProvider = identityProviderRepository.findById(id);
if (identityProvider.isPresent()) {
return convert(identityProvider.get());
}
throw new IdentityProviderNotFoundException(id);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to find an identity provider using its ID {}", id, ex);
throw new TechnicalManagementException("An error occurs while trying to delete an identity provider using its ID " + id, ex);
}
}
use of io.gravitee.repository.management.model.IdentityProvider in project gravitee-management-rest-api by gravitee-io.
the class IdentityProviderServiceImpl method delete.
@Override
public void delete(String id) {
try {
LOGGER.debug("Delete identity provider: {}", id);
Optional<IdentityProvider> identityProvider = identityProviderRepository.findById(id);
if (!identityProvider.isPresent()) {
throw new IdentityProviderNotFoundException(id);
}
identityProviderRepository.delete(id);
auditService.createOrganizationAuditLog(Collections.singletonMap(IDENTITY_PROVIDER, id), IdentityProvider.AuditEvent.IDENTITY_PROVIDER_DELETED, new Date(), identityProvider.get(), null);
identityProviderActivationService.deactivateIdpOnAllTargets(id);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to delete an identity provider using its ID {}", id, ex);
throw new TechnicalManagementException("An error occurs while trying to delete an identity provider using its ID " + id, ex);
}
}
Aggregations