Search in sources :

Example 1 with IdentityProviderActivation

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

the class IdentityProviderActivationServiceImpl method deactivateIdpOnAllTargets.

@Override
public void deactivateIdpOnAllTargets(String identityProviderId) {
    LOGGER.debug("Deactivate identity provider {} on all targets", identityProviderId);
    try {
        Set<IdentityProviderActivation> iPAsToRemove = identityProviderActivationRepository.findAllByIdentityProviderId(identityProviderId);
        identityProviderActivationRepository.deleteByIdentityProviderId(identityProviderId);
        for (IdentityProviderActivation ipa : iPAsToRemove) {
            auditService.createAuditLog(Audit.AuditReferenceType.valueOf(ipa.getReferenceType().name()), ipa.getReferenceId(), Collections.singletonMap(Audit.AuditProperties.IDENTITY_PROVIDER, ipa.getIdentityProviderId()), IdentityProvider.AuditEvent.IDENTITY_PROVIDER_DEACTIVATED, new Date(), ipa, null);
        }
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to deactivate identity provider {} on all targets", identityProviderId, ex);
        throw new TechnicalManagementException("An error occurs while trying to deactivate identity provider " + identityProviderId + " on all targets", 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 2 with IdentityProviderActivation

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

the class IdentityProviderActivationServiceImpl method activateIdpOnTargets.

@Override
public Set<IdentityProviderActivationEntity> activateIdpOnTargets(String identityProviderId, ActivationTarget... targetsToAdd) {
    LOGGER.debug("Activate identity provider {} on targets {} ", identityProviderId, targetsToAdd);
    try {
        Set<IdentityProviderActivationEntity> createdActivations = new HashSet<>();
        for (ActivationTarget target : targetsToAdd) {
            IdentityProviderActivation createdIdentityProviderActivation = createIdentityProviderActivation(identityProviderId, target);
            createdActivations.add(convert(createdIdentityProviderActivation));
        }
        return createdActivations;
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to Activate identity provider {} on targets {}", identityProviderId, targetsToAdd, ex);
        throw new TechnicalManagementException("An error occurs while trying to Activate identity provider " + identityProviderId + " on targets " + Arrays.toString(targetsToAdd), ex);
    }
}
Also used : IdentityProviderActivation(io.gravitee.repository.management.model.IdentityProviderActivation) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) IdentityProviderActivationEntity(io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 3 with IdentityProviderActivation

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

the class IdentityProviderActivationServiceImpl method createIdentityProviderActivation.

@NotNull
private IdentityProviderActivation createIdentityProviderActivation(String identityProviderId, ActivationTarget target) throws TechnicalException {
    IdentityProviderActivation createdIdentityProviderActivation = identityProviderActivationRepository.create(convert(identityProviderId, target, new Date()));
    auditService.createAuditLog(Audit.AuditReferenceType.valueOf(target.getReferenceType().name()), target.getReferenceId(), Collections.singletonMap(Audit.AuditProperties.IDENTITY_PROVIDER, createdIdentityProviderActivation.getIdentityProviderId()), IdentityProvider.AuditEvent.IDENTITY_PROVIDER_ACTIVATED, createdIdentityProviderActivation.getCreatedAt(), null, createdIdentityProviderActivation);
    return createdIdentityProviderActivation;
}
Also used : IdentityProviderActivation(io.gravitee.repository.management.model.IdentityProviderActivation) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with IdentityProviderActivation

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

the class IdentityProviderActivationServiceImpl method addIdpsOnTarget.

@Override
public Set<IdentityProviderActivationEntity> addIdpsOnTarget(ActivationTarget target, String... identityProviderIdsToAdd) {
    LOGGER.debug("Add identity providers {} on target {} ", identityProviderIdsToAdd, target);
    try {
        Set<IdentityProviderActivationEntity> createdActivations = new HashSet<>();
        for (String identityProviderId : identityProviderIdsToAdd) {
            IdentityProviderActivation createdIdentityProviderActivation = createIdentityProviderActivation(identityProviderId, target);
            createdActivations.add(convert(createdIdentityProviderActivation));
        }
        return createdActivations;
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to add identity providers {} on target {}", identityProviderIdsToAdd, target, ex);
        throw new TechnicalManagementException("An error occurs while trying to add identity providers " + Arrays.toString(identityProviderIdsToAdd) + " on target " + target, ex);
    }
}
Also used : IdentityProviderActivation(io.gravitee.repository.management.model.IdentityProviderActivation) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) IdentityProviderActivationEntity(io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 5 with IdentityProviderActivation

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

the class IdentityProviderActivationServiceTest method shouldAddIdpsOnTarget.

@Test
public void shouldAddIdpsOnTarget() 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(ANOTHER_IDENTITY_PROVIDER_ID);
    anotherCreatedIPA.setReferenceId(TARGET_REFERENCE_ID);
    anotherCreatedIPA.setReferenceType(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) -> ANOTHER_IDENTITY_PROVIDER_ID.equals(ipa.getIdentityProviderId()) && TARGET_REFERENCE_ID.equals(ipa.getReferenceId()) && TARGET_REFERENCE_TYPE.equals(ipa.getReferenceType())));
    // When
    Set<IdentityProviderActivationEntity> activatedIdentityProviders = this.identityProviderActivationService.addIdpsOnTarget(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
    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) -> ANOTHER_IDENTITY_PROVIDER_ID.equals(ipa.getIdentityProviderId()) && TARGET_REFERENCE_ID.equals(ipa.getReferenceId()) && 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(TARGET_REFERENCE_TYPE.name())), eq(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)

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