Search in sources :

Example 16 with IdmProfileDto

use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.

the class DefaultTwoFactorAuthenticationManagerIntegrationTest method testRequireTwoFactorAuthenticationNotificationWithoutPassword.

@Test(expected = EntityNotFoundException.class)
public void testRequireTwoFactorAuthenticationNotificationWithoutPassword() {
    // password is needed
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmProfileDto profile = getHelper().createProfile(identity);
    // set without confirm, secret etc.
    profile.setTwoFactorAuthenticationType(TwoFactorAuthenticationType.NOTIFICATION);
    profileService.save(profile);
    // 
    IdmTokenDto token = createToken(identity, false);
    // 
    manager.requireTwoFactorAuthentication(identity.getId(), token.getId());
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 17 with IdmProfileDto

use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.

the class ProfileByIdentityEvaluatorIntegrationTest method testPolicy.

@Test
public void testPolicy() {
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmIdentityDto identityOther = getHelper().createIdentity();
    IdmRoleDto role = getHelper().createRole();
    getHelper().createIdentityRole(identity, role);
    // 
    List<IdmProfileDto> profiles = null;
    IdmProfileDto profile = getHelper().createProfile(identity);
    // other
    getHelper().createProfile(identityOther);
    // check created identity doesn't have compositions
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        profiles = service.find(null, IdmBasePermission.READ).getContent();
        Assert.assertTrue(profiles.isEmpty());
    } finally {
        logout();
    }
    // 
    // create authorization policy - assign to role
    getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.PROFILE, IdmProfile.class, ProfileByIdentityEvaluator.class);
    getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, SelfIdentityEvaluator.class, IdmBasePermission.READ);
    // 
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        // evaluate	access
        profiles = service.find(null, IdmBasePermission.READ).getContent();
        Assert.assertEquals(1, profiles.size());
        Assert.assertEquals(profile.getId(), profiles.get(0).getId());
        // 
        Set<String> permissions = service.getPermissions(profile);
        Assert.assertEquals(1, permissions.size());
        Assert.assertEquals(IdmBasePermission.READ.name(), permissions.iterator().next());
    } finally {
        logout();
    }
    // 
    ConfigurationMap properties = new ConfigurationMap();
    properties.put(ProfileByIdentityEvaluator.PARAMETER_IDENTITY_READ, Boolean.TRUE);
    getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.PROFILE, IdmProfile.class, ProfileByIdentityEvaluator.class, properties);
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        // evaluate	access
        profiles = service.find(null, IdmBasePermission.READ).getContent();
        Assert.assertEquals(1, profiles.size());
        Assert.assertEquals(profile.getId(), profiles.get(0).getId());
        // 
        Set<String> permissions = service.getPermissions(profile);
        Assert.assertEquals(3, permissions.size());
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.CREATE.name())));
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.UPDATE.name())));
    } finally {
        logout();
    }
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SelfIdentityEvaluator(eu.bcvsolutions.idm.core.security.evaluator.identity.SelfIdentityEvaluator) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest) Assert(org.junit.Assert) IdmProfileService(eu.bcvsolutions.idm.core.api.service.IdmProfileService) IdmProfile(eu.bcvsolutions.idm.core.model.entity.IdmProfile) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Example 18 with IdmProfileDto

use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.

the class InitAdminIdentityProcessor method process.

