Search in sources :

Example 6 with IdmAuthorityChange

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

the class PermissionsAuthorityChangeProcessorTest method testCreateAuthorityChangeEntity.

/**
 * In case the identity in role does not have IdmAuthorityChange entity
 * relation, changing role's authorities must create one.
 * @throws Exception
 */
@Test
public void testCreateAuthorityChangeEntity() throws Exception {
    IdmRoleDto role = getTestRole();
    IdmIdentityDto i = getTestUser();
    IdmIdentityContractDto c = getTestContract(i);
    getTestIdentityRole(role, c);
    deleteAuthorityChangedEntity(i);
    IdmAuthorityChange ac = acRepository.findOneByIdentity_Id(i.getId());
    Assert.assertNull(ac);
    sleep();
    clearAuthPolicies(role);
    ac = acRepository.findOneByIdentity_Id(i.getId());
    Assert.assertNotNull(ac);
    Assert.assertNotNull(ac.getAuthChangeTimestamp());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorityChange(eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test)

Example 7 with IdmAuthorityChange

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

the class OAuthAuthenticationManager method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    if (!(authentication instanceof IdmJwtAuthentication)) {
        throw new IdmAuthenticationException("Unsupported granted authority " + authentication.getClass().getName());
    }
    IdmJwtAuthentication idmJwtAuthentication = (IdmJwtAuthentication) authentication;
    IdmIdentityDto identity = getIdentityForToken(idmJwtAuthentication);
    IdmAuthorityChange authChange = getIdentityAuthorityChange(identity);
    checkIssuedTime(idmJwtAuthentication.getIssuedAt(), authChange);
    checkExpirationTime(idmJwtAuthentication);
    checkDisabled(identity);
    // Set logged user to workflow engine
    workflowIdentityService.setAuthenticatedUserId(identity.getUsername());
    // set authentication
    securityService.setAuthentication(idmJwtAuthentication);
    // 
    return idmJwtAuthentication;
}
Also used : IdmAuthorityChange(eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange) IdmAuthenticationException(eu.bcvsolutions.idm.core.security.exception.IdmAuthenticationException) IdmJwtAuthentication(eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 8 with IdmAuthorityChange

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

the class IdentityRoleAddAuthoritiesProcessorTest method testAddRoleDoNotModifyAuthorities.

@Test
public void testAddRoleDoNotModifyAuthorities() throws Exception {
    IdmRoleDto role = getTestRole();
    IdmRoleDto role2 = getTestRole();
    IdmIdentityDto i = getTestUser();
    IdmIdentityContractDto c = getTestContract(i);
    IdmAuthorityChange ac = getAuthorityChange(i);
    // user has no authorities - change flag is null
    Assert.assertNull(ac);
    // authority added
    getTestIdentityRole(role, c);
    i = identityService.get(i.getId());
    ac = getAuthorityChange(i);
    DateTime firstChangeTs = ac.getAuthChangeTimestamp();
    Assert.assertNotNull(firstChangeTs);
    Thread.sleep(10);
    getTestIdentityRole(role2, c);
    i = identityService.get(i.getId());
    ac = getAuthorityChange(i);
    Assert.assertEquals(firstChangeTs, ac.getAuthChangeTimestamp());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorityChange(eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 9 with IdmAuthorityChange

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

the class IdentityRoleAddAuthoritiesProcessorTest method testAddRoleModifyAuthorities.

@Test
public void testAddRoleModifyAuthorities() {
    IdmRoleDto role = getTestRole();
    IdmIdentityDto i = getTestUser();
    IdmIdentityContractDto c = getTestContract(i);
    IdmAuthorityChange ac = getAuthorityChange(i);
    // user has no authorities - change flag is null
    Assert.assertNull(ac);
    // authority added
    getTestIdentityRole(role, c);
    i = identityService.get(i.getId());
    ac = getAuthorityChange(i);
    Assert.assertNotNull(ac);
    Assert.assertNotNull(ac.getAuthChangeTimestamp());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorityChange(eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test)

Example 10 with IdmAuthorityChange

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

the class PermissionsAuthorityChangeProcessorTest method testChangePersmissions.

/**
 * Change permissions type for given policy.
 * @throws Exception
 */
@Test
public void testChangePersmissions() throws Exception {
    securityService.setSystemAuthentication();
    IdmRoleDto role = getTestRole();
    IdmIdentityDto i = getTestUser();
    IdmIdentityContractDto c = getTestContract(i);
    getTestIdentityRole(role, c);
    IdmAuthorityChange ac = acRepository.findOneByIdentity_Id(i.getId());
    Assert.assertNotNull(ac);
    Assert.assertNotNull(ac.getAuthChangeTimestamp());
    DateTime origChangeTime = ac.getAuthChangeTimestamp();
    sleep();
    changeAuthorizationPolicyPermissions(role);
    ac = acRepository.findOneByIdentity_Id(i.getId());
    Assert.assertNotNull(ac);
    Assert.assertNotNull(ac.getAuthChangeTimestamp());
    Assert.assertTrue(origChangeTime.getMillis() < ac.getAuthChangeTimestamp().getMillis());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorityChange(eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

IdmAuthorityChange (eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange)16 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 Test (org.junit.Test)10 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)9 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 DateTime (org.joda.time.DateTime)7 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)4 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)4 IdmIdentityContract (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)2 IdmJwtAuthentication (eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 IdmAuthenticationException (eu.bcvsolutions.idm.core.security.exception.IdmAuthenticationException)1 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1