Skip to content

Conversation

@nathanjrobertson
Copy link
Contributor

I have a use case where we have a number of dynamic attributes that follow a particular pattern, and if any of them exist, I need to add an attribute.

As a concrete example, if any of customerTypeA, customerTypeB, customerTypeC, ... exists, then set isCustomer = ['true'].

With this PR, this can easily be done with:

    'authproc' => [
        50 => [
            'class' => 'core:AttributeAdd',
            '%if_attr_regex_matches' => '/^customerType/',
            'isCustomer' => ['true'],
        ],
    ],

I added both the string and regular expression options, as not every user will understand regular expressions, yet it's the only sensible way to support a dynamic list of attributes (such as my use case).

Fully backward compatible as usual. If neither options are specified then it will add the attribute, as per existing functionality. PHPUnit tests and documentation updated too.

@tvdijen
Copy link
Member

tvdijen commented Nov 18, 2025

Thanks Nathan! I feel like this use-case is so specific that it should probably go into a custom authproc-filter.

@nathanjrobertson
Copy link
Contributor Author

nathanjrobertson commented Nov 18, 2025

Thanks Nathan! I feel like this use-case is so specific that it should probably go into a custom authproc-filter.

Yeah, that was my inital thoughts too. My original design was this:

    'authproc' => [
        50 => [
            'class' => 'core:AttributeConditionalAdd',
            'conditions' => [
                'attrExists' => [
                    'eduPersonAffiliation',
                ],
                'attrExistsRegex' => [
                    '/^person.*$/',
                ],
                'attrValueIs' => [
                    'departmentName' => 'Physics',
                ],
                'attrValueIsRegex' => [
                    'employeeType' => '/^staff$/',
                ],
            ],
            'attributes' => [
                'isInternal' => ['true'],
            ],
        ],
    ],

But the base case is just:

'authproc' => [
        50 => [
            'class' => 'core:AttributeConditionalAdd',
            'conditions' => [], // empty array should be default, so we shouldn't need to specify it
            'attributes' => [
                'attributeToAdd' => ['true'],
            ],
        ],
    ],

Which is just core:AttributeAdd (an empty conditions array evaluates to true, and is the default). So retrofitting conditionals to core:AttributeAdd was what I went with.

I'm happy to submit a PR for core:AttributeConditionalAdd if you'd consider it for merging. I don't think conditional adding of attributes would be that unusual to do. Also happy to take feedback on the above design.

Another thing I considered doing was just using %precondition filters, but I could see that that method would quickly become an unmaintainable mess of hard to test PHP code.

Thanks Tim. I appreciate the feedback.

@pradtke
Copy link
Contributor

pradtke commented Dec 8, 2025

I'm curious what this looks like with the existing %precondition for conditionally running the authproc. Or these conditions too conplex/awkward to fit into that framework?

@nathanjrobertson
Copy link
Contributor Author

I'm curious what this looks like with the existing %precondition for conditionally running the authproc. Or these conditions too conplex/awkward to fit into that framework?

Honestly, I haven't tried. The use of %precondition I see as a last resort, and providing something more declarative (and easier to test) preferable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants