Search in sources :

Example 11 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 12 with VsAccountDto

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

the class VsAccountController method getFormValues.

/**
 * Returns filled form values
 *
 * @param backendId
 * @return
 */
@ResponseBody
@RequestMapping(value = "/{backendId}/form-values", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + VirtualSystemGroupPermission.VS_ACCOUNT_READ + "')")
@ApiOperation(value = "Account form definition - read values", nickname = "getAccountFormValues", tags = { VsAccountController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = VirtualSystemGroupPermission.VS_ACCOUNT_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = VirtualSystemGroupPermission.VS_ACCOUNT_READ, description = "") }) })
public Resource<?> getFormValues(@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) {
    VsAccountDto entity = getDto(backendId);
    if (entity == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    // 
    IdmFormDefinitionDto formDefinition = formDefinitionController.getDefinition(VsAccount.class, definitionCode);
    // 
    return formDefinitionController.getFormValues(entity, formDefinition);
}
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)

Example 13 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)

Example 14 with VsAccountDto

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

the class VsReqeustServiceTest method realizeUpdateAndDeleteRequestsTest.

@Test
public void realizeUpdateAndDeleteRequestsTest() {
    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);
    // Delete identity
    identityService.delete(userOne);
    // Test read rights (none requests can be returned for UserOne)
    IdmIdentityDto userTwo = helper.createIdentity("vsUserTwo");
    super.logout();
    loginService.login(new LoginDto(userTwo.getUsername(), new GuardedString("password")));
    requests = requestService.find(requestFilter, null, IdmBasePermission.READ).getContent();
    Assert.assertEquals("We found request without correct rights!", 0, requests.size());
    // Test read rights (3 requests must be returned for UserImplementer)
    super.logout();
    loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
    requests = requestService.find(requestFilter, null, IdmBasePermission.READ).getContent();
    Assert.assertEquals(3, 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);
    VsRequestDto deleteRequest = requests.stream().filter(req -> VsRequestState.IN_PROGRESS == req.getState() && VsOperationType.DELETE == req.getOperationType()).findFirst().orElse(null);
    Assert.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);
    Assert.assertNotNull("Request with create not found!", createRequest);
    // 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().filter(req -> VsRequestState.REALIZED != req.getState()).findFirst().isPresent();
    Assert.assertTrue("Found not realized requests!", !foundNotRealized);
}
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) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) 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 15 with VsAccountDto

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

the class VsReqeustServiceTest 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);
    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);
}
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) 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)17 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)8 VsRequestDto (eu.bcvsolutions.idm.vs.dto.VsRequestDto)8 VsRequestFilter (eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter)8 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)7 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)7 Test (org.junit.Test)7 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)6 IcException (eu.bcvsolutions.idm.ic.exception.IcException)6 IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)5 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)4 IcUidAttributeImpl (eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl)4 UUID (java.util.UUID)4 IcConnectorObjectImpl (eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl)3 IcObjectClassImpl (eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl)3 ArrayList (java.util.ArrayList)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)2 BasicVirtualConfiguration (eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConfiguration)2