Search in sources :

Example 6 with IdmTokenFilter

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

the class PermissionsAuthorityChangeProcessorTest method testChangePersmissions.

/**
 * Change permissions type for given policy.
 * @throws Exception
 */
@Test
public void testChangePersmissions() throws Exception {
    IdmRoleDto role = getTestRole();
    IdmIdentityDto i = getHelper().createIdentity();
    IdmIdentityContractDto c = getTestContract(i);
    getTestIdentityRole(role, c);
    // 
    IdmTokenFilter filter = new IdmTokenFilter();
    filter.setOwnerType(tokenManager.getOwnerType(i.getClass()));
    filter.setOwnerId(i.getId());
    List<IdmTokenDto> tokens = tokenManager.getTokens(i);
    // 
    Assert.assertTrue(tokens.isEmpty());
    // 
    // login - one token
    getHelper().login(i.getUsername(), i.getPassword());
    try {
        tokens = tokenManager.getTokens(i);
        Assert.assertEquals(1, tokens.size());
        Assert.assertFalse(tokens.get(0).isDisabled());
        // 
        changeAuthorizationPolicyPermissions(role);
        // 
        tokens = tokenManager.getTokens(i);
        Assert.assertEquals(1, tokens.size());
        Assert.assertTrue(tokens.get(0).isDisabled());
    } finally {
        getHelper().logout();
    }
}
Also used : IdmTokenFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTokenFilter) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test)

Example 7 with IdmTokenFilter

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

the class IdmTokenControllerRestTest method testFindByExpirationTill.

@Test
public void testFindByExpirationTill() {
    UUID mockOwnerId = UUID.randomUUID();
    ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
    // 
    IdmTokenDto tokenOne = prepareDto();
    tokenOne.setOwnerId(mockOwnerId);
    tokenOne.setExpiration(now);
    tokenOne = createDto(tokenOne);
    IdmTokenDto tokenTwo = prepareDto();
    tokenTwo.setOwnerId(mockOwnerId);
    tokenTwo.setExpiration(now.plusDays(2));
    tokenTwo = createDto(tokenTwo);
    // 
    IdmTokenFilter filter = new IdmTokenFilter();
    filter.setOwnerId(mockOwnerId);
    filter.setExpirationTill(now);
    List<IdmTokenDto> results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(tokenOne, results.get(0));
    // 
    filter.setExpirationTill(now.plusDays(1));
    results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(tokenOne, results.get(0));
    // 
    filter.setExpirationTill(now.plusDays(2));
    results = find(filter);
    // 
    Assert.assertEquals(2, results.size());
}
Also used : IdmTokenFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTokenFilter) IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 8 with IdmTokenFilter

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

the class IdmTokenControllerRestTest method testFindByOwner.

@Test
public void testFindByOwner() {
    IdmIdentityDto owner = getHelper().createIdentity();
    IdmTokenDto tokenOne = prepareDto();
    tokenOne.setOwnerId(owner.getId());
    String ownerType = tokenManager.getOwnerType(owner);
    tokenOne.setOwnerType(ownerType);
    tokenOne = createDto(tokenOne);
    // other
    createDto();
    // other
    createDto();
    IdmTokenFilter filter = new IdmTokenFilter();
    filter.setOwnerType(ownerType);
    filter.setOwnerId(owner.getId());
    List<IdmTokenDto> results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(tokenOne, results.get(0));
}
Also used : IdmTokenFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTokenFilter) IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Aggregations

IdmTokenFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmTokenFilter)8 IdmTokenDto (eu.bcvsolutions.idm.core.api.dto.IdmTokenDto)5 Test (org.junit.Test)5 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)3 UUID (java.util.UUID)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)2 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)2 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 ZonedDateTime (java.time.ZonedDateTime)1 Sort (org.springframework.data.domain.Sort)1 Transactional (org.springframework.transaction.annotation.Transactional)1