Search in sources :

Example 21 with VsAccountDto

use of eu.bcvsolutions.idm.vs.dto.VsAccountDto 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 22 with VsAccountDto

use of eu.bcvsolutions.idm.vs.dto.VsAccountDto 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 23 with VsAccountDto

use of eu.bcvsolutions.idm.vs.dto.VsAccountDto 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 24 with VsAccountDto

use of eu.bcvsolutions.idm.vs.dto.VsAccountDto 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)

Example 25 with VsAccountDto

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

the class DefaultVsRequestServiceIntegrationTest method createAndRealizeRequestWithNoteTest.

@Test
public void createAndRealizeRequestWithNoteTest() {
    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")));
    String note = helper.createName();
    request = requestService.realize(request, note);
    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);
    request = requestService.get(request.getId());
    Assert.assertEquals(note, request.getReason());
}
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)

Aggregations

VsAccountDto (eu.bcvsolutions.idm.vs.dto.VsAccountDto)31 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)22 VsRequestDto (eu.bcvsolutions.idm.vs.dto.VsRequestDto)22 VsRequestFilter (eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter)22 Test (org.junit.Test)21 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)18 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)17 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)13 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 IcException (eu.bcvsolutions.idm.ic.exception.IcException)6 IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)5 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)5 UUID (java.util.UUID)5 IcObjectClassImpl (eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl)4 IcUidAttributeImpl (eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl)4 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)3 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)3 IcConnectorObjectImpl (eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl)3 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2