Skip to content

[#192] Check the attributes given to create and update with one method, so create refuses an attribute the schema does not have - #216

Merged
maximthomas merged 4 commits into
OpenIdentityPlatform:masterfrom
maximthomas:issues/192-xml-shared-attribute-checks
Oct 30, 2026
Merged

maximthomas merged 4 commits into
OpenIdentityPlatform:masterfrom
maximthomas:issues/192-xml-shared-attribute-checks

Conversation

@maximthomas

@maximthomas maximthomas commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #192.
Closes #190.

XMLHandlerImpl.create went through the attributes of the schema, and update went through the attributes it was given. Each had its own copy of the attribute checks, and the copies had drifted apart in order and in wording. create also never looked at a given attribute that the schema does not have, so it dropped that attribute silently and returned a uid. The check on the value type was another split: update of an optional attribute used valuesAreExpectedClass, which calls getClass() on each value, so a [null] value failed with a NullPointerException (#190). On the other paths findAttributeValue refused the same [null] with <name> contains invalid type. Value(s) should be of type java.lang.String.

Now both operations check each given attribute with one method, checkAttribute(attribute, objAttributes, change). The Change argument, CREATE or UPDATE, decides only the operation's own schema rule. The checks run in this order, and the first that fails throws IllegalArgumentException:

  1. The schema has no such attribute: Data field: X is not supported.
  2. The operation's rule: X is not a creatable field. on create, X is not updatable. on update.
  3. AttributeTypeUtil.findAttributeValue reads the values once, so a guarded value is decrypted once. It now refuses a null value, first or not, with X contains a null value, before the type check. A value of the wrong type still gets X contains invalid type. Value(s) should be of type <class>.
  4. For a required attribute, and for __NAME__ whatever the XSD says: no values give No values provided for required attribute: X, and a blank value gives Parameter 'X' must not be blank.
  5. More than one value on a single-valued attribute: Data field: X is not multivalued can not have more than one value. The double space is in the existing update message, and create now uses the same text.

create checks every attribute in the map that AttributeUtil.toMap builds from its input. That map is case-insensitive: of two names that differ only in case it keeps the first spelling and the last attribute's values. create then refuses a required schema attribute that was not given, with No values provided for required attribute: X. Only after both passes does it look up the name with entryExists. It writes the values the checks returned, in schema order, as before.

valuesAreExpectedClass is removed. AttributeBuilder accepts only values whose class is exactly one of FrameworkUtil's supported types, or any Map. For a non-null value that is not a Map, the exact-class test was therefore the same as findAttributeValue's isInstance test. findAttributeValue now refuses a Map value with the old X contains values of illegal type: the connector writes it as {k=v} text and reads that text back as null. Apart from Map, the two tests differed only on null.

Changes in behaviour

  • create refuses an attribute that the schema does not have, with Data field: X is not supported. Before, it dropped the attribute and created the entry.
    • With OpenIDM, a create request that carries a property the provisioner's objectTypes list as creatable but the XSD lacks now fails this way. Before, the property was lost. Remove the property from the provisioner or add it to the XSD.
  • create uses the update messages:
    • A missing required attribute: Missing required field: X becomes No values provided for required attribute: X.
    • Two values on a single-valued attribute: Attribute field: X is not multivalued and can not contain more than one value becomes the Data field: … message above.
  • update of an optional attribute with a value of the wrong type: X contains values of illegal type becomes X contains invalid type. Value(s) should be of type <class>.
  • A [null] value gets X contains a null value on every path. Before, it got a NullPointerException on an optional-attribute update, and the type message everywhere else.
  • create with a blank __NAME__: Uid value must not be blank! becomes Parameter '__NAME__' must not be blank.
  • create checks the attributes before it looks up the name. A taken name together with a bad or missing attribute now gets the IllegalArgumentException about the attribute instead of AlreadyExistsException. With no data file, a bad attribute gets that IllegalArgumentException before Data file does not exists.
  • When several given attributes fail, create reports the first one in the order of a HashMap, not the first in schema order.
  • An attribute whose XSD type is a Map class such as java.util.HashMap gets X contains values of illegal type on create and update. Before, a HashMap value was written as text that reads back as null. An attribute typed java.util.Map got the same message before.
  • An attribute whose name differs from the schema's only in case is now checked. Before, create ignored it. For example, IS-DELETED=true now gets IS-DELETED is not a creatable field., and FirstName=[null] now gets firstname contains a null value. Such an attribute is still not written (XML connector: create and update accept an attribute name in another case, then lose its value #212).

Tests

  • AttributeTypeUtilTest#findAttributeValueRefusesANullValue has three rows, firstname=[null], firstname=["a", null] and FirstName=[null], for the schema attribute firstname. All three expect firstname contains a null value, in the schema's spelling. On master all three get firstname contains invalid type. Value(s) should be of type java.lang.String.
  • AttributeTypeUtilTest#findAttributeValueRefusesAMapValue gives a HashMap value to an attribute typed java.util.Map and to one typed java.util.HashMap. Both expect settings contains values of illegal type. On master findAttributeValue returns {k=v} for both.
  • XMLHandlerReloadTests#rejectedUpdateLeavesTheEntryAndTheFileAlone gets three new rows: lastname=[null], firstname=[null] and email=["a@example.com", null]. On master the first gets the type message and the other two a NullPointerException. The age="12" row now expects age contains invalid type. Value(s) should be of type java.lang.Integer.
  • XMLHandlerReloadTests#createAndUpdateRefuseAnAttributeAlike has nine rows: an unknown attribute, a valueless lastname, a blank lastname, a blank __NAME__, lastname=5, age="12", firstname=[null], email=["a@example.com", null] and lastname=["A", "B"].
    • Each row goes through create, where the row's attribute replaces the same-named attribute of a valid new account.
    • Each row also goes through update of an existing entry.
    • Both operations must throw the same message, and the file and the entry in memory must be unchanged.
    • On master four rows fail in create: the unknown attribute is accepted, the valueless lastname gets Missing required field: lastname, the blank __NAME__ gets Uid value must not be blank!, and the two lastname values get the Attribute field: … message.
  • XMLHandlerReloadTests#eachOperationAppliesItsOwnRule:
    • create refuses avg-wage (not creatable) and accepts account-created-timestamp.
    • update refuses account-created-timestamp (not updatable) and accepts avg-wage.
    • The file then holds those values. The test passes on master.
  • XMLHandlerReloadTests#createRefusesAMissingRequiredAttribute creates the taken name alice with no lastname, and then with LASTNAME in place of lastname. Both expect No values provided for required attribute: lastname, and the file must be unchanged. On master both get AlreadyExistsException.
  • XMLHandlerReloadTests#createKeepsOneOfTwoSameNamedAttributes: create with email=a and email=b writes only b. The test calls the handler; the framework's CreateImpl refuses this pair before it reaches the connector. The test passes on master.
  • XMLHandlerIndexTests#clearingTheOptionalNameOfAnEntryWithoutUidIsRefused now also creates a uid-less __GROUP__ with a blank __NAME__, "" and " ", on a schema where __NAME__ is optional. It expects Parameter '__NAME__' must not be blank. On master it gets Uid value must not be blank!.
  • CreateEntryTests#twoSecretPinValuesAreRefusedAsNotMultivalued expects the new message. The commented-out expected messages in CreateEntryTests and UpdateEntryTests are updated to the new texts; those tests check only the exception class.

Each of these mutants fails at least one test:

  • the null check removed, or moved after isInstance;
  • the null message built from the given name instead of the schema's;
  • the Map check removed;
  • isCreateable and isUpdateable swapped in Change;
  • the lookup of required attributes made case-insensitive;
  • entryExists moved between the two check passes of create;
  • || Name.NAME dropped;
  • the blank check on __NAME__ kept for update only.

createKeepsOneOfTwoSameNamedAttributes pins the last-wins result. It does not catch a check loop that goes through the given set instead of the map, because that loop also keeps the last value.

The module runs 366 tests with no failures, 345 on master.

Not covered

  • Attribute-name case is unchanged (XML connector: create and update accept an attribute name in another case, then lose its value #212). Given alone, an attribute whose name differs from the schema's only in case is checked but not written, and LASTNAME does not stand in for lastname.
  • A case variant given together with the schema's spelling either stands in for it or hides it, depending on the order of the given set: [lastname=L, LASTNAME=X] writes X into lastname, [EMAIL=a, email=b] writes no email, and [LASTNAME=X, lastname=L] is refused because lastname is missing. With two spellings of __NAME__, the taken-name check uses the first and the file gets the last. Master behaves the same way (XML connector: create and update accept an attribute name in another case, then lose its value #212). The framework's CreateImpl refuses two attributes with exactly the same name.
  • For a name that differs from the schema's in case, the type and null messages from findAttributeValue name the attribute as the schema spells it. The other messages use the caller's spelling.

@maximthomas maximthomas added bug Something isn't working java Pull requests that update java code tests Test additions or fixes connector:xml XML connector labels Oct 30, 2026
…ly for __UID__, and say how create keeps names that differ in case

- findAttributeValue refuses a Map value with "X contains values of illegal type",
  as valuesAreExpectedClass did for an attribute typed java.util.Map: the value is
  written as {k=v} text and createInstantiatedObject reads that back as null.
- create picks a random uid only when the schema has an attribute named exactly
  __UID__, the only element the write loop puts the uid into. objAttributes is
  now case-insensitive, so containsKey matched a schema element __uid__.
- The comment in create and the javadoc of createKeepsOneOfTwoSameNamedAttributes
  say how AttributeUtil.toMap keeps two names that differ only in case (OpenIdentityPlatform#212).
- findAttributeValueRefusesANullValue gets a FirstName=[null] row that pins the
  schema's spelling in the message.
@maximthomas
maximthomas marked this pull request as ready for review October 30, 2026 08:52
@maximthomas
maximthomas requested a review from vharseko October 30, 2026 08:52

@vharseko vharseko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new issues found. The existing attribute-name case limitations are documented in the PR and tracked in #212.

@vharseko vharseko added the data-loss Fixes or risks loss or corruption of stored data label Oct 30, 2026
@maximthomas
maximthomas merged commit 953cb5a into OpenIdentityPlatform:master Oct 30, 2026
15 checks passed
@maximthomas
maximthomas deleted the issues/192-xml-shared-attribute-checks branch October 30, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working connector:xml XML connector data-loss Fixes or risks loss or corruption of stored data java Pull requests that update java code tests Test additions or fixes

Projects

None yet

2 participants