Search in sources :

Example 1 with ActivationTarget

use of io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget 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 2 with ActivationTarget

use of io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget in project gravitee-management-rest-api by gravitee-io.

the class IdentityProviderActivationServiceTest method shouldNotDeactivateIdpOnTargetWhenNotActivated.

@Test(expected = IdentityProviderActivationNotFoundException.class)
public void shouldNotDeactivateIdpOnTargetWhenNotActivated() throws TechnicalException {
    // Given
    doReturn(Optional.empty()).when(identityProviderActivationRepository).findById(IDENTITY_PROVIDER_ID, TARGET_REFERENCE_ID, TARGET_REFERENCE_TYPE);
    // When
    this.identityProviderActivationService.deactivateIdpOnTargets(IDENTITY_PROVIDER_ID, new ActivationTarget(TARGET_REFERENCE_ID, io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationReferenceType.valueOf(TARGET_REFERENCE_TYPE.name())));
}
Also used : ActivationTarget(io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget) Test(org.junit.Test)

Example 3 with ActivationTarget

use of io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget 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 4 with ActivationTarget

use of io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget 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 5 with ActivationTarget

use of io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget in project gravitee-management-rest-api by gravitee-io.

the class IdentityProviderUpgrader method getActivationsTarget.

private ActivationTarget[] getActivationsTarget(int providerIndex) {
    List<String> targetStrings = getListOfString("security.providers[" + providerIndex + "].activations");
    List<ActivationTarget> activationTargets = new ArrayList<>();
    targetStrings.forEach(target -> {
        final String[] orgEnv = target.split(":");
        if (orgEnv.length == 1) {
            try {
                this.organizationService.findById(orgEnv[0]);
                activationTargets.add(new ActivationTarget(orgEnv[0], IdentityProviderActivationReferenceType.ORGANIZATION));
            } catch (OrganizationNotFoundException onfe) {
                logger.warn("Organization {} does not exist", orgEnv[0]);
            }
        } else if (orgEnv.length == 2) {
            try {
                this.organizationService.findById(orgEnv[0]);
                EnvironmentEntity env = this.environmentService.findById(orgEnv[1]);
                if (env.getOrganizationId().equals(orgEnv[0])) {
                    activationTargets.add(new ActivationTarget(orgEnv[1], IdentityProviderActivationReferenceType.ENVIRONMENT));
                } else {
                    logger.warn("Environment {} does not exist in organization {}", orgEnv[1], orgEnv[0]);
                }
            } catch (OrganizationNotFoundException onfe) {
                logger.warn("Organization {} does not exist", orgEnv[0]);
            } catch (EnvironmentNotFoundException Enfe) {
                logger.warn("Environment {} does not exist", orgEnv[1]);
            }
        }
    });
    return activationTargets.toArray(new ActivationTarget[activationTargets.size()]);
}
Also used : ActivationTarget(io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget) OrganizationNotFoundException(io.gravitee.rest.api.service.exceptions.OrganizationNotFoundException) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) EnvironmentNotFoundException(io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException)

Aggregations

ActivationTarget (io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget)10 Test (org.junit.Test)8 IdentityProviderActivation (io.gravitee.repository.management.model.IdentityProviderActivation)6 Date (java.util.Date)6 IdentityProviderActivationEntity (io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity)3 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)1 EnvironmentNotFoundException (io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException)1 OrganizationNotFoundException (io.gravitee.rest.api.service.exceptions.OrganizationNotFoundException)1