use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.
the class ProfileProvisioningProcessorIntegrationTest method testProvisioningAfterProfileIsSaved.
@Test
public void testProvisioningAfterProfileIsSaved() {
SysSystemDto system = getHelper().createTestResourceSystem(true);
//
// check before
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemId(system.getId());
List<SysProvisioningArchiveDto> content = provisioningArchiveService.find(filter, null).getContent();
Assert.assertTrue(content.isEmpty());
//
// create identity
IdmIdentityDto identity = getHelper().createIdentity();
getHelper().createIdentityAccount(system, identity);
//
// save identity with account, invoke provisioning = create
identity = identityService.save(identity);
//
content = provisioningArchiveService.find(filter, null).getContent();
Assert.assertEquals(1, content.size());
SysProvisioningArchiveDto sysProvisioningArchiveDto = content.get(0);
Assert.assertEquals(ProvisioningEventType.CREATE, sysProvisioningArchiveDto.getOperationType());
Assert.assertEquals(SystemEntityType.IDENTITY, sysProvisioningArchiveDto.getEntityType());
Assert.assertEquals(identity.getId(), sysProvisioningArchiveDto.getEntityIdentifier());
//
IdmProfileDto profile = getHelper().createProfile(identity);
//
// check after create profile - without image
content = provisioningArchiveService.find(filter, null).getContent();
Assert.assertEquals(1, content.size());
//
IdmAttachmentDto attachment = new IdmAttachmentDto();
attachment.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachment.setName("name-" + UUID.randomUUID());
attachment.setMimetype(AttachableEntity.DEFAULT_MIMETYPE);
attachment.setEncoding(AttachableEntity.DEFAULT_ENCODING);
attachment.setVersionNumber(1);
attachment.setVersionLabel("1.0");
attachment.setContentId(UUID.randomUUID());
attachment.setContentPath("mock");
attachment.setFilesize(1L);
attachment.setInputData(IOUtils.toInputStream("mock"));
attachment = attachmentManager.saveAttachment(profile, attachment);
profile.setImage(attachment.getId());
profile = profileService.save(profile);
//
content = provisioningArchiveService.find(filter, null).getContent();
Assert.assertEquals(2, content.size());
sysProvisioningArchiveDto = content.stream().max(Comparator.comparing(SysProvisioningArchiveDto::getCreated)).orElse(null);
Assert.assertEquals(ProvisioningEventType.UPDATE, sysProvisioningArchiveDto.getOperationType());
Assert.assertEquals(SystemEntityType.IDENTITY, sysProvisioningArchiveDto.getEntityType());
Assert.assertEquals(identity.getId(), sysProvisioningArchiveDto.getEntityIdentifier());
//
attachment = new IdmAttachmentDto();
attachment.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachment.setName("name-" + UUID.randomUUID());
attachment.setMimetype(AttachableEntity.DEFAULT_MIMETYPE);
attachment.setEncoding(AttachableEntity.DEFAULT_ENCODING);
attachment.setVersionNumber(1);
attachment.setVersionLabel("1.0");
attachment.setContentId(UUID.randomUUID());
attachment.setContentPath("mock");
attachment.setFilesize(1L);
attachment.setInputData(IOUtils.toInputStream("mock"));
attachment = attachmentManager.saveAttachment(profile, attachment);
profile.setImage(attachment.getId());
profile = profileService.save(profile);
content = provisioningArchiveService.find(filter, null).getContent();
Assert.assertEquals(3, content.size());
sysProvisioningArchiveDto = content.stream().max(Comparator.comparing(SysProvisioningArchiveDto::getCreated)).orElse(null);
Assert.assertEquals(ProvisioningEventType.UPDATE, sysProvisioningArchiveDto.getOperationType());
Assert.assertEquals(SystemEntityType.IDENTITY, sysProvisioningArchiveDto.getEntityType());
Assert.assertEquals(identity.getId(), sysProvisioningArchiveDto.getEntityIdentifier());
//
profile.setImage(null);
profile = profileService.save(profile);
content = provisioningArchiveService.find(filter, null).getContent();
Assert.assertEquals(4, content.size());
sysProvisioningArchiveDto = content.stream().max(Comparator.comparing(SysProvisioningArchiveDto::getCreated)).orElse(null);
Assert.assertEquals(ProvisioningEventType.UPDATE, sysProvisioningArchiveDto.getOperationType());
Assert.assertEquals(SystemEntityType.IDENTITY, sysProvisioningArchiveDto.getEntityType());
Assert.assertEquals(identity.getId(), sysProvisioningArchiveDto.getEntityIdentifier());
//
profile.setImage(attachment.getId());
profile = profileService.save(profile);
profileService.delete(profile);
content = provisioningArchiveService.find(filter, null).getContent();
Assert.assertEquals(6, content.size());
sysProvisioningArchiveDto = content.stream().max(Comparator.comparing(SysProvisioningArchiveDto::getCreated)).orElse(null);
Assert.assertEquals(ProvisioningEventType.UPDATE, sysProvisioningArchiveDto.getOperationType());
Assert.assertEquals(SystemEntityType.IDENTITY, sysProvisioningArchiveDto.getEntityType());
Assert.assertEquals(identity.getId(), sysProvisioningArchiveDto.getEntityIdentifier());
//
identityService.delete(identity);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.
the class IdmProfileController method twoFactorConfirm.
@ResponseBody
@ApiOperation(value = "Login - additional two factor authentication confirm", notes = "Additional two factor authentication with TOTP verification code.", response = IdmProfileDto.class, tags = { IdmProfileController.TAG })
@RequestMapping(path = "/{backendId}/two-factor/confirm", method = RequestMethod.PUT)
public ResponseEntity<?> twoFactorConfirm(@ApiParam(value = "Profile's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Verification secret and code.", required = true) @Valid @RequestBody(required = true) TwoFactorRegistrationConfirmDto registrationConfirm) {
IdmProfileDto dto = getDto(backendId);
if (dto == null) {
throw new EntityNotFoundException(getService().getEntityClass(), backendId);
}
//
twoFactorAuthenticationManager.confirm(dto.getIdentity(), registrationConfirm);
//
return new ResponseEntity<>(toResource(getDto(dto)), HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.
the class DefaultAuditServiceIntegrationTest method testFindByTypes.
@Test
public void testFindByTypes() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmProfileDto profile = getHelper().createProfile(identity);
//
IdmAuditFilter filter = new IdmAuditFilter();
filter.setRelatedOwnerId(identity.getId());
filter.setTypes(Lists.newArrayList(IdmProfile.class.getCanonicalName(), IdmIdentity.class.getCanonicalName()));
//
List<IdmAuditDto> revisions = auditService.find(filter, null).getContent();
Assert.assertEquals(2, revisions.size());
Assert.assertEquals(RevisionType.ADD.name(), revisions.get(0).getModification());
Assert.assertTrue(revisions.stream().anyMatch(r -> r.getEntityId().equals(profile.getId())));
Assert.assertTrue(revisions.stream().anyMatch(r -> r.getEntityId().equals(identity.getId())));
//
// non transactional test => cleanup
identityService.delete(identity);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.
the class LoginControllerRestTest method testChangePasswordWithTwoFactorLogin.
@Test
public void testChangePasswordWithTwoFactorLogin() throws Exception {
IdmIdentityDto identity = getHelper().createIdentity();
IdmProfileDto profile = getHelper().createProfile(identity);
IdmRoleDto role = getHelper().createRole();
getHelper().createIdentityRole(identity, role);
getHelper().createBasePolicy(role.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.READ);
// login
Map<String, String> login = new HashMap<>();
login.put("username", identity.getUsername());
login.put("password", identity.getPassword().asString());
String response = getMockMvc().perform(post(BaseController.BASE_PATH + LoginController.AUTH_PATH).content(serialize(login)).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
String token = getToken(response);
//
// init two factor authentication by profile controller
response = getMockMvc().perform(put(BaseController.BASE_PATH + "/profiles/" + profile.getId() + "/two-factor/init").param(IdmAuthenticationFilter.AUTHENTICATION_TOKEN_NAME, token).param("twoFactorAuthenticationType", TwoFactorAuthenticationType.APPLICATION.name()).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
TwoFactorRegistrationResponseDto twoFactorInit = getMapper().readValue(response, TwoFactorRegistrationResponseDto.class);
Assert.assertNotNull(twoFactorInit);
Assert.assertNotNull(twoFactorInit.getVerificationSecret());
//
// confirm two factor authentication by profile controller
Map<String, String> twoFactorConfirm = new HashMap<>();
twoFactorConfirm.put("verificationCode", twoFactorAuthenticationManager.generateCode(new GuardedString(twoFactorInit.getVerificationSecret())).asString());
twoFactorConfirm.put("verificationSecret", twoFactorInit.getVerificationSecret());
twoFactorConfirm.put("twoFactorAuthenticationType", TwoFactorAuthenticationType.APPLICATION.name());
response = getMockMvc().perform(put(BaseController.BASE_PATH + "/profiles/" + profile.getId() + "/two-factor/confirm").param(IdmAuthenticationFilter.AUTHENTICATION_TOKEN_NAME, token).content(serialize(twoFactorConfirm)).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
IdmProfileDto updatedProfile = getMapper().readValue(response, IdmProfileDto.class);
Assert.assertNotNull(updatedProfile);
Assert.assertEquals(TwoFactorAuthenticationType.APPLICATION, updatedProfile.getTwoFactorAuthenticationType());
//
// set password must change
IdmPasswordDto password = getHelper().getPassword(identity);
password.setMustChange(true);
passwordService.save(password);
//
// change password
Map<String, String> passwordChange = new HashMap<>();
passwordChange.put("oldPassword", identity.getPassword().asString());
String newPassword = getHelper().createName();
passwordChange.put("newPassword", newPassword);
passwordChange.put("idm", Boolean.TRUE.toString());
getMockMvc().perform(put(BaseController.BASE_PATH + "/public/identities/" + identity.getId() + "/password-change").content(serialize(passwordChange)).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.
the class ProfileProvisioningProcessor method conditional.
@Override
public boolean conditional(EntityEvent<IdmProfileDto> event) {
if (!super.conditional(event)) {
return false;
}
if (this.getBooleanProperty(IdmAccountDto.SKIP_PROPAGATE, event.getProperties())) {
return false;
}
IdmProfileDto originalSource = event.getOriginalSource();
IdmProfileDto profile = event.getContent();
// profile was added with image is defined
if (originalSource == null && profile.getImage() != null) {
return true;
}
// profile was deleted with image is defined
if (event.hasType(ProfileEventType.DELETE) && profile.getImage() != null) {
return true;
}
// image is changed
if (originalSource != null && !Objects.equals(originalSource.getImage(), profile.getImage())) {
return true;
}
// image is not changed - provisioning is not needed.
return false;
}
Aggregations