Search in sources :

Example 26 with VsAccountDto

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

the class DefaultVsRequestServiceIntegrationTest 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 27 with VsAccountDto

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

the class BasicVirtualConnector method internalDelete.

@Override
public void internalDelete(IcUidAttribute uid, IcObjectClass objectClass) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    String uidValue = this.validateAndGetUid(uid);
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    // Find account by UID and System ID
    VsAccountDto account = accountService.findByUidSystem(uidValue, systemId);
    if (account == null) {
        throw new IcException(MessageFormat.format("Vs account was not found for UID [{0}] and system ID [{1}]!", uidValue, systemId));
    }
    // Delete vs account and connected form values
    accountService.delete(account);
}
Also used : VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) IcException(eu.bcvsolutions.idm.ic.exception.IcException)

Example 28 with VsAccountDto

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

the class BasicVirtualConnector method read.

@Override
public IcConnectorObject read(IcUidAttribute uid, IcObjectClass objectClass) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    Assert.notNull(uid, "UID cannot be null!");
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    String uidValue = uid.getUidValue();
    if (uidValue == null) {
        throw new IcException("UID value cannot be null!");
    }
    // Find account by UID and System ID
    VsAccountDto account = accountService.findByUidSystem(uidValue, systemId);
    // All attributes from VS account
    List<IcAttribute> vsAttributes = new ArrayList<>();
    // Create uid attribute
    IcAttributeImpl uidAttribute = new IcAttributeImpl(IcAttributeInfo.NAME, uidValue);
    vsAttributes.add(uidAttribute);
    if (account != null) {
        // Create enable attribute
        if (this.virtualConfiguration.isDisableSupported()) {
            IcAttributeImpl enableAttribute = new IcAttributeImpl(IcAttributeInfo.ENABLE, account.isEnable());
            vsAttributes.add(enableAttribute);
        }
        // Attributes from definition and configuration
        UUID accountId = account.getId();
        Arrays.asList(virtualConfiguration.getAttributes()).forEach(virtualAttirbute -> {
            IcAttribute attribute = accountService.getIcAttribute(accountId, virtualAttirbute, formDefinition);
            if (attribute == null) {
                return;
            }
            vsAttributes.add(attribute);
        });
    }
    // Overwrite attributes form VS account with attributes from unresloved
    // requests
    List<IcAttribute> attributes = this.overwriteAttributesByUnresolvedRequests(account, uidValue, vsAttributes);
    if (attributes == null) {
        return null;
    }
    IcConnectorObjectImpl connectorObject = new IcConnectorObjectImpl();
    connectorObject.setUidValue(uidValue);
    connectorObject.setObjectClass(new IcObjectClassImpl(IcObjectClassInfo.ACCOUNT));
    connectorObject.setAttributes(attributes);
    return connectorObject;
}
Also used : IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) ArrayList(java.util.ArrayList) IcException(eu.bcvsolutions.idm.ic.exception.IcException) UUID(java.util.UUID) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl)

Example 29 with VsAccountDto

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

the class VsRequestCancelBulkActionTest method testCancelRequestWithoutReason.

@Test(expected = ResultCodeException.class)
public void testCancelRequestWithoutReason() {
    IdmIdentityDto implementer = helper.createIdentity();
    IdmIdentityDto identity = helper.createIdentity();
    IdmRoleDto roleForVs = helper.createRole();
    SysSystemDto system = this.createVirtualSystem(implementer, null);
    helper.createRoleSystem(roleForVs, system);
    helper.createIdentityRole(identity, roleForVs);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setUid(identity.getUsername());
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    VsRequestDto request = requests.get(0);
    Assert.assertEquals(identity.getUsername(), request.getUid());
    Assert.assertEquals(VsOperationType.CREATE, request.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
    VsAccountDto account = accountService.findByUidSystem(identity.getUsername(), system.getId());
    Assert.assertNull("Account must be null, because request was not realized yet!", account);
    // We try cancel the request
    IdmBulkActionDto bulkAction = this.findBulkAction(VsRequest.class, VsRequestCancelBulkAction.NAME);
    bulkAction.setIdentifiers(Sets.newHashSet(request.getId()));
    // Reason is null -> request cannot be cancelled.
    Map<String, Object> properties = new HashMap<>();
    properties.put(VsRequestCancelBulkAction.REASON, null);
    bulkAction.setProperties(properties);
    bulkActionManager.processAction(bulkAction);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 30 with VsAccountDto

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

the class VsAccountController method saveFormValues.

/**
 * Saves connector configuration form values
 *
 * @param backendId
 * @param formValues
 * @return
 */
@ResponseBody
@PreAuthorize("hasAuthority('" + VirtualSystemGroupPermission.VS_ACCOUNT_UPDATE + "')")
@RequestMapping(value = "/{backendId}/form-values", method = RequestMethod.POST)
@ApiOperation(value = "Account form definition - save values", nickname = "postAccountFormValues", tags = { VsAccountController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = VirtualSystemGroupPermission.VS_ACCOUNT_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = VirtualSystemGroupPermission.VS_ACCOUNT_UPDATE, description = "") }) })
public Resource<?> saveFormValues(@ApiParam(value = "Account's uuid identifier.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Code of form definition (default will be used if no code is given).", required = false, defaultValue = FormService.DEFAULT_DEFINITION_CODE) @RequestParam(name = "definitionCode", required = false) String definitionCode, @ApiParam(value = "Filled form data.", required = true) @RequestBody @Valid List<IdmFormValueDto> formValues) {
    VsAccountDto entity = getDto(backendId);
    if (entity == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    checkAccess(entity, IdmBasePermission.UPDATE);
    // 
    IdmFormDefinitionDto formDefinition = formDefinitionController.getDefinition(VsAccount.class, definitionCode);
    // 
    return formDefinitionController.saveFormValues(entity, formDefinition, formValues);
}
Also used : VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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