Search in sources :

Example 1 with VsAccountDto

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

the class VsReqeustServiceTest method disableRequestTest.

@Test
public void disableRequestTest() {
    SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
    IdmIdentityDto identity = helper.createIdentity(USER_ONE_NAME);
    this.assignRoleSystem(system, identity, 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);
    Assert.assertEquals(Boolean.TRUE, account.isEnable());
    super.logout();
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    // Disable the identity
    identity.setState(IdentityState.DISABLED_MANUALLY);
    identityService.save(identity);
    // Find created requests
    requests = requestService.find(requestFilter, null).getContent().stream().filter(r -> VsRequestState.IN_PROGRESS == r.getState()).collect(Collectors.toList());
    Assert.assertEquals(1, requests.size());
    request = requests.get(0);
    Assert.assertEquals(USER_ONE_NAME, request.getUid());
    Assert.assertEquals(VsOperationType.UPDATE, request.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
    // 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);
    Assert.assertEquals(Boolean.FALSE, account.isEnable());
}
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) 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 2 with VsAccountDto

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

the class VsReqeustServiceTest 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(system.getConnectorInstance(), 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 3 with VsAccountDto

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

the class VsReqeustServiceTest method createMoreRequestsTest.

@Test
public void createMoreRequestsTest() {
    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);
    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);
    IdmIdentityDto userOne = identityService.getByUsername(USER_ONE_NAME);
    userOne.setFirstName(changed);
    userOne.setLastName(changed);
    identityService.save(userOne);
    // Duplicated save ... not invoke provisioning
    identityService.save(userOne);
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(2, requests.size());
    VsRequestDto changeRequest = requests.stream().filter(req -> VsRequestState.IN_PROGRESS == req.getState() && VsOperationType.UPDATE == req.getOperationType()).findFirst().orElse(null);
    Assert.assertNotNull("Request with change not found!", changeRequest);
}
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) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with VsAccountDto

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

the class DefaultVsRequestService method getVsConnectorObject.

@Override
public IcConnectorObject getVsConnectorObject(VsRequestDto request) {
    LOG.info(MessageFormat.format("Start read vs connector object [{0}].", request));
    Assert.notNull(request, "VS request cannot be null!");
    Assert.notNull(request.getConnectorObject(), "Connector object in request cannot be null!");
    // Find account by UID and System ID
    VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
    if (account == null) {
        return null;
    }
    BasicVirtualConfiguration configuration = getVirtualConnector(request).getVirtualConfiguration();
    List<IcAttribute> attributes = accountService.getIcAttributes(account);
    // result list
    if (!configuration.isDisableSupported()) {
        attributes.stream().filter(attribute -> IcAttributeInfo.ENABLE.equals(attribute.getName())).findFirst().ifPresent(attributes::remove);
    }
    IcConnectorObjectImpl connectorObject = new IcConnectorObjectImpl();
    connectorObject.setUidValue(account.getUid());
    connectorObject.setObjectClass(request.getConnectorObject().getObjectClass());
    connectorObject.setAttributes(attributes);
    return connectorObject;
}
Also used : IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) BasicVirtualConfiguration(eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConfiguration)

Example 5 with VsAccountDto

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

the class DefaultVsRequestService method internalExecute.

