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();
}
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));
}
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;
}
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);
});
}
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());
}
Aggregations