Search in sources :

Example 6 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 shouldNotRemoveIdpsFromTargetWhenNotActivated.

@Test(expected = IdentityProviderActivationNotFoundException.class)
public void shouldNotRemoveIdpsFromTargetWhenNotActivated() throws TechnicalException {
    // Given
    doReturn(Optional.empty()).when(identityProviderActivationRepository).findById(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);
}
Also used : ActivationTarget(io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget) Test(org.junit.Test)

Example 7 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 shouldFindAllByTarget.

@Test
public void shouldFindAllByTarget() 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(ANOTHER_IDENTITY_PROVIDER_ID);
    anotherIpa.setReferenceId(TARGET_REFERENCE_ID);
    anotherIpa.setReferenceType(TARGET_REFERENCE_TYPE);
    anotherIpa.setCreatedAt(now);
    doReturn(newSet(ipa, anotherIpa)).when(identityProviderActivationRepository).findAllByReferenceIdAndReferenceType(TARGET_REFERENCE_ID, TARGET_REFERENCE_TYPE);
    // When
    Set<IdentityProviderActivationEntity> foundIdentityProviders = this.identityProviderActivationService.findAllByTarget(new ActivationTarget(TARGET_REFERENCE_ID, io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationReferenceType.valueOf(TARGET_REFERENCE_TYPE.name())));
    // Then
    assertNotNull(foundIdentityProviders);
    assertEquals(2, foundIdentityProviders.size());
    verify(identityProviderActivationRepository).findAllByReferenceIdAndReferenceType(TARGET_REFERENCE_ID, TARGET_REFERENCE_TYPE);
}
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 8 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 shouldRemoveAllIdpsFromTarget.

@Test
public void shouldRemoveAllIdpsFromTarget() 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(newSet(ipaToRemove, anotherIpaToRemove)).when(identityProviderActivationRepository).findAllByReferenceIdAndReferenceType(TARGET_REFERENCE_ID, TARGET_REFERENCE_TYPE);
    // When
    this.identityProviderActivationService.removeAllIdpsFromTarget(new ActivationTarget(TARGET_REFERENCE_ID, io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationReferenceType.valueOf(TARGET_REFERENCE_TYPE.name())));
    // Then
    verify(identityProviderActivationRepository).findAllByReferenceIdAndReferenceType(TARGET_REFERENCE_ID, TARGET_REFERENCE_TYPE);
    verify(identityProviderActivationRepository).deleteByReferenceIdAndReferenceType(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 9 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)

Example 10 with ActivationTarget

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

the class IdentityProviderActivationUpgrader method upgrade.

@Override
public boolean upgrade() {
    // initialize roles.
    final ActivationTarget defaultEnvTarget = new ActivationTarget(GraviteeContext.getDefaultEnvironment(), IdentityProviderActivationReferenceType.ENVIRONMENT);
    final ActivationTarget defaultOrgTarget = new ActivationTarget(GraviteeContext.getDefaultOrganization(), IdentityProviderActivationReferenceType.ORGANIZATION);
    if (this.identityProviderActivationService.findAllByTarget(defaultOrgTarget).isEmpty() && this.identityProviderActivationService.findAllByTarget(defaultEnvTarget).isEmpty()) {
        logger.info("    No activation found. Active all idp on all target by default if enabled.");
        this.identityProviderService.findAll().forEach(idp -> {
            if (idp.isEnabled()) {
                this.identityProviderActivationService.activateIdpOnTargets(idp.getId(), defaultOrgTarget, defaultEnvTarget);
            }
        });
    }
    return true;
}
Also used : ActivationTarget(io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget)

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