Filtering list in NetScaler and converting to XML using Policy Extension – v2

As I’ve stated, my knowledge of Lua and development is very limited. My good friend Ulrik pointed out to me that the code I was using (in my previous blog post) wasn’t optimized and helped me get it both faster and easier to understand. It’s actually works better and is about 21 times faster (the last one took about 533 437 nanoseconds/0,5ms to process and the new one takes 25 278 nanoseconds/0,025ms in my tests).

The Lua code:

A few things to note:

  • The last one did actually take the input and match it to lower, so if you entered “Group” instead of “group”, it didn’t work.
  • The processing used another function, which I’ve removed
  • I’ve tested this one with pattern matching for example “SG-AD-SAML-User” etc.

If a user is member of the following groups:
Group1, Group2, Grupp1, Grupp2, SG-AD-SAML-User, SG-AD-SAML-User-Office365, SG-AD-SAML-Admin ABC, SG-AD-SAML-Admin-Office365, SG-AD-Role-Employee

And we want to extract everything that contains -AD-SAML-, we’ll use an expression like this:

This will output all the groups containing “-AD-SAML-” into an XML-list  with the tag “xmltag” like this:
<xmltag>SG-AD-SAML-User<xmltag></xmltag>SG-AD-SAML-User-Office365<xmltag></xmltag>SG-AD-SAML-Admin ABC<xmltag></xmltag>SG-AD-SAML-Admin-Office365</xmltag>

As always, please leave a comment if you have any feedback!

Disclaimer: All information on this blog is offered "as is" with no warranty. It is strongly recommended that you verify all information and validate all scripts in isolated test environments before using them in production environments.