use of io.gravitee.repository.management.model.IdentityProviderActivation in project gravitee-management-rest-api by gravitee-io.
the class IdentityProviderActivationServiceTest method shouldDeactivateIdpOnTargets.
@Test
public void shouldDeactivateIdpOnTargets() 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(IDENTITY_PROVIDER_ID);
anotherIpaToRemove.setReferenceId(ANOTHER_TARGET_REFERENCE_ID);
anotherIpaToRemove.setReferenceType(ANOTHER_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(IDENTITY_PROVIDER_ID, ANOTHER_TARGET_REFERENCE_ID, ANOTHER_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())), new ActivationTarget(ANOTHER_TARGET_REFERENCE_ID, io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationReferenceType.valueOf(ANOTHER_TARGET_REFERENCE_TYPE.name())));
// Then
verify(identityProviderActivationRepository).findById(IDENTITY_PROVIDER_ID, TARGET_REFERENCE_ID, TARGET_REFERENCE_TYPE);
verify(identityProviderActivationRepository).findById(IDENTITY_PROVIDER_ID, ANOTHER_TARGET_REFERENCE_ID, ANOTHER_TARGET_REFERENCE_TYPE);
verify(identityProviderActivationRepository).delete(IDENTITY_PROVIDER_ID, TARGET_REFERENCE_ID, TARGET_REFERENCE_TYPE);
verify(identityProviderActivationRepository).delete(IDENTITY_PROVIDER_ID, ANOTHER_TARGET_REFERENCE_ID, ANOTHER_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(ANOTHER_TARGET_REFERENCE_TYPE.name())), eq(ANOTHER_TARGET_REFERENCE_ID), any(), eq(IdentityProvider.AuditEvent.IDENTITY_PROVIDER_DEACTIVATED), any(), eq(anotherIpaToRemove), isNull());
}
use of io.gravitee.repository.management.model.IdentityProviderActivation in project gravitee-management-rest-api by gravitee-io.
the class IdentityProviderActivationServiceTest method shouldDeactivateIdpOnAllTargets.
@Test
public void shouldDeactivateIdpOnAllTargets() 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(IDENTITY_PROVIDER_ID);
anotherIpaToRemove.setReferenceId(ANOTHER_TARGET_REFERENCE_ID);
anotherIpaToRemove.setReferenceType(ANOTHER_TARGET_REFERENCE_TYPE);
anotherIpaToRemove.setCreatedAt(now);
doReturn(newSet(ipaToRemove, anotherIpaToRemove)).when(identityProviderActivationRepository).findAllByIdentityProviderId(IDENTITY_PROVIDER_ID);
// When
this.identityProviderActivationService.deactivateIdpOnAllTargets(IDENTITY_PROVIDER_ID);
// Then
verify(identityProviderActivationRepository).findAllByIdentityProviderId(IDENTITY_PROVIDER_ID);
verify(identityProviderActivationRepository).deleteByIdentityProviderId(IDENTITY_PROVIDER_ID);
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(ANOTHER_TARGET_REFERENCE_TYPE.name())), eq(ANOTHER_TARGET_REFERENCE_ID), any(), eq(IdentityProvider.AuditEvent.IDENTITY_PROVIDER_DEACTIVATED), any(), eq(anotherIpaToRemove), isNull());
}
use of io.gravitee.repository.management.model.IdentityProviderActivation 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);
}
use of io.gravitee.repository.management.model.IdentityProviderActivation 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());
}
Aggregations