Search in sources :

Example 46 with GuardedString

use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.

the class SendNotificationToApplicantAndImplementerTest method createStructure.

/**
 * Creates organization's structure and identity testUser2 as manager
 */
private void createStructure() {
    IdmRoleDto superAdminRole = this.roleService.getByCode(InitApplicationData.ADMIN_ROLE);
    IdmTreeNodeDto rootOrganization = treeNodeService.findRoots((UUID) null, new PageRequest(0, 1)).getContent().get(0);
    IdmRoleDto role2 = new IdmRoleDto();
    role2.setName("TestCustomRole002" + System.currentTimeMillis());
    List<IdmRoleCompositionDto> subRoles = new ArrayList<>();
    subRoles.add(new IdmRoleCompositionDto(role2.getId(), superAdminRole.getId()));
    role2.setSubRoles(subRoles);
    role2 = this.roleService.save(role2);
    testUser2 = new IdmIdentityDto();
    testUser2.setUsername("Test_user_Manager" + System.currentTimeMillis());
    testUser2.setPassword(new GuardedString("heslo"));
    testUser2.setFirstName("Test");
    testUser2.setLastName("Second User");
    testUser2.setEmail("test2@bscsolutions.eu");
    testUser2 = this.identityService.save(testUser2);
    IdmTreeTypeDto type = treeTypeService.get(rootOrganization.getTreeType());
    organization = new IdmTreeNodeDto();
    organization.setCode("test" + System.currentTimeMillis());
    organization.setName("Organization Test Notification");
    organization.setParent(rootOrganization.getId());
    organization.setTreeType(type.getId());
    organization = this.treeNodeService.save(organization);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) PageRequest(org.springframework.data.domain.PageRequest) IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) ArrayList(java.util.ArrayList) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 47 with GuardedString

use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.

the class VsReqeustServiceTest method disableRequestTest.

@Test
public void disableRequestTest() {
    SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
    IdmIdentityDto identity = helper.createIdentity(USER_ONE_NAME);
    this.assignRoleSystem(system, identity, 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);
    Assert.assertEquals(Boolean.TRUE, account.isEnable());
    super.logout();
    loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
    // Disable the identity
    identity.setState(IdentityState.DISABLED_MANUALLY);
    identityService.save(identity);
    // Find created requests
    requests = requestService.find(requestFilter, null).getContent().stream().filter(r -> VsRequestState.IN_PROGRESS == r.getState()).collect(Collectors.toList());
    Assert.assertEquals(1, requests.size());
    request = requests.get(0);
    Assert.assertEquals(USER_ONE_NAME, request.getUid());
    Assert.assertEquals(VsOperationType.UPDATE, request.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, request.getState());
    // 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);
    Assert.assertEquals(Boolean.FALSE, account.isEnable());
}
Also used : VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 48 with GuardedString

use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.

the class VsReqeustServiceTest method changeUidTest.

