use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class DefaultTestHelper method waitForResult.
@Override
public void waitForResult(Function<String, Boolean> continueFunction, Integer interationWaitMilis, Integer iterationCount) {
int maxCounter = (iterationCount == null) ? 50 : (iterationCount > 300) ? 300 : iterationCount;
int waitTime = interationWaitMilis == null ? 300 : interationWaitMilis;
//
int counter = 0;
while ((continueFunction == null ? true : continueFunction.apply(null)) && (counter < maxCounter)) {
counter++;
try {
Thread.sleep(waitTime);
} catch (InterruptedException ex) {
throw new CoreException(ex);
}
}
;
//
if (continueFunction != null && continueFunction.apply(null)) {
throw new IllegalStateException("Continue function is defined and timeout exceeded before function returned false (~ before complete).");
}
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class DefaultSchedulerManager method find.
@Override
public Page<Task> find(TaskFilter filter, Pageable pageable) {
try {
List<Task> tasks = new ArrayList<>();
// load scheduled tasks
for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(DEFAULT_GROUP_NAME))) {
Task task = getTask(jobKey);
//
if (passFilter(task, filter)) {
tasks.add(task);
}
}
//
// pageable is required internally
Pageable internalPageable;
if (pageable == null) {
internalPageable = PageRequest.of(0, Integer.MAX_VALUE);
} else {
internalPageable = pageable;
}
// apply "naive" sort and pagination
tasks = tasks.stream().sorted((taskOne, taskTwo) -> {
Sort sort = internalPageable.getSort();
if (internalPageable.getSort() == null) {
return 0;
}
int compareAscValue = 0;
boolean asc = true;
// "naive" sort implementation
Order orderForTaskType = sort.getOrderFor(Task.PROPERTY_TASK_TYPE);
if (orderForTaskType != null) {
asc = orderForTaskType.isAscending();
compareAscValue = taskOne.getTaskType().getSimpleName().compareTo(taskTwo.getTaskType().getSimpleName());
}
Order orderForDescription = sort.getOrderFor(Task.PROPERTY_DESCRIPTION);
if (orderForDescription != null) {
asc = orderForDescription.isAscending();
compareAscValue = StringUtils.compare(taskOne.getDescription(), taskTwo.getDescription());
}
Order orderForInstance = sort.getOrderFor(Task.PROPERTY_INSTANCE_ID);
if (orderForInstance != null) {
asc = orderForInstance.isAscending();
compareAscValue = StringUtils.compare(taskOne.getInstanceId(), taskTwo.getInstanceId());
}
//
return asc ? compareAscValue : compareAscValue * -1;
}).collect(Collectors.toList());
// "naive" pagination
int first = internalPageable.getPageNumber() * internalPageable.getPageSize();
int last = internalPageable.getPageSize() + first;
List<Task> taskPage = tasks.subList(first < tasks.size() ? first : tasks.size() > 0 ? tasks.size() - 1 : 0, last < tasks.size() ? last : tasks.size());
//
return new PageImpl<>(taskPage, internalPageable, tasks.size());
} catch (org.quartz.SchedulerException ex) {
throw new CoreException(ex);
}
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class DefaultEntityEventManagerIntergationTest method testNextProcessorIsNotExecutedAfterException.
@Test
public void testNextProcessorIsNotExecutedAfterException() {
EntityEvent<TestContent> event = new CoreEvent<>(CoreEventType.CREATE, new TestContent());
event.getContent().setException(3);
try {
manager.process(event);
} catch (CoreException ex) {
// ok
}
Assert.assertEquals("2", event.getContent().getText());
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class AbstractReadWriteDtoControllerRestTest method testFindByCodeable.
/**
* Test search by external identifier, if DTO implements {@link ExternalIdentifiable}
*
* @throws Exception
*/
@Test
public void testFindByCodeable() {
if (!DataFilter.class.isAssignableFrom(getController().getFilterClass())) {
LOG.warn("Controller [{}] doesn't support DataFilter. Find by codeable will not be tested.", getController().getClass());
return;
}
//
DTO dto = prepareDto();
if (!(dto instanceof Codeable)) {
// ignore test
return;
}
Codeable codeable = (Codeable) dto;
if (StringUtils.isEmpty(codeable.getCode())) {
throw new CoreException("Code has to be set by #prepareDto method, its required by default");
}
//
DTO createdDto = createDto(dto);
// mock dto
createDto(prepareDto());
//
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.set(DataFilter.PARAMETER_CODEABLE_IDENTIFIER, codeable.getCode());
//
List<DTO> results = find(parameters);
//
Assert.assertEquals(1, results.size());
Assert.assertEquals(createdDto.getId(), results.get(0).getId());
//
if (supportsAutocomplete()) {
results = autocomplete(parameters);
//
Assert.assertEquals(1, results.size());
Assert.assertEquals(createdDto.getId(), results.get(0).getId());
} else {
LOG.info("Controller [{}] doesn't support autocomplete method. Method will not be tested.", getController().getClass());
}
//
Assert.assertEquals(1, count(parameters));
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class AdUserConnectorType method getCertificateFromAD.
/**
* Try to find authority for this certificate in AD (we want to return certificate with the biggest validity).
*/
private X509Certificate getCertificateFromAD(X509Certificate serverCrt, String port, String host, String user, String password) {
X509Certificate resultCertificate = null;
DirContext ldapContext = null;
try {
// Init LDAP context.
Hashtable<String, String> ldapEnv = getAdEnvironment(host, "389", user, password, false);
ldapContext = new InitialDirContext(ldapEnv);
boolean continueSearching = true;
resultCertificate = serverCrt;
while (continueSearching) {
X509Certificate authorityCrtOnAD = findAuthorityCrtOnAD(resultCertificate, ldapContext);
if (authorityCrtOnAD != null) {
// Validate certificate by found authority.
try {
CertificateUtils.verifyCertificate(resultCertificate, authorityCrtOnAD);
} catch (CertificateException ex) {
throw new ResultCodeException(AccResultCode.WIZARD_AD_CONNECTOR_CRT_NOT_TRUSTED, ImmutableMap.of("serialNumber", authorityCrtOnAD.getSerialNumber().toString(16).toUpperCase()), ex);
}
}
if (authorityCrtOnAD == null) {
// No authority certificate was found, previous certificate is result.
continueSearching = false;
} else if (authorityCrtOnAD.getIssuerDN() != null && resultCertificate.getIssuerDN() != null && resultCertificate.getIssuerDN().getName().equals(authorityCrtOnAD.getIssuerDN().getName())) {
// Issuer name in previous and returned authority certificate is same -> returned certificate is result.
resultCertificate = authorityCrtOnAD;
continueSearching = false;
} else if (authorityCrtOnAD.getIssuerDN() == null || Strings.isBlank(authorityCrtOnAD.getIssuerDN().getName())) {
// Found authority certificate doesn't have issuer -> it is result.
resultCertificate = authorityCrtOnAD;
continueSearching = false;
} else {
// Next round.
resultCertificate = authorityCrtOnAD;
}
}
} catch (CommunicationException ex) {
throw new ResultCodeException(AccResultCode.WIZARD_AD_COMMUNICATION_EXCEPTION, ImmutableMap.of("host", host), ex);
} catch (NamingException ex) {
throw new ResultCodeException(AccResultCode.WIZARD_AD_OPERATION_FAILED, ImmutableMap.of("dn", serverCrt != null ? serverCrt.getSubjectDN().getName() : host), ex);
} catch (CertificateException ex) {
throw new CoreException(ex.getLocalizedMessage(), ex);
} finally {
if (ldapContext != null) {
try {
ldapContext.close();
} catch (NamingException e) {
// Only log it.
LOG.error(e.getLocalizedMessage(), e);
}
}
}
return resultCertificate;
}
Aggregations