Skip to content

Commit

Permalink
Apply fastAddOperations when parsing trusted data
Browse files Browse the repository at this point in the history
This can be questionable when the schema changes, but in general it
should be worth the (negligible) risk.
  • Loading branch information
mederly committed Apr 27, 2023
1 parent fba1e2c commit 23e237a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -718,21 +718,23 @@ public void consolidate() throws CommunicationException, ObjectNotFoundException

if (!toAdd.isEmpty()) {
PrismValue valueToAdd = equivalenceClass.getRepresentative().clone();
valueToAdd.getValueMetadataAsContainer().clear();
PrismContainer<Containerable> valueMetadataAsContainer = valueToAdd.getValueMetadataAsContainer();
valueMetadataAsContainer.clear();
for (ValueMetadataType metadataToAdd : toAdd) {
//noinspection unchecked
valueToAdd.getValueMetadataAsContainer().add(metadataToAdd.clone().asPrismContainerValue());
valueMetadataAsContainer.add(metadataToAdd.clone().asPrismContainerValue());
}
//noinspection unchecked
itemDelta.addValueToAdd((V) valueToAdd);
}

if (!toDelete.isEmpty()) {
PrismValue valueToDelete = equivalenceClass.getRepresentative().clone();
valueToDelete.getValueMetadataAsContainer().clear();
PrismContainer<Containerable> valueMetadataAsContainer = valueToDelete.getValueMetadataAsContainer();
valueMetadataAsContainer.clear();
for (ValueMetadataType metadataToDelete : toDelete) {
//noinspection unchecked
valueToDelete.getValueMetadataAsContainer().add(metadataToDelete.clone().asPrismContainerValue());
valueMetadataAsContainer.add(metadataToDelete.clone().asPrismContainerValue());
}
//noinspection unchecked
itemDelta.addValueToDelete((V) valueToDelete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ private void insertChangedItemPaths(
try {
ObjectDeltaType deltaBean =
schemaService.parserFor(delta.serializedDelta)
.fastAddOperations()
.parseRealValue(ObjectDeltaType.class);
for (ItemDeltaType itemDelta : deltaBean.getItemDelta()) {
ItemPath path = itemDelta.getPath().getItemPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private <T> T parseBytes(byte[] bytes, boolean usingSqlServer, Class<T> clazz) {
return repositoryContext()
.createStringParser(RUtil.getSerializedFormFromBytes(bytes, usingSqlServer))
.compat()
.fastAddOperations()
.parseRealValue(clazz);
} catch (SchemaException e) {
logger.error("Cannot parse {}: {}", clazz.getSimpleName(), e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ public static AccessCertificationCaseType createJaxb(
LOGGER.trace("RAccessCertificationCase full object to be parsed\n{}", serializedFrom);
try {
return prismContext.parserFor(serializedFrom)
.compat().parseRealValue(AccessCertificationCaseType.class);
.compat()
.fastAddOperations()
.parseRealValue(AccessCertificationCaseType.class);
} catch (SchemaException e) {
LOGGER.debug("Couldn't parse certification case because of schema exception ({}):\nData: {}", e, serializedFrom);
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,9 @@ private <T extends ObjectType> PrismObject<T> updateLoadedObject(GetObjectResult
// "Postel mode": be tolerant what you read. We need this to tolerate (custom) schema changes
ParsingContext parsingContext = prismContext.createParsingContextForCompatibilityMode();
prismObject = prismContext.parserFor(serializedForm)
.context(parsingContext).parse();
.context(parsingContext)
.fastAddOperations()
.parse();
if (parsingContext.hasWarnings()) {
LOGGER.warn("Object {} parsed with {} warnings", ObjectTypeUtil.toShortString(prismObject), parsingContext.getWarnings().size());
}
Expand Down Expand Up @@ -522,6 +524,7 @@ private <T extends ObjectType> PrismObject<T> updateLoadedObject(GetObjectResult
if (opResult != null) {
String serializedResult = RUtil.getSerializedFormFromBytes(opResult);
OperationResultType resultType = prismContext.parserFor(serializedResult)
.fastAddOperations()
.parseRealValue(OperationResultType.class);

PrismProperty<OperationResultType> resultProperty =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ public <T> RepositoryObjectParseResult<T> parsePrismObject(
// "Postel mode": be tolerant what you read. We need this to tolerate (custom) schema changes
ParsingContext parsingContext = prismContext.createParsingContextForCompatibilityMode();
T value = createStringParser(serializedForm)
.context(parsingContext).parseRealValue(schemaType);
.context(parsingContext)
.fastAddOperations()
.parseRealValue(schemaType);
return new RepositoryObjectParseResult<>(parsingContext, value);
} catch (RuntimeException e) {
throw new SchemaException("Unexpected exception while parsing serialized form: " + e, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ public <T> T extractResult(Response response, Class<T> expectedClass) throws Sch
if (response.hasEntity()) {
String body = response.readEntity(String.class);
if (expectedClass == null || Object.class.equals(expectedClass)) {
return prismContext.parserFor(body).parseRealValue();
return prismContext.parserFor(body).fastAddOperations().parseRealValue();
} else {
return prismContext.parserFor(body).parseRealValue(expectedClass);
return prismContext.parserFor(body).fastAddOperations().parseRealValue(expectedClass);
}
} else {
return null;
Expand Down

0 comments on commit 23e237a

Please sign in to comment.