Can a variable reference be used on RHS side of JavaRegex condition

Hi all, @Dino-at-Google @@Dino


From Apigee docs I could see below

Suppose the authentication server returns a list of roles as a comma-delimted string: "editor, author, guest".

To test the presence of the editor role, this construction will not work, because "editor" is only part of the entire string.

<Condition>returned_roles ~~ "editor"</Condition>

However, this construction will work:

<Condition>returned_roles ~~ ".*\beditor\b.*")</Condition>

It works because it takes into account word breaks and any other parts of the string with the .* prefix and suffix.

——


My requirement is on RHS ( right hand side) also I have an variable , for example request.header.name instead of single direct value.Wanted to know how to achieve this check


P.S - don’t want to use JavaScript


Thank you in advance!!

Solved Solved
0 4 120
1 ACCEPTED SOLUTION

nope

You can’t do that.

View solution in original post

4 REPLIES 4

nope

You can’t do that.

Thank you for quick response @Dino-at-Google

Any other suggestions to achieve this ask ?

Sorry! I should have suggested an alternative in my original answer.

If I had to compare two dynamic data items, I think I might use a JavaScript policy...

So it would be something like this

// the assumption is that "returned_roles" contains a JSON array like
// [ "role1", "role2", "role3"] 
var returnedRoles = JSON.parse(context.getVariable('returned_roles'));
var actualRole = context.getVariable('request.header.name');

var found = returnedRoles.indexOf(actualRole) >= 0;
context.setVariable('found_role', found);

And then in the condition, something like this:

<Condition>found_role is true</Condition>

Funny, I had a totally different question yesterday, for which I suggested a similar solution.

@Dino-at-Google Thank you again !!