Search in sources :

Example 6 with IdentityProviderActivation

use of io.gravitee.repository.management.model.IdentityProviderActivation in project gravitee-management-rest-api by gravitee-io.

the class IdentityProviderActivationServiceTest method shouldFindAllByIdentityProviderId.

@Test
public void shouldFindAllByIdentityProviderId() throws TechnicalException {
    // Given
    final Date now = new Date();
    IdentityProviderActivation ipa = new IdentityProviderActivation();
    ipa.setIdentityProviderId(IDENTITY_PROVIDER_ID);
    ipa.setReferenceId(TARGET_REFERENCE_ID);
    ipa.setReferenceType(TARGET_REFERENCE_TYPE);
    ipa.setCreatedAt(now);
    IdentityProviderActivation anotherIpa = new IdentityProviderActivation();
    anotherIpa.setIdentityProviderId(IDENTITY_PROVIDER_ID);
    anotherIpa.setReferenceId(ANOTHER_TARGET_REFERENCE_ID);
    anotherIpa.setReferenceType(ANOTHER_TARGET_REFERENCE_TYPE);
    anotherIpa.setCreatedAt(now);
    doReturn(newSet(ipa, anotherIpa)).when(identityProviderActivationRepository).findAllByIdentityProviderId(IDENTITY_PROVIDER_ID);
    // When
    Set<IdentityProviderActivationEntity> foundIdentityProviders = this.identityProviderActivationService.findAllByIdentityProviderId(IDENTITY_PROVIDER_ID);
    // Then
    assertNotNull(foundIdentityProviders);
    assertEquals(2, foundIdentityProviders.size());
    verify(identityProviderActivationRepository).findAllByIdentityProviderId(IDENTITY_PROVIDER_ID);
}
Also used : IdentityProviderActivation(io.gravitee.repository.management.model.IdentityProviderActivation) IdentityProviderActivationEntity(io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity) Date(java.util.Date) Test(org.junit.Test)

Example 7 with IdentityProviderActivation

use of io.gravitee.repository.management.model.IdentityProviderActivation in project gravitee-management-rest-api by gravitee-io.

the class IdentityProviderActivationServiceTest method shouldRemoveIdpsFromTarget.

@Test
public void shouldRemoveIdpsFromTarget() throws TechnicalException {
    // Given
    final Date now = new Date();
    IdentityProviderActivation ipaToRemove = new IdentityProviderActivation();
    ipaToRemove.setIdentityProviderId(IDENTITY_PROVIDER_ID);
    ipaToRemove.setReferenceId(TARGET_REFERENCE_ID);
    ipaToRemove.setReferenceType(TARGET_REFERENCE_TYPE);
    ipaToRemove.setCreatedAt(now);
    IdentityProviderActivation anotherIpaToRemove = new IdentityProviderActivation();
    anotherIpaToRemove.setIdentityProviderId(ANOTHER_IDENTITY_PROVIDER_ID);
    anotherIpaToRemove.setReferenceId(TARGET_REFERENCE_ID);
    anotherIpaToRemove.setReferenceType(TARGET_REFERENCE_TYPE);
    anotherIpaToRemove.setCreatedAt(now);
    doReturn(Optional.of(ipaToRemove)).when(identityProviderActivationRepository).findById(IDENTITY_PROVIDER_ID, TARGET_REFERENCE_ID, TARGET_REFERENCE_TYPE);
    doReturn(Optional.of(anotherIpaToRemove)).when(identityProviderActivationRepository).findById(ANOTHER_IDENTITY_PROVIDER_ID, TARGET_REFERENCE_ID, TARGET_REFERENCE_TYPE);
    // When
    this.identityProviderActivationService.removeIdpsFromTarget(new ActivationTarget(TARGET_REFERENCE_ID, io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationReferenceType.valueOf(TARGET_REFERENCE_TYPE.name())), IDENTITY_PROVIDER_ID, ANOTHER_IDENTITY_PROVIDER_ID);
    // Then
    verify(identityProviderActivationRepository).findById(IDENTITY_PROVIDER_ID, TARGET_REFERENCE_ID, TARGET_REFERENCE_TYPE);
    verify(identityProviderActivationRepository).findById(ANOTHER_IDENTITY_PROVIDER_ID, TARGET_REFERENCE_ID, TARGET_REFERENCE_TYPE);
    verify(identityProviderActivationRepository).delete(IDENTITY_PROVIDER_ID, TARGET_REFERENCE_ID, TARGET_REFERENCE_TYPE);
    verify(identityProviderActivationRepository).delete(ANOTHER_IDENTITY_PROVIDER_ID, TARGET_REFERENCE_ID, TARGET_REFERENCE_TYPE);
    verify(auditService).createAuditLog(eq(Audit.AuditReferenceType.valueOf(TARGET_REFERENCE_TYPE.name())), eq(TARGET_REFERENCE_ID), any(), eq(IdentityProvider.AuditEvent.IDENTITY_PROVIDER_DEACTIVATED), any(), eq(ipaToRemove), isNull());
    verify(auditService).createAuditLog(eq(Audit.AuditReferenceType.valueOf(TARGET_REFERENCE_TYPE.name())), eq(TARGET_REFERENCE_ID), any(), eq(IdentityProvider.AuditEvent.IDENTITY_PROVIDER_DEACTIVATED), any(), eq(anotherIpaToRemove), isNull());
}
Also used : IdentityProviderActivation(io.gravitee.repository.management.model.IdentityProviderActivation) ActivationTarget(io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget) Date(java.util.Date) Test(org.junit.Test)