@Override
public EventResult<ModuleDescriptorDto> process(EntityEvent<ModuleDescriptorDto> event) {
    IdmRoleDto adminRole = roleConfiguration.getAdminRole();
    if (adminRole == null) {
        LOG.warn("Admin role is not configured. Admin identity cannot be created, skipping.");
        // 
        return null;
    }
    // 
    // Create admin, if no other valid identity with admin role exists.
    IdmIdentityFilter filter = new IdmIdentityFilter();
    filter.setRoles(Lists.newArrayList(adminRole.getId()));
    filter.setDisabled(Boolean.FALSE);
    long adminCount = identityService.count(filter);
    if (adminCount > 0) {
        LOG.debug("Super admin identities found [{}], were created before. Admin with username [{}] will not be created.", adminCount, ADMIN_USERNAME);
        // 
        return null;
    }
    // 
    // create admin identity
    IdmIdentityDto identityAdmin = new IdmIdentityDto();
    identityAdmin.setUsername(ADMIN_USERNAME);
    identityAdmin.setPassword(new GuardedString(ADMIN_PASSWORD));
    identityAdmin.setLastName("Administrator");
    identityAdmin = identityService.save(identityAdmin);
    // 
    // set never expires to identity password
    IdmPasswordDto adminPassword = passwordService.findOneByIdentity(identityAdmin.getId());
    adminPassword.setPasswordNeverExpires(true);
    passwordService.save(adminPassword);
    // 
    LOG.info("Admin identity created [{}]", ADMIN_USERNAME);
    // 
    // set show system information to profile
    IdmProfileDto adminProfile = profileService.findOrCreateByIdentity(identityAdmin.getId());
    adminProfile.setSystemInformation(true);
    profileService.save(adminProfile);
    // 
    // create prime contract (required for assigned role)
    IdmIdentityContractDto contract = identityContractService.getPrimeContract(identityAdmin.getId());
    if (contract == null) {
        contract = identityContractService.prepareMainContract(identityAdmin.getId());
        contract.setValidFrom(null);
        contract.setValidTill(null);
        contract = identityContractService.save(contract);
    }
    // 
    // assign admin role
    IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
    identityRole.setIdentityContract(contract.getId());
    identityRole.setRole(adminRole.getId());
    identityRoleService.save(identityRole);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 19 with IdmProfileDto

use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.

the class DefaultAuditServiceIntegrationTest method testProfileOwner.

@Test
public void testProfileOwner() {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmProfileDto profile = getHelper().createProfile(identity);
    // 
    IdmAuditFilter filter = new IdmAuditFilter();
    filter.setOwnerId(identity.getId().toString());
    filter.setType(IdmProfile.class.getCanonicalName());
    // 
    List<IdmAuditDto> revisions = auditService.find(filter, null).getContent();
    Assert.assertEquals(1, revisions.size());
    Assert.assertEquals(RevisionType.ADD.name(), revisions.get(0).getModification());
    Assert.assertEquals(profile.getId(), revisions.get(0).getEntityId());
    // 
    // non transactional test => cleanup
    identityService.delete(identity);
}
Also used : IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) IdmProfile(eu.bcvsolutions.idm.core.model.entity.IdmProfile) 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 20 with IdmProfileDto

use of eu.bcvsolutions.idm.core.api.dto.IdmProfileDto in project CzechIdMng by bcvsolutions.

the class IdmIdentityControllerRestTest method testUploadProfile.

@Test
public void testUploadProfile() throws UnsupportedEncodingException, IOException, Exception {
    IdmIdentityDto owner = getHelper().createIdentity((GuardedString) null);
    // 
    String fileName = "file.png";
    String content = "some image";
    String response = getMockMvc().perform(MockMvcRequestBuilders.multipart(getDetailUrl(owner.getId()) + "/profile/image").file(new MockMultipartFile("data", fileName, "image/png", IOUtils.toByteArray(IOUtils.toInputStream(content)))).param("fileName", fileName).with(authentication(getAdminAuthentication()))).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
    IdmProfileDto createdProfile = (IdmProfileDto) getMapper().readValue(response, IdmProfileDto.class);
    // 
    Assert.assertNotNull(createdProfile);
    Assert.assertNotNull(createdProfile.getId());
    Assert.assertNotNull(createdProfile.getImage());
    IdmAttachmentDto image = attachmentManager.get(createdProfile.getImage());
    Assert.assertEquals(content.length(), image.getFilesize().intValue());
    Assert.assertEquals(createdProfile.getId(), image.getOwnerId());
    Assert.assertEquals(attachmentManager.getOwnerType(createdProfile), image.getOwnerType());
    Assert.assertEquals(fileName, image.getName());
    InputStream is = attachmentManager.getAttachmentData(image.getId());
    try {
        Assert.assertEquals(content, IOUtils.toString(is));
    } finally {
        IOUtils.closeQuietly(is);
    }
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) InputStream(java.io.InputStream) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

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