Search in sources :

Example 6 with IdentityProvider

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"));
}
Also used : Role(io.gravitee.repository.management.model.Role) HashMap(java.util.HashMap) IdentityProvider(io.gravitee.repository.management.model.IdentityProvider) Test(org.junit.Test)

Example 7 with IdentityProvider

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());
}
Also used : IdentityProvider(io.gravitee.repository.management.model.IdentityProvider) Test(org.junit.Test)

Example 8 with IdentityProvider

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"));
}
Also used : HashMap(java.util.HashMap) IdentityProvider(io.gravitee.repository.management.model.IdentityProvider) Test(org.junit.Test)

Example 9 with IdentityProvider

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);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) IdentityProvider(io.gravitee.repository.management.model.IdentityProvider) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 10 with IdentityProvider

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);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) IdentityProvider(io.gravitee.repository.management.model.IdentityProvider) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Aggregations

IdentityProvider (io.gravitee.repository.management.model.IdentityProvider)10 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)4 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 Role (io.gravitee.repository.management.model.Role)1 IdentityProviderActivationService (io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService)1