use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProhibitedValueItemType in project midpoint by Evolveum.
the class ValuePolicyProcessor method testProhibitedValues.
private StringLimitationResult testProhibitedValues(String newPassword, ProhibitedValuesType prohibitedValuesType, ObjectBasedValuePolicyOriginResolver<?> originResolver, String shortDesc, Task task, OperationResult result, List<LocalizableMessage> messages) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
if (prohibitedValuesType == null || originResolver == null) {
return null;
}
StringLimitationResult limitation = new StringLimitationResult();
PolyStringType name = new PolyStringType("prohibited value");
PolyStringTranslationType translation = new PolyStringTranslationType();
translation.setKey("ValuePolicy.prohibitedValueName");
name.setTranslation(translation);
limitation.setName(name);
PolyStringType help = new PolyStringType("");
PolyStringTranslationType helpTranslation = new PolyStringTranslationType();
helpTranslation.setKey("ValuePolicy.prohibitedValue");
help.setTranslation(helpTranslation);
limitation.setHelp(help);
limitation.setSuccess(true);
Consumer<ProhibitedValueItemType> failAction = (prohibitedItemType) -> {
LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.prohibitedValue").build();
result.addSubresult(new OperationResult("Prohibited value", OperationResultStatus.FATAL_ERROR, msg));
messages.add(msg);
limitation.setSuccess(false);
};
checkProhibitedValues(newPassword, prohibitedValuesType, originResolver, failAction, shortDesc, task, result);
return limitation;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProhibitedValueItemType in project midpoint by Evolveum.
the class ValuePolicyProcessor method checkProhibitedValues.
private <O extends ObjectType, R extends ObjectType> boolean checkProhibitedValues(String newPassword, ProhibitedValuesType prohibitedValuesType, ObjectBasedValuePolicyOriginResolver<O> originResolver, Consumer<ProhibitedValueItemType> failAction, String shortDesc, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
if (prohibitedValuesType == null || originResolver == null) {
return true;
}
MutableBoolean isAcceptable = new MutableBoolean(true);
for (ProhibitedValueItemType prohibitedItemType : prohibitedValuesType.getItem()) {
ItemPathType itemPathType = prohibitedItemType.getPath();
if (itemPathType == null) {
throw new SchemaException("No item path defined in prohibited item in " + shortDesc);
}
ItemPath itemPath = itemPathType.getItemPath();
ResultHandler<R> handler = (object, objectResult) -> {
PrismProperty<Object> objectProperty = object.findProperty(itemPath);
if (objectProperty == null) {
return true;
}
if (isMatching(newPassword, objectProperty)) {
if (failAction != null) {
failAction.accept(prohibitedItemType);
}
isAcceptable.setValue(false);
return false;
}
return true;
};
originResolver.resolve(prohibitedItemType, handler, shortDesc, task, result);
}
return isAcceptable.booleanValue();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProhibitedValueItemType in project midpoint by Evolveum.
the class AbstractValuePolicyOriginResolver method handleProjections.
private <P extends ObjectType> void handleProjections(ResultHandler<P> handler, ProhibitedValueItemType prohibitedValueItemType, String contextDescription, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
// Not very efficient. We will usually read the shadows again, as they are already in model context.
// It will also work only for the items that are stored in shadow (usually not attributes, unless caching is enabled).
// But this is good enough for now.
FocusType focus;
if (object.canRepresent(FocusType.class)) {
focus = (FocusType) object.asObjectable();
} else if (object.canRepresent(ShadowType.class)) {
if (object.getOid() == null) {
// process only provided shadow or do not handle projection?
return;
}
ObjectQuery query = object.getPrismContext().queryFor(FocusType.class).item(FocusType.F_LINK_REF).ref(object.getOid()).maxSize(1).build();
try {
List<PrismObject<FocusType>> objects = objectResolver.searchObjects(FocusType.class, query, createReadOnlyCollection(), task, result);
if (objects.isEmpty()) {
return;
}
focus = MiscUtil.extractSingleton(objects).asObjectable();
} catch (CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
throw new SystemException(e.getMessage(), e);
}
} else {
return;
}
// We want to provide default intent to allow configurators to be a little lazy and skip intent specification.
// Consider changing this if necessary.
ResourceShadowDiscriminator shadowDiscriminator = ResourceShadowDiscriminator.fromResourceShadowDiscriminatorType(prohibitedValueItemType.getProjectionDiscriminator(), true);
for (ObjectReferenceType linkRef : focus.getLinkRef()) {
GetOperationOptions options = GetOperationOptions.createReadOnly();
options.setNoFetch(true);
ShadowType resolvedShadow = objectResolver.resolve(linkRef, ShadowType.class, SelectorOptions.createCollection(options), "resolving projection shadow in " + contextDescription, task, result);
if (shadowDiscriminator != null) {
if (!ShadowUtil.matches(resolvedShadow.asPrismObject(), shadowDiscriminator)) {
LOGGER.trace("Skipping evaluation of projection {} in {} because it does not match discriminator", resolvedShadow, contextDescription);
continue;
}
}
// noinspection unchecked
handler.handle((PrismObject<P>) resolvedShadow.asPrismObject(), result);
}
}
Aggregations