authproc: Support conditionally adding attributes declaratively#2579
authproc: Support conditionally adding attributes declaratively#2579nathanjrobertson wants to merge 6 commits intosimplesamlphp:simplesamlphp-2.5from
Conversation
|
The failing PHP 8.5 tests are not your fault. We will fix this |
4874a87 to
4398438
Compare
Yeah, I took a look at it yesterday. Looks like a dependency that is currently in composer.lock depends on PHP 8.2-8.4, and there is an updated version of it that works only with PHP 8.3-8.5, so I figured I'd leave that one to a true genius whilst I paddle in the shallow end of the pool. |
|
Well, this genius decided that for SSP 2.5 we're going to bump the minimum PHP version to 8.3! |
|
@tvdijen Any chance you or somebody else could take a look at this one? I've got a couple of use cases where I'd like to use this functionality and ideally I'd like it merged before sending stuff to production. |
d380e5a to
e0d2141
Compare
|
Quick note - we've had this running in production now for a week or so with no issues. It has helped in getting the number of attribute queries we needed to do in sqlauth down, improving our performance quite a bit. |
I have a number of cases where I'm looking to use authprocs to add extra attributes, but only if certain attributes already exist, and in some cases only if they have particular values or the names or values of the attributes match given regular expressions. I've found
%preconditionto be ok for really simple cases, but maintenance and debugging to be a pain - I really want something more expressive and declarative.I previously wrote PR #2559 to partially address this, but it was a bit of a hack to tack on support for just a few use cases. The incompleteness bothered me, so I've since torn that down and produced a far more comprehensive way to declaratively specify conditional adding of attributes in an authproc.
In doing this, the base case of unconditionally adding an attribute (essentially what the existing
core:AttributeAdddoes) remains reasonably simple:However, the main feature of this PR is the
conditionskey, which has a list of optional conditionals, which if satisfied, theattributesare added. By default, if more than one condition is specified, all must pass (essentially AND). The%anyconditionflag switches this to "one or more must pass" (essentially OR).The full dictionary of supported conditionals is:
The
%replaceflag is retained from the existingcore:AttributeAdd, and there is a new%nodupeflag, which removes duplicate values when appending new values to an attribute.One final example (taken from the documentation) showing the power of what this PR brings - in the below case, the user must either have a "supplierId" attribute, or have the "staff" role and be in the "Procurement" department to receive the 'allowedSystems' => ['procurement'] attribute:
The implementation itself is quite extensible. To add an extra type of condition later you implement three private methods (eg. if you were implementing
attrHasSomethingOrOther, you'd implementsetAttrHasSomethingOrOther()andisConfiguredAttrHasSomethingOrOther()andprocessConditionalAttrHasSomethingOrOther(). So extra new types of conditionals are now trivial to add later on.Included in this PR is 50+ PHPUnit tests and detailed user documentation which includes examples.
Follow-up work would be to have the existing
core:AttributeAddjust call this, providing backward compatibility but not carrying extra code. However, I thought I'd get this reviewed first before disturbing existing functionality.