Search in sources :

Example 36 with VsRequestDto

use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestServiceIntegrationTest method realizeRequestWithouRightTest.

@Test(expected = ForbiddenEntityException.class)
public void realizeRequestWithouRightTest() {
    String reason = "cancel \"request\" reason!";
    SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
    this.assignRoleSystem(system, helper.createIdentity(USER_ONE_NAME), ROLE_ONE_NAME);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setUid(USER_ONE_NAME);
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    VsRequestDto request = requests.get(0);
    Assert.assertEquals(USER_ONE_NAME, request.getUid());
    Assert.assertEquals(VsOperationType.CREATE, request.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
    VsAccountDto account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
    Assert.assertNull("Account must be null, because request was not realized yet!", account);
    // We try cancel the request
    super.logout();
    loginService.login(new LoginDto(USER_ONE_NAME, new GuardedString("password")));
    request = requestService.cancel(request, reason);
}
Also used : VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 37 with VsRequestDto

use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestServiceIntegrationTest method checkSinglevalueInWishObjectTest.

@Test
public void checkSinglevalueInWishObjectTest() {
    String changed = "changed";
    String firstName = "firstName";
    String lastName = "lastName";
    SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
    IdmIdentityDto userOne = helper.createIdentity(USER_ONE_NAME);
    userOne.setFirstName(firstName);
    userOne.setLastName(lastName);
    identityService.save(userOne);
    this.assignRoleSystem(system, userOne, ROLE_ONE_NAME);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setUid(USER_ONE_NAME);
    requestFilter.setState(VsRequestState.IN_PROGRESS);
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    VsRequestDto createRequest = requests.get(0);
    Assert.assertEquals(USER_ONE_NAME, createRequest.getUid());
    Assert.assertEquals(VsOperationType.CREATE, createRequest.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, createRequest.getState());
    VsConnectorObjectDto wish = requestService.getWishConnectorObject(createRequest);
    boolean findAttributeWithouChange = wish.getAttributes().stream().filter(attribute -> !attribute.isChanged()).findFirst().isPresent();
    Assert.assertTrue(!findAttributeWithouChange);
    // Change singlevalue attributes
    userOne.setFirstName(changed);
    userOne.setLastName(changed);
    // Invoke provisioning
    identityService.save(userOne);
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(2, requests.size());
    // We realize the create request
    super.logout();
    loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
    requestService.realize(createRequest);
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    // get wish
    wish = requestService.getWishConnectorObject(requests.get(0));
    Assert.assertEquals(2, wish.getAttributes().stream().filter(attr -> attr.isChanged()).count());
    // Find change for firstName value
    boolean findCorrectChangedFirstName = wish.getAttributes().stream().filter(attr -> attr.getValue() != null && attr.getValue().getValue().equals(changed) && attr.getValue().getOldValue().equals(firstName) && SysValueChangeType.UPDATED == attr.getValue().getChange()).findFirst().isPresent();
    Assert.assertTrue(findCorrectChangedFirstName);
    // Find change for lastName value
    boolean findCorrectChangedLastName = wish.getAttributes().stream().filter(attr -> attr.getValue() != null && attr.getValue().getValue().equals(changed) && attr.getValue().getOldValue().equals(lastName) && SysValueChangeType.UPDATED == attr.getValue().getChange()).findFirst().isPresent();
    Assert.assertTrue(findCorrectChangedLastName);
}
Also used : VsConnectorObjectDto(eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 38 with VsRequestDto

use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestServiceIntegrationTest method systemAccountFilterTest.

@Test
public void systemAccountFilterTest() {
    SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
    this.assignRoleSystem(system, helper.createIdentity(USER_ONE_NAME), ROLE_ONE_NAME);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setUid(USER_ONE_NAME);
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    VsRequestDto request = requests.get(0);
    Assert.assertEquals(USER_ONE_NAME, request.getUid());
    Assert.assertEquals(VsOperationType.CREATE, request.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
    VsAccountDto account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
    Assert.assertNull("Account must be null, because request was not realized yet!", account);
    // We try realize the request
    super.logout();
    loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
    request = requestService.realize(request);
    Assert.assertEquals(VsRequestState.REALIZED, request.getState());
    account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
    Assert.assertNotNull("Account cannot be null, because request was realized!", account);
    IcConnectorConfiguration configuration = systemService.getConnectorConfiguration(system);
    IcObjectClass objectClass = new IcObjectClassImpl("__ACCOUNT__");
    List<String> uids = new ArrayList<>();
    connectorFacade.search(systemService.getConnectorInstance(system), configuration, objectClass, null, new IcResultsHandler() {

        @Override
        public boolean handle(IcConnectorObject connectorObject) {
            uids.add(connectorObject.getUidValue());
            return true;
        }
    });
    Assert.assertEquals(1, uids.size());
    Assert.assertEquals(USER_ONE_NAME, uids.get(0));
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcResultsHandler(eu.bcvsolutions.idm.ic.filter.api.IcResultsHandler) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 39 with VsRequestDto

use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestServiceIntegrationTest method realizeRequestOwnereRelationAfterDeleteTest.

/**
 * Relation on identity (target entity) after delete account must exists in vs-request.
 */
@Test
public void realizeRequestOwnereRelationAfterDeleteTest() {
    String changed = "changed";
    SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
    this.assignRoleSystem(system, helper.createIdentity(USER_ONE_NAME), ROLE_ONE_NAME);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setUid(USER_ONE_NAME);
    requestFilter.setIncludeOwner(true);
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    assertEquals(1, requests.size());
    VsRequestDto request = requests.get(0);
    assertEquals(USER_ONE_NAME, request.getUid());
    assertEquals(VsOperationType.CREATE, request.getOperationType());
    assertEquals(VsRequestState.IN_PROGRESS, request.getState());
    VsAccountDto account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
    Assert.assertNull("Account must be null, because request was not realized yet!", account);
    IdmIdentityDto userOne = identityService.getByUsername(USER_ONE_NAME);
    userOne.setFirstName(changed);
    userOne.setLastName(changed);
    identityService.save(userOne);
    // Delete identity roles for userOne.
    IdmRoleRequestDto roleRequestDelete = roleRequestService.createRequest(helper.getPrimeContract(userOne.getId()));
    identityRoleService.findAllByIdentity(userOne.getId()).forEach(identityRole -> {
        roleRequestService.createConcept(roleRequestDelete, helper.getPrimeContract(userOne.getId()), identityRole.getId(), identityRole.getRole(), ConceptRoleRequestOperation.REMOVE);
    });
    this.getHelper().executeRequest(roleRequestDelete, false, true);
    requests = requestService.find(requestFilter, null, IdmBasePermission.READ).getContent();
    assertEquals(3, requests.size());
    VsRequestDto changeRequest = requests.stream().filter(req -> VsRequestState.IN_PROGRESS == req.getState() && VsOperationType.UPDATE == req.getOperationType()).findFirst().orElse(null);
    assertNotNull("Request with change not found!", changeRequest);
    VsRequestDto deleteRequest = requests.stream().filter(req -> VsRequestState.IN_PROGRESS == req.getState() && VsOperationType.DELETE == req.getOperationType()).findFirst().orElse(null);
    assertNotNull("Request with delete not found!", deleteRequest);
    VsRequestDto createRequest = requests.stream().filter(req -> VsRequestState.IN_PROGRESS == req.getState() && VsOperationType.CREATE == req.getOperationType()).findFirst().orElse(null);
    assertNotNull("Request with create not found!", createRequest);
    // Target entity must exists.
    assertNotNull(deleteRequest.getTargetEntity());
    assertNotNull(deleteRequest.getTargetEntityType());
    assertEquals(userOne.getId(), deleteRequest.getTargetEntity().getId());
    // Realize create request
    request = requestService.realize(createRequest);
    // Realize update request
    request = requestService.realize(changeRequest);
    // Realize delete request
    request = requestService.realize(deleteRequest);
    // Find only archived
    requestFilter.setOnlyArchived(Boolean.TRUE);
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(3, requests.size());
    boolean foundNotRealized = requests.stream().anyMatch(req -> VsRequestState.REALIZED != req.getState());
    Assert.assertFalse("Found not realized requests!", foundNotRealized);
    // Delete
    identityService.delete(userOne);
}
Also used : VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 40 with VsRequestDto

use of eu.bcvsolutions.idm.vs.dto.VsRequestDto in project CzechIdMng by bcvsolutions.

the class DefaultVsRequestServiceIntegrationTest method createAndRealizeRequestTest.

@Test
public void createAndRealizeRequestTest() {
    SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
    this.assignRoleSystem(system, helper.createIdentity(USER_ONE_NAME), ROLE_ONE_NAME);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setUid(USER_ONE_NAME);
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    VsRequestDto request = requests.get(0);
    UUID requestId = request.getId();
    Assert.assertEquals(USER_ONE_NAME, request.getUid());
    Assert.assertEquals(VsOperationType.CREATE, request.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
    VsAccountDto account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
    Assert.assertNull("Account must be null, because request was not realized yet!", account);
    // We try realize the request
    super.logout();
    loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
    request = requestService.realize(request);
    Assert.assertEquals(VsRequestState.REALIZED, request.getState());
    account = accountService.findByUidSystem(USER_ONE_NAME, system.getId());
    Assert.assertNotNull("Account cannot be null, because request was realized!", account);
    // test referential integrity - delete system
    // TODO: move to api
    String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", system.getConnectorKey().getFullName(), system.getId());
    Assert.assertNotNull(formService.getDefinition(VsAccount.class, virtualSystemKey));
    VsSystemImplementerFilter implementerFilter = new VsSystemImplementerFilter();
    implementerFilter.setSystemId(system.getId());
    Assert.assertNotEquals(0, systemImplementerService.count(implementerFilter));
    // clean up acc accounts
    AccAccountFilter accAccountFilter = new AccAccountFilter();
    accAccountFilter.setSystemId(system.getId());
    accAccountService.find(accAccountFilter, null).forEach(a -> {
        accAccountService.delete(a);
    });
    requestService.find(requestFilter, null).forEach(r -> {
        // delete account creates request in progress
        if (!r.getId().equals(requestId)) {
            requestService.delete(r);
        }
    });
    Assert.assertNotNull(requestService.get(request));
    systemService.delete(system);
    Assert.assertNull(formService.getDefinition(VsAccount.class, virtualSystemKey));
    Assert.assertNull(requestService.get(request));
    Assert.assertNull(accountService.get(account));
    Assert.assertEquals(0, systemImplementerService.count(implementerFilter));
}
Also used : VsAccount(eu.bcvsolutions.idm.vs.entity.VsAccount) VsSystemImplementerFilter(eu.bcvsolutions.idm.vs.dto.filter.VsSystemImplementerFilter) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) UUID(java.util.UUID) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

VsRequestDto (eu.bcvsolutions.idm.vs.dto.VsRequestDto)50 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)37 VsRequestFilter (eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter)37 Test (org.junit.Test)35 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)29 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)27 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)26 VsAccountDto (eu.bcvsolutions.idm.vs.dto.VsAccountDto)24 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)19 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)13 VsConnectorObjectDto (eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto)7 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)6 UUID (java.util.UUID)6 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)5 ArrayList (java.util.ArrayList)5 SysSystemEntityFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter)4 IcConnectorConfiguration (eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration)4 IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)4 IcException (eu.bcvsolutions.idm.ic.exception.IcException)4 IcResultsHandler (eu.bcvsolutions.idm.ic.filter.api.IcResultsHandler)4