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