Search in sources :

Example 1 with IdmProfileDto

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);
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) SysProvisioningOperationFilter(eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter) SysProvisioningArchiveDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningArchiveDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 2 with IdmProfileDto

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);
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) ResponseEntity(org.springframework.http.ResponseEntity) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with IdmProfileDto

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);
}
Also used : IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ZonedDateTime(java.time.ZonedDateTime) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) Map(java.util.Map) IdmIdentityFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmIdentityFormValue) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) Assert.fail(org.junit.Assert.fail) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Serializable(java.io.Serializable) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) List(java.util.List) IdmAuthenticationException(eu.bcvsolutions.idm.core.security.api.exception.IdmAuthenticationException) RevisionType(org.hibernate.envers.RevisionType) IdmAuditService(eu.bcvsolutions.idm.core.api.audit.service.IdmAuditService) Assert.assertFalse(org.junit.Assert.assertFalse) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallback(org.springframework.transaction.support.TransactionCallback) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmProfile(eu.bcvsolutions.idm.core.model.entity.IdmProfile) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) IdmContractGuarantee(eu.bcvsolutions.idm.core.model.entity.IdmContractGuarantee) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) Lists(com.google.common.collect.Lists) BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) IdmAuditEntityDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditEntityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AuthenticationManager(eu.bcvsolutions.idm.core.security.api.authentication.AuthenticationManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) Assert.assertNull(org.junit.Assert.assertNull) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuditFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter) IdmIdentity_(eu.bcvsolutions.idm.core.model.entity.IdmIdentity_) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) Transactional(org.springframework.transaction.annotation.Transactional) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) IdmAuditFilter(eu.bcvsolutions.idm.core.api.audit.dto.filter.IdmAuditFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with IdmProfileDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) HashMap(java.util.HashMap) TwoFactorRegistrationResponseDto(eu.bcvsolutions.idm.core.security.api.dto.TwoFactorRegistrationResponseDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 5 with IdmProfileDto

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;
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto)

Aggregations

IdmProfileDto (eu.bcvsolutions.idm.core.api.dto.IdmProfileDto)32 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)22 Test (org.junit.Test)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)6 ApiOperation (io.swagger.annotations.ApiOperation)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 IdmProfileFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmProfileFilter)5 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)5 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 ResponseEntity (org.springframework.http.ResponseEntity)5 Transactional (org.springframework.transaction.annotation.Transactional)4 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)3 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)3 EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)3