Search in sources :

Example 6 with IdmIdentity

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.

the class UsernameIdentityFilterIntegrationTest method testFilteringFound.

@Test
public void testFilteringFound() {
    String username = getHelper().createName();
    IdmIdentityDto identityOne = getHelper().createIdentity(username);
    IdmIdentityDto identityTwo = getHelper().createIdentity(getHelper().createName() + username + getHelper().createName());
    IdmIdentityDto identityThree = getHelper().createIdentity(getHelper().createName() + username + getHelper().createName());
    IdmIdentityFilter filter = new IdmIdentityFilter();
    filter.setUsername(username);
    List<IdmIdentity> identities = usernameIdentityFilter.find(filter, null).getContent();
    assertEquals(3, identities.size());
    IdmIdentity identity = identities.stream().filter(ident -> ident.getId().equals(identityOne.getId())).findFirst().get();
    assertNotNull(identity);
    identity = identities.stream().filter(ident -> ident.getId().equals(identityTwo.getId())).findFirst().get();
    assertNotNull(identity);
    identity = identities.stream().filter(ident -> ident.getId().equals(identityThree.getId())).findFirst().get();
    assertNotNull(identity);
}
Also used : List(java.util.List) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) Assert.assertNotNull(org.junit.Assert.assertNotNull) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 7 with IdmIdentity

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.

the class UsernameIdentityFilterIntegrationTest method testFilteringNotFound.

@Test
public void testFilteringNotFound() {
    String username = "usernameValue" + System.currentTimeMillis();
    getHelper().createIdentity(username);
    getHelper().createIdentity("123" + username + getHelper().createName());
    getHelper().createIdentity(getHelper().createName() + username + getHelper().createName());
    IdmIdentityFilter filter = new IdmIdentityFilter();
    // value is different than variable username
    filter.setUsername("username1Value");
    List<IdmIdentity> identities = usernameIdentityFilter.find(filter, null).getContent();
    assertEquals(0, identities.size());
}
Also used : IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 8 with IdmIdentity

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.

the class IdmIdentityController method findRevision.

@ResponseBody
@RequestMapping(value = "/{backendId}/revisions/{revId}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.IDENTITY_READ + "')")
@ApiOperation(value = "Identity audit - read revision detail", nickname = "getIdentityRevision", tags = { IdmIdentityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }) })
public ResponseEntity<?> findRevision(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable("backendId") String backendId, @ApiParam(value = "Revision identifier.", required = true) @PathVariable("revId") Long revId) {
    IdmIdentityDto originalEntity = getDto(backendId);
    if (originalEntity == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    // 
    IdmIdentity revisionIdentity;
    try {
        revisionIdentity = this.auditService.findRevision(IdmIdentity.class, originalEntity.getId(), revId);
    } catch (RevisionDoesNotExistException ex) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("revision", revId), ex);
    }
    // FIXME: to dto
    return new ResponseEntity<>(revisionIdentity, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) RevisionDoesNotExistException(org.hibernate.envers.exception.RevisionDoesNotExistException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with IdmIdentity

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.

the class OptimisticLockIntegrationTest method testOptimisticLockException.

@Transactional
@Test(expected = ObjectOptimisticLockingFailureException.class)
public void testOptimisticLockException() {
    IdmIdentity identityOne = identityRepository.findOneByUsername(InitTestDataProcessor.TEST_USER_1);
    entityManager.detach(identityOne);
    IdmIdentity identityTwo = identityRepository.findOneByUsername(InitTestDataProcessor.TEST_USER_1);
    entityManager.detach(identityTwo);
    assertNull(identityOne.getTitleAfter());
    assertNull(identityOne.getTitleBefore());
    assertNull(identityTwo.getTitleAfter());
    assertNull(identityTwo.getTitleBefore());
    identityOne.setTitleAfter("after");
    identityTwo.setTitleBefore("before");
    assertEquals("after", identityOne.getTitleAfter());
    assertNull(identityOne.getTitleBefore());
    assertNull(identityTwo.getTitleAfter());
    assertEquals("before", identityTwo.getTitleBefore());
    saveInNewTransaction(identityOne);
    entityManager.detach(identityOne);
    entityManager.flush();
    assertEquals("after", identityOne.getTitleAfter());
    assertNull(identityOne.getTitleBefore());
    assertNull(identityTwo.getTitleAfter());
    assertEquals("before", identityTwo.getTitleBefore());
    saveInNewTransaction(identityTwo);
}
Also used : 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)

Example 10 with IdmIdentity

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity in project CzechIdMng by bcvsolutions.

the class DefaultEntityEventManagerUnitTest method testPropagatePropertiesOnNotifyIntoChildren.

@Test
public void testPropagatePropertiesOnNotifyIntoChildren() {
    IdmIdentity identity = new IdmIdentity(UUID.randomUUID());
    when(lookupService.getOwnerId(any())).thenReturn(identity.getId());
    // 
    Map<String, Serializable> props = new HashMap<>();
    props.put("one", "valueOne");
    // 
    IdmEntityEventDto entityEvent = manager.prepareEvent(identity, new CoreEvent<>(CoreEventType.CREATE, identity, props));
    // 
    Assert.assertEquals(props.get("one"), entityEvent.getProperties().get("one"));
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmEntityEventDto(eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Aggregations

IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)58 Test (org.junit.Test)44 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)28 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)20 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)18 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)13 Transactional (org.springframework.transaction.annotation.Transactional)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)7 DataFilter (eu.bcvsolutions.idm.core.api.dto.filter.DataFilter)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 IdmIdentityContract (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)5 Assert (org.junit.Assert)5 IdmAuthorityChange (eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange)4 UUID (java.util.UUID)4 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)3 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3