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));
}
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())));
}
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());
}
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));
}
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()]);
}
Aggregations