Repository navigation
fix(acl): make the domain classes that s2-create-acl-domains generates compare and serialize as the plugin's - #16968
Conversation
…s compare and serialize as the plugin's The templates of AclClass, AclSid, AclEntry and AclObjectIdentity had no @EqualsAndHashCode and did not implement Serializable, unlike the plugin's own domain classes. A generated copy compared by identity, and a generated AclObjectIdentity compared equal to another with a different objectId, because the equality of its base class ignores objectId. The ACL services look ACLs up by that equality, so an object whose ACL exists failed with a NotFoundException. The templates now declare the same equality and serialVersionUID as the domain classes. GeneratedAclDomainsSpec renders each template, compiles it and checks equality, hashCode and Serializable. The script does not overwrite an existing class, so the documentation of s2-create-acl-domains says what to add to a copy generated earlier. Fixes #15927 Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
jamesfredley
left a comment
There was a problem hiding this comment.
The generated classes compare and serialize the same way as the plugin's classes. Existing plugin classes are unchanged.
✅ All tests passed ✅🏷️ Commit: c49d2e5 Learn more about TestLens at testlens.app/docs. |
sbglasius
left a comment
There was a problem hiding this comment.
The four templates now declare the same @EqualsAndHashCode keys, Serializable and serialVersionUID as the plugin's domain classes, so a generated AclObjectIdentity no longer equals one with a different objectId. I ran GeneratedAclDomainsSpec: it passes on this branch, and all four features fail against the 7.0.x templates. The guide note for copies generated before this fix is a good addition, since the script does not overwrite them. Two optional nits inline.
| @Issue('#15927') | ||
| class GeneratedAclDomainsSpec extends Specification { | ||
|
|
||
| private static final String TEMPLATES = 'src/main/templates' |
There was a problem hiding this comment.
Nit: this path depends on the working directory being the module folder. That is true under Gradle but not always in an IDE run. Passing the folder in as a system property from build.gradle, or finding it relative to the class location, would make it independent of that. Not blocking.
| expect: | ||
| identity.newInstance(objectId: 2L, aclClass: aclClass) == identity.newInstance(objectId: 2L, aclClass: aclClass) | ||
| identity.newInstance(objectId: 2L, aclClass: aclClass).hashCode() == identity.newInstance(objectId: 2L, aclClass: aclClass).hashCode() | ||
| identity.newInstance(objectId: 2L, aclClass: aclClass) != identity.newInstance(objectId: 3L, aclClass: aclClass) |
There was a problem hiding this comment.
Optional: the reported bug was objectId being ignored, and that is covered. One more line, such as two identities with the same objectId but a different aclClass not being equal, would also show that callSuper = true keeps the base-class fields in the comparison.
|
Thanks, Søren. The two nits are tracked in #17132, outside this PR. |
|
@borinquenkid this conflicts with #17114 - please hold off on further contributing changes to the scripts/forge functionality since they're being rewritten |
|
Understood |
Fixes #15927 (reported by DamsoftDevelopers; a merge to 7.0.x does not close it, so it is closed by hand once the merge-ups land).
The reporter's cause: the domain classes that
s2-create-acl-domainscopies into an application come from templates, and the templates did not have what the plugin's own domain classes have.AclObjectIdentityhad no@EqualsAndHashCode(includes = 'objectId', callSuper = true), so a generated copy compared equal to another with a differentobjectId: the equality of its base class (AbstractAclObjectIdentity) covers only the class, the parent, the owner andentriesInheriting. The ACL services look ACLs up by that equality, so after a restart a list of more than one object could fail withNotFoundException: Unable to find ACL information for object identity. The other three templates had the same gap: no@EqualsAndHashCode, and none of the four implementedSerializable.Change: the four templates declare the same
@EqualsAndHashCodeincludes,SerializableandserialVersionUIDas the domain classes of the plugin (className;sidandprincipal; identity, order, sid, mask, granting and the audit flags;objectIdwithcallSuper). Their owntoStringis kept.s2-create-acl-domainsdoes not overwrite a class that already exists, so the page of the script in the guide now says what to add to a copy generated earlier.Test: a new
GeneratedAclDomainsSpec(the module had no unit tests; it uses the testing support the module already declares) renders each real template, compiles it under another name and checks equality,hashCodeandSerializable, including that two identities with differentobjectIdare not equal. All four fail without the change, as run in the repo; with it they pass. CodeNarc and rat are clean. CI is off (no ci).Not covered: a running application with a generated copy; the spec checks the classes the templates produce, not the script's rendering.
Two of the three reviewers (matrei, codeconsole, jdaugherty), as 7.0.x is released.
https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL