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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations