Search in sources :

Example 1 with IdentityProviderActivationEntity

use of io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity 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 2 with IdentityProviderActivationEntity

use of io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity 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 3 with IdentityProviderActivationEntity

use of io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity 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)

Example 4 with IdentityProviderActivationEntity

use of io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity 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 5 with IdentityProviderActivationEntity

use of io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity 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)

Aggregations

IdentityProviderActivationEntity (io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity)8 IdentityProviderActivation (io.gravitee.repository.management.model.IdentityProviderActivation)6 Test (org.junit.Test)5 Date (java.util.Date)4 ActivationTarget (io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget)3 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)2 PortalSettingsEntity (io.gravitee.rest.api.model.settings.PortalSettingsEntity)1 ConfigurationIdentitiesResponse (io.gravitee.rest.api.portal.rest.model.ConfigurationIdentitiesResponse)1 Response (javax.ws.rs.core.Response)1