@Override
public IcUidAttribute internalExecute(VsRequestDto request) {
    request.setState(VsRequestState.REALIZED);
    Assert.notNull(request.getConfiguration(), "Request have to contains connector configuration!");
    Assert.notNull(request.getConnectorKey(), "Request have to contains connector key!");
    // Find connector by request
    VsVirtualConnector virtualConnector = getVirtualConnector(request);
    IcUidAttribute result = null;
    // Save the request
    this.save(request);
    switch(request.getOperationType()) {
        case CREATE:
            {
                result = virtualConnector.internalCreate(request.getConnectorObject().getObjectClass(), request.getConnectorObject().getAttributes());
                break;
            }
        case UPDATE:
            {
                VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
                if (account == null) {
                    throw new VsException(VsResultCode.VS_REQUEST_UPDATING_ACCOUNT_NOT_EXIST, ImmutableMap.of("uid", request.getUid()));
                }
                result = virtualConnector.internalUpdate(new IcUidAttributeImpl(null, request.getUid(), null), request.getConnectorObject().getObjectClass(), request.getConnectorObject().getAttributes());
                break;
            }
        case DELETE:
            {
                VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
                if (account == null) {
                    throw new VsException(VsResultCode.VS_REQUEST_DELETING_ACCOUNT_NOT_EXIST, ImmutableMap.of("uid", request.getUid()));
                }
                virtualConnector.internalDelete(new IcUidAttributeImpl(null, request.getUid(), null), request.getConnectorObject().getObjectClass());
                // All unresolved request created before this delete request will be
                // canceled
                VsRequestFilter filter = new VsRequestFilter();
                filter.setCreatedBefore(request.getCreated());
                filter.setUid(request.getUid());
                filter.setSystemId(request.getSystem());
                filter.setState(VsRequestState.IN_PROGRESS);
                // Unresolved request created before this request
                List<VsRequestDto> beforeRequests = this.find(filter, null).getContent();
                beforeRequests.forEach(beforeRequest -> {
                    String reason = MessageFormat.format("Request [{0}] was canceled (by SYSTEM), because 'after' delete request [{1}] was realized!", beforeRequest.getId(), request.getId());
                    this.cancel(beforeRequest, reason);
                    LOG.info(reason);
                });
                break;
            }
        default:
            throw new IcException(MessageFormat.format("Unsupported operation type [{0}]", request.getOperationType()));
    }
    return result;
}
Also used : SysSystem_(eu.bcvsolutions.idm.acc.entity.SysSystem_) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) SysAttributeDifferenceDto(eu.bcvsolutions.idm.acc.dto.SysAttributeDifferenceDto) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) StringUtils(org.apache.commons.lang3.StringUtils) VsRequestEvent(eu.bcvsolutions.idm.vs.event.VsRequestEvent) VsVirtualConnector(eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) Predicate(javax.persistence.criteria.Predicate) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) VsSystemService(eu.bcvsolutions.idm.vs.service.api.VsSystemService) Sort(org.springframework.data.domain.Sort) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsConnectorObjectDto(eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto) Path(javax.persistence.criteria.Path) VsOperationType(eu.bcvsolutions.idm.vs.domain.VsOperationType) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) VsRequest_(eu.bcvsolutions.idm.vs.entity.VsRequest_) ImmutableMap(com.google.common.collect.ImmutableMap) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) List(java.util.List) VsRequest(eu.bcvsolutions.idm.vs.entity.VsRequest) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) CzechIdMIcConnectorService(eu.bcvsolutions.idm.ic.czechidm.service.impl.CzechIdMIcConnectorService) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) VsRequestRealizationProcessor(eu.bcvsolutions.idm.vs.event.processor.VsRequestRealizationProcessor) BasicVirtualConfiguration(eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConfiguration) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) VsSystemImplementerService(eu.bcvsolutions.idm.vs.service.api.VsSystemImplementerService) VsRequestRepository(eu.bcvsolutions.idm.vs.repository.VsRequestRepository) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) IdmRoleRequest_(eu.bcvsolutions.idm.core.model.entity.IdmRoleRequest_) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) MessageFormat(java.text.MessageFormat) VsResultCode(eu.bcvsolutions.idm.vs.exception.VsResultCode) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) CollectionUtils(org.apache.commons.collections.CollectionUtils) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) Service(org.springframework.stereotype.Service) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) VsRequestEventType(eu.bcvsolutions.idm.vs.event.VsRequestEvent.VsRequestEventType) AbstractReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.AbstractReadWriteDtoService) VsSystemImplementer(eu.bcvsolutions.idm.vs.entity.VsSystemImplementer) Direction(org.springframework.data.domain.Sort.Direction) Root(javax.persistence.criteria.Root) IcAttributeInfo(eu.bcvsolutions.idm.ic.api.IcAttributeInfo) CzechIdMIcConfigurationService(eu.bcvsolutions.idm.ic.czechidm.service.impl.CzechIdMIcConfigurationService) SysProvisioningArchiveService(eu.bcvsolutions.idm.acc.service.api.SysProvisioningArchiveService) Logger(org.slf4j.Logger) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsAccountService(eu.bcvsolutions.idm.vs.service.api.VsAccountService) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) IdmIdentityContract_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract_) VsException(eu.bcvsolutions.idm.vs.exception.VsException) VsSystemImplementer_(eu.bcvsolutions.idm.vs.entity.VsSystemImplementer_) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) VirtualSystemModuleDescriptor(eu.bcvsolutions.idm.vs.VirtualSystemModuleDescriptor) SynchronizationEntityExecutor(eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor) VsRequestState(eu.bcvsolutions.idm.vs.domain.VsRequestState) Subquery(javax.persistence.criteria.Subquery) VirtualSystemGroupPermission(eu.bcvsolutions.idm.vs.domain.VirtualSystemGroupPermission) VsRequestService(eu.bcvsolutions.idm.vs.service.api.VsRequestService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) IcException(eu.bcvsolutions.idm.ic.exception.IcException) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) VsException(eu.bcvsolutions.idm.vs.exception.VsException) IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) List(java.util.List) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) VsVirtualConnector(eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector)

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