Example 8 with IdentityProviderActivation

use of io.gravitee.repository.management.model.IdentityProviderActivation in project gravitee-management-rest-api by gravitee-io.

the class IdentityProviderActivationServiceTest method shouldActivateIdpOnTargets.

@Test
public void shouldActivateIdpOnTargets() throws TechnicalException {
    // Given
    final Date now = new Date();
    IdentityProviderActivation createdIPA = new IdentityProviderActivation();
    createdIPA.setIdentityProviderId(IDENTITY_PROVIDER_ID);
    createdIPA.setReferenceId(TARGET_REFERENCE_ID);
    createdIPA.setReferenceType(TARGET_REFERENCE_TYPE);
    createdIPA.setCreatedAt(now);
    IdentityProviderActivation anotherCreatedIPA = new IdentityProviderActivation();
    anotherCreatedIPA.setIdentityProviderId(IDENTITY_PROVIDER_ID);
    anotherCreatedIPA.setReferenceId(ANOTHER_TARGET_REFERENCE_ID);
    anotherCreatedIPA.setReferenceType(ANOTHER_TARGET_REFERENCE_TYPE);
    anotherCreatedIPA.setCreatedAt(now);
    doReturn(createdIPA).when(identityProviderActivationRepository).create(argThat((IdentityProviderActivation ipa) -> IDENTITY_PROVIDER_ID.equals(ipa.getIdentityProviderId()) && TARGET_REFERENCE_ID.equals(ipa.getReferenceId()) && TARGET_REFERENCE_TYPE.equals(ipa.getReferenceType())));
    doReturn(anotherCreatedIPA).when(identityProviderActivationRepository).create(argThat((IdentityProviderActivation ipa) -> IDENTITY_PROVIDER_ID.equals(ipa.getIdentityProviderId()) && ANOTHER_TARGET_REFERENCE_ID.equals(ipa.getReferenceId()) && ANOTHER_TARGET_REFERENCE_TYPE.equals(ipa.getReferenceType())));
    // When
    Set<IdentityProviderActivationEntity> activatedIdentityProviders = this.identityProviderActivationService.activateIdpOnTargets(IDENTITY_PROVIDER_ID, new ActivationTarget(TARGET_REFERENCE_ID, io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationReferenceType.valueOf(TARGET_REFERENCE_TYPE.name())), new ActivationTarget(ANOTHER_TARGET_REFERENCE_ID, io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationReferenceType.valueOf(ANOTHER_TARGET_REFERENCE_TYPE.name())));
    // Then
    assertNotNull(activatedIdentityProviders);
    assertEquals(2, activatedIdentityProviders.size());
    verify(identityProviderActivationRepository).create(argThat((IdentityProviderActivation ipa) -> IDENTITY_PROVIDER_ID.equals(ipa.getIdentityProviderId()) && TARGET_REFERENCE_ID.equals(ipa.getReferenceId()) && TARGET_REFERENCE_TYPE.equals(ipa.getReferenceType())));
    verify(identityProviderActivationRepository).create(argThat((IdentityProviderActivation ipa) -> IDENTITY_PROVIDER_ID.equals(ipa.getIdentityProviderId()) && ANOTHER_TARGET_REFERENCE_ID.equals(ipa.getReferenceId()) && ANOTHER_TARGET_REFERENCE_TYPE.equals(ipa.getReferenceType())));
    verify(auditService).createAuditLog(eq(Audit.AuditReferenceType.valueOf(TARGET_REFERENCE_TYPE.name())), eq(TARGET_REFERENCE_ID), any(), eq(IdentityProvider.AuditEvent.IDENTITY_PROVIDER_ACTIVATED), eq(now), isNull(), eq(createdIPA));
    verify(auditService).createAuditLog(eq(Audit.AuditReferenceType.valueOf(ANOTHER_TARGET_REFERENCE_TYPE.name())), eq(ANOTHER_TARGET_REFERENCE_ID), any(), eq(IdentityProvider.AuditEvent.IDENTITY_PROVIDER_ACTIVATED), eq(now), isNull(), eq(anotherCreatedIPA));
}
Also used : IdentityProviderActivation(io.gravitee.repository.management.model.IdentityProviderActivation) ActivationTarget(io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget) IdentityProviderActivationEntity(io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity) Date(java.util.Date) Test(org.junit.Test)

Example 9 with IdentityProviderActivation

use of io.gravitee.repository.management.model.IdentityProviderActivation in project gravitee-management-rest-api by gravitee-io.

the class IdentityProviderActivationServiceImpl method removeAllIdpsFromTarget.

@Override
public void removeAllIdpsFromTarget(ActivationTarget target) {
    LOGGER.debug("Remove all identity providers from target {} ", target);
    try {
        Set<IdentityProviderActivation> iPAsToRemove = identityProviderActivationRepository.findAllByReferenceIdAndReferenceType(target.getReferenceId(), convert(target.getReferenceType()));
        identityProviderActivationRepository.deleteByReferenceIdAndReferenceType(target.getReferenceId(), convert(target.getReferenceType()));
        for (IdentityProviderActivation ipa : iPAsToRemove) {
            auditService.createAuditLog(Audit.AuditReferenceType.valueOf(ipa.getReferenceType().name()), ipa.getReferenceId(), Collections.singletonMap(Audit.AuditProperties.IDENTITY_PROVIDER, ipa.getReferenceId()), IdentityProvider.AuditEvent.IDENTITY_PROVIDER_DEACTIVATED, new Date(), ipa, null);
        }
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to remove all identity providers from target {}", target, ex);
        throw new TechnicalManagementException("An error occurs while trying to remove all identity providers from target " + target, ex);
    }
}
Also used : IdentityProviderActivation(io.gravitee.repository.management.model.IdentityProviderActivation) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 10 with IdentityProviderActivation

use of io.gravitee.repository.management.model.IdentityProviderActivation in project gravitee-management-rest-api by gravitee-io.

the class IdentityProviderActivationServiceImpl method convert.

private IdentityProviderActivation convert(String identityProviderId, ActivationTarget target, Date createdAt) {
    IdentityProviderActivation identityProviderActivation = new IdentityProviderActivation();
    identityProviderActivation.setIdentityProviderId(identityProviderId);
    identityProviderActivation.setReferenceId(target.getReferenceId());
    identityProviderActivation.setReferenceType(convert(target.getReferenceType()));
    identityProviderActivation.setCreatedAt(createdAt);
    return identityProviderActivation;
}
Also used : IdentityProviderActivation(io.gravitee.repository.management.model.IdentityProviderActivation)

Aggregations

IdentityProviderActivation (io.gravitee.repository.management.model.IdentityProviderActivation)14 Date (java.util.Date)8 Test (org.junit.Test)8 IdentityProviderActivationEntity (io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity)6 ActivationTarget (io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget)6 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)4 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)4 NotNull (org.jetbrains.annotations.NotNull)1