Search in sources :

Example 1 with IdmTokenFilter

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

the class DefaultTokenManager method getTokens.

@Override
public List<IdmTokenDto> getTokens(Identifiable owner, BasePermission... permission) {
    Assert.notNull(owner, "Owner is required.");
    Assert.notNull(owner.getId(), "Owner identifier is required.");
    // 
    IdmTokenFilter filter = new IdmTokenFilter();
    filter.setOwnerType(getOwnerType(owner.getClass()));
    filter.setOwnerId(getOwnerId(owner));
    // 
    return tokenService.find(filter, PageRequest.of(0, Integer.MAX_VALUE, new Sort(Direction.ASC, IdmToken_.expiration.getName())), permission).getContent();
}
Also used : IdmTokenFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTokenFilter) Sort(org.springframework.data.domain.Sort)

Example 2 with IdmTokenFilter

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

the class IdmTokenControllerRestTest method testFindByDisabled.

@Test
public void testFindByDisabled() {
    UUID mockOwnerId = UUID.randomUUID();
    // 
    IdmTokenDto tokenOne = prepareDto();
    tokenOne.setOwnerId(mockOwnerId);
    tokenOne.setDisabled(true);
    tokenOne = createDto(tokenOne);
    IdmTokenDto tokenTwo = prepareDto();
    tokenTwo.setOwnerId(mockOwnerId);
    tokenTwo.setDisabled(false);
    tokenTwo = createDto(tokenTwo);
    // 
    IdmTokenFilter filter = new IdmTokenFilter();
    filter.setOwnerId(mockOwnerId);
    filter.setDisabled(true);
    List<IdmTokenDto> results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(tokenOne, results.get(0));
    // 
    filter.setDisabled(false);
    results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(tokenTwo, results.get(0));
}
Also used : IdmTokenFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTokenFilter) IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) UUID(java.util.UUID) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 3 with IdmTokenFilter

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

the class IdmTokenController method toFilter.

@Override
protected IdmTokenFilter toFilter(MultiValueMap<String, Object> parameters) {
    IdmTokenFilter filter = new IdmTokenFilter(parameters, getParameterConverter());
    // owner decorator
    String ownerId = getParameterConverter().toString(parameters, IdmEntityEventFilter.PARAMETER_OWNER_ID);
    UUID ownerUuid = null;
    String ownerType = filter.getOwnerType();
    if (StringUtils.isNotEmpty(ownerType) && StringUtils.isNotEmpty(ownerId)) {
        // try to find entity owner by Codeable identifier
        AbstractDto owner = manager.findOwner(ownerType, ownerId);
        if (owner != null) {
            ownerUuid = owner.getId();
        } else {
            LOG.debug("Entity type [{}] with identifier [{}] does not found, raw ownerId will be used as uuid.", ownerType, ownerId);
            // Better exception for FE.
            try {
                DtoUtils.toUuid(ownerId);
            } catch (ClassCastException ex) {
                throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", ownerId), ex);
            }
        }
    }
    if (ownerUuid == null) {
        ownerUuid = getParameterConverter().toUuid(parameters, IdmEntityEventFilter.PARAMETER_OWNER_ID);
    }
    filter.setOwnerId(ownerUuid);
    // 
    return filter;
}
Also used : IdmTokenFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTokenFilter) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) UUID(java.util.UUID)

Example 4 with IdmTokenFilter

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

the class DefaultTokenManager method disableTokens.

@Override
@Transactional
public void disableTokens(Identifiable owner, BasePermission... permission) {
    Assert.notNull(owner, "Owner is required.");
    Assert.notNull(owner.getId(), "Owner identifier is required.");
    // 
    IdmTokenFilter filter = new IdmTokenFilter();
    filter.setOwnerType(getOwnerType(owner));
    filter.setOwnerId(getOwnerId(owner));
    filter.setDisabled(Boolean.FALSE);
    // valid tokens only
    filter.setExpirationFrom(ZonedDateTime.now());
    // 
    tokenService.find(filter, // permissions are evaluated below, we want to disable all tokens (e.g. referential integrity)
    null).forEach(token -> {
        disableToken(token, permission);
    });
}
Also used : IdmTokenFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTokenFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 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)

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