use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class CorrelationConfirmationEvaluator method matchUserCorrelationRule.
public <F extends FocusType> boolean matchUserCorrelationRule(Class<F> focusType, PrismObject<ShadowType> currentShadow, PrismObject<F> userType, ObjectSynchronizationType synchronization, ResourceType resourceType, SystemConfigurationType configurationType, Task task, OperationResult result) {
if (synchronization == null) {
LOGGER.warn("Resource does not support synchronization. Skipping evaluation correlation/confirmation for {} and {}", userType, currentShadow);
return false;
}
List<ConditionalSearchFilterType> conditionalFilters = synchronization.getCorrelation();
try {
for (ConditionalSearchFilterType conditionalFilter : conditionalFilters) {
if (matchUserCorrelationRule(focusType, currentShadow, userType, resourceType, configurationType, conditionalFilter, task, result)) {
LOGGER.debug("SYNCHRONIZATION: CORRELATION: expression for {} match user: {}", currentShadow, userType);
return true;
}
}
} catch (SchemaException ex) {
throw new SystemException("Failed to match user using correlation rule. " + ex.getMessage(), ex);
}
LOGGER.debug("SYNCHRONIZATION: CORRELATION: expression for {} does not match user: {}", new Object[] { currentShadow, userType });
return false;
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class CorrelationConfirmationEvaluator method findUsersByCorrelationRule.
private <F extends FocusType> List<PrismObject<F>> findUsersByCorrelationRule(Class<F> focusType, ShadowType currentShadow, ConditionalSearchFilterType conditionalFilter, ResourceType resourceType, SystemConfigurationType configurationType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
if (!conditionalFilter.containsFilterClause()) {
LOGGER.warn("Correlation rule for resource '{}' doesn't contain filter clause, " + "returning empty list of users.", resourceType);
return null;
}
ObjectQuery q;
try {
q = QueryJaxbConvertor.createObjectQuery(focusType, conditionalFilter, prismContext);
q = updateFilterWithAccountValues(currentShadow, resourceType, configurationType, q, "Correlation expression", task, result);
if (q == null) {
// to null and the processing should be skipped
return null;
}
} catch (SchemaException ex) {
LoggingUtils.logException(LOGGER, "Couldn't convert query (simplified)\n{}.", ex, SchemaDebugUtil.prettyPrint(conditionalFilter));
throw new SchemaException("Couldn't convert query.", ex);
} catch (ObjectNotFoundException ex) {
LoggingUtils.logException(LOGGER, "Couldn't convert query (simplified)\n{}.", ex, SchemaDebugUtil.prettyPrint(conditionalFilter));
throw new ObjectNotFoundException("Couldn't convert query.", ex);
} catch (ExpressionEvaluationException ex) {
LoggingUtils.logException(LOGGER, "Couldn't convert query (simplified)\n{}.", ex, SchemaDebugUtil.prettyPrint(conditionalFilter));
throw new ExpressionEvaluationException("Couldn't convert query.", ex);
}
List<PrismObject<F>> users;
try {
LOGGER.trace("SYNCHRONIZATION: CORRELATION: expression for results in filter\n{}", q.debugDumpLazily());
users = repositoryService.searchObjects(focusType, q, null, result);
} catch (RuntimeException ex) {
LoggingUtils.logException(LOGGER, "Couldn't search users in repository, based on filter (simplified)\n{}.", ex, q.debugDump());
throw new SystemException("Couldn't search users in repository, based on filter (See logs).", ex);
}
return users;
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class CorrelationConfirmationEvaluator method findUserByConfirmationRule.
public <F extends FocusType> List<PrismObject<F>> findUserByConfirmationRule(Class<F> focusType, List<PrismObject<F>> users, ShadowType currentShadow, ResourceType resource, SystemConfigurationType configuration, ExpressionType expression, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
List<PrismObject<F>> list = new ArrayList<PrismObject<F>>();
for (PrismObject<F> user : users) {
try {
F userType = user.asObjectable();
boolean confirmedUser = evaluateConfirmationExpression(focusType, userType, currentShadow, resource, configuration, expression, task, result);
if (confirmedUser) {
list.add(user);
}
} catch (RuntimeException ex) {
LoggingUtils.logException(LOGGER, "Couldn't confirm user {}", ex, user.getElementName());
throw new SystemException("Couldn't confirm user " + user.getElementName(), ex);
} catch (ExpressionEvaluationException ex) {
LoggingUtils.logException(LOGGER, "Couldn't confirm user {}", ex, user.getElementName());
throw new ExpressionEvaluationException("Couldn't confirm user " + user.getElementName(), ex);
} catch (ObjectNotFoundException ex) {
LoggingUtils.logException(LOGGER, "Couldn't confirm user {}", ex, user.getElementName());
throw new ObjectNotFoundException("Couldn't confirm user " + user.getElementName(), ex);
} catch (SchemaException ex) {
LoggingUtils.logException(LOGGER, "Couldn't confirm user {}", ex, user.getElementName());
throw new SchemaException("Couldn't confirm user " + user.getElementName(), ex);
}
}
LOGGER.debug("SYNCHRONIZATION: CONFIRMATION: expression for {} matched {} users.", new Object[] { currentShadow, list.size() });
return list;
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class UserProfileServiceImpl method getPrincipal.
@Override
public MidPointPrincipal getPrincipal(String username) throws ObjectNotFoundException, SchemaException {
OperationResult result = new OperationResult(OPERATION_GET_PRINCIPAL);
PrismObject<UserType> user;
try {
user = findByUsername(username, result);
} catch (ObjectNotFoundException ex) {
LOGGER.trace("Couldn't find user with name '{}', reason: {}.", username, ex.getMessage(), ex);
throw ex;
} catch (Exception ex) {
LOGGER.warn("Error getting user with name '{}', reason: {}.", username, ex.getMessage(), ex);
throw new SystemException(ex.getMessage(), ex);
}
return createPrincipal(user, result);
}
use of com.evolveum.midpoint.util.exception.SystemException in project midpoint by Evolveum.
the class MidpointAbstractProvider method readFrom.
@Override
public T readFrom(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
if (entityStream == null) {
return null;
}
PrismParser parser = getParser(entityStream);
T object;
try {
LOGGER.info("type of request: {}", type);
if (PrismObject.class.isAssignableFrom(type)) {
object = (T) parser.parse();
} else {
// TODO consider prescribing type here (if no convertor is specified)
object = parser.parseRealValue();
}
if (object != null && !type.isAssignableFrom(object.getClass())) {
// TODO treat multivalues here
Optional<Annotation> convertorAnnotation = Arrays.stream(annotations).filter(a -> a instanceof Convertor).findFirst();
if (convertorAnnotation.isPresent()) {
Class<? extends ConvertorInterface> convertorClass = ((Convertor) convertorAnnotation.get()).value();
ConvertorInterface convertor;
try {
convertor = convertorClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new SystemException("Couldn't instantiate convertor class " + convertorClass, e);
}
object = (T) convertor.convert(object);
}
}
return object;
} catch (SchemaException ex) {
throw new WebApplicationException(ex);
}
}
Aggregations