@Test
public void changeUidTest() {
    SysSystemDto system = this.createVirtualSystem(USER_IMPLEMENTER_NAME, null);
    IdmIdentityDto userOne = helper.createIdentity(USER_ONE_NAME);
    identityService.save(userOne);
    this.assignRoleSystem(system, userOne, ROLE_ONE_NAME);
    // Find created requests
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setSystemId(system.getId());
    requestFilter.setUid(USER_ONE_NAME);
    requestFilter.setState(VsRequestState.IN_PROGRESS);
    List<VsRequestDto> requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    VsRequestDto createRequest = requests.get(0);
    Assert.assertEquals(USER_ONE_NAME, createRequest.getUid());
    Assert.assertEquals(VsOperationType.CREATE, createRequest.getOperationType());
    Assert.assertEquals(VsRequestState.IN_PROGRESS, createRequest.getState());
    VsConnectorObjectDto wish = requestService.getWishConnectorObject(createRequest);
    boolean findAttributeWithouChange = wish.getAttributes().stream().filter(attribute -> !attribute.isChanged()).findFirst().isPresent();
    Assert.assertTrue(!findAttributeWithouChange);
    // Change username attributes
    userOne.setUsername(USER_ONE_CHANGED_NAME);
    // Invoke provisioning
    identityService.save(userOne);
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(2, requests.size());
    // We realize the create request
    super.logout();
    loginService.login(new LoginDto(USER_IMPLEMENTER_NAME, new GuardedString("password")));
    requestService.realize(createRequest);
    requests = requestService.find(requestFilter, null).getContent();
    Assert.assertEquals(1, requests.size());
    // get wish
    wish = requestService.getWishConnectorObject(requests.get(0));
    Assert.assertEquals(1, wish.getAttributes().stream().filter(attr -> attr.isChanged()).count());
    // Find change for firstName value
    boolean findCorrectChangedUserName = wish.getAttributes().stream().filter(attr -> attr.getValue().getValue().equals(USER_ONE_CHANGED_NAME) && attr.getValue().getOldValue().equals(USER_ONE_NAME) && VsValueChangeType.UPDATED == attr.getValue().getChange()).findFirst().isPresent();
    Assert.assertTrue(findCorrectChangedUserName);
    SysSystemEntityFilter systemEntityFilter = new SysSystemEntityFilter();
    systemEntityFilter.setSystemId(system.getId());
    systemEntityFilter.setUid(USER_ONE_NAME);
    boolean oldUserNameExist = !systemEntityService.find(systemEntityFilter, null).getContent().isEmpty();
    Assert.assertTrue(oldUserNameExist);
    // Realize change username
    requestService.realize(requests.get(0));
    // We expects change UID in SystemEntity.UID
    oldUserNameExist = !systemEntityService.find(systemEntityFilter, null).getContent().isEmpty();
    Assert.assertTrue(!oldUserNameExist);
    systemEntityFilter.setUid(USER_ONE_CHANGED_NAME);
    boolean changedUserNameExist = !systemEntityService.find(systemEntityFilter, null).getContent().isEmpty();
    Assert.assertTrue(changedUserNameExist);
}
Also used : VsConnectorObjectDto(eu.bcvsolutions.idm.vs.dto.VsConnectorObjectDto) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 49 with GuardedString

use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.

the class VsReqeustServiceTest method systemAccountFilterTest.

@Test
public void systemAccountFilterTest() {
    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);
    IcConnectorConfiguration configuration = systemService.getConnectorConfiguration(system);
    IcObjectClass objectClass = new IcObjectClassImpl("__ACCOUNT__");
    List<String> uids = new ArrayList<>();
    connectorFacade.search(system.getConnectorInstance(), configuration, objectClass, null, new IcResultsHandler() {

        @Override
        public boolean handle(IcConnectorObject connectorObject) {
            uids.add(connectorObject.getUidValue());
            return true;
        }
    });
    Assert.assertEquals(1, uids.size());
    Assert.assertEquals(USER_ONE_NAME, uids.get(0));
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcResultsHandler(eu.bcvsolutions.idm.ic.filter.api.IcResultsHandler) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 50 with GuardedString

use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.

the class DefaultIdmConfidentialStorageIntegrationTest method testReadGuardedString.

@Test
@Transactional
public void testReadGuardedString() {
    IdmIdentity identity = identityRepository.findOneByUsername(InitTestData.TEST_USER_1);
    String password = "heslo";
    confidentalStorage.save(identity.getId(), IdmIdentity.class, STORAGE_KEY_ONE, new GuardedString(password).asString());
    GuardedString savedPassword = confidentalStorage.getGuardedString(identity.getId(), IdmIdentity.class, STORAGE_KEY_ONE);
    assertEquals(password, savedPassword.asString());
}
Also used : GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)97 Test (org.junit.Test)61 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)59 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)49 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)40 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)30 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)26 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)20 ArrayList (java.util.ArrayList)13 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)11 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)11 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)10 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)9 HashMap (java.util.HashMap)9 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)8 Transactional (org.springframework.transaction.annotation.Transactional)8 ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)7 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)7 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)7 List (java.util.List)7