• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Mister PKI

SSL Certificates * SSL Tools * Certificate Decoder

  • PKI Training
  • OpenSSL
  • Keytool
  • PKI Tools
    • Apereo CAS
    • SAML
    • OpenID Connect
  • Get expert help

Apereo CAS Release Multi-Value Attribute

January 17, 2025 by Mister PKI Leave a Comment

This article will demonstrate how to in Apereo CAS release a multi-value attribute. Each Service Provider (SP) is different in how they parse incoming attributes. Some may accept a comma delimited list and others may require multiple values for the same attribute.

By default, attributes such as memberOf in Active Directory (AD) should be sent as multi-value. It may not be as obvious how to release a custom attribute this way. This solution will make use of a custom groovy script for attribute computation and release configured in a registered service in the json service registry.

CAS JSON Service Config

This article presumes you already have a json service configured in your json service registry. For example:


  "@class": "org.apereo.cas.support.saml.services.SamlRegisteredService",
  "serviceId": "example",
  "name": "example",
  "environments": [
    "java.util.HashSet",
    [
      "prod"
    ]
  ],
  "id": 1234,
  "metadataLocation": "file:/etc/cas/config/metadata/example.xml",
  "evaluationOrder": 1234,
  "requiredNameIdFormat": "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
  "usernameAttributeProvider": {
    "@class": "org.apereo.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider",
    "usernameAttribute": "emailAddress"
  },
  "attributeReleasePolicy": {
    "@class": "org.apereo.cas.services.ReturnMappedAttributeReleasePolicy",
    "allowedAttributes": {
      "@class": "java.util.TreeMap",
      "role": "file:/etc/cas/config/groovy/example.groovy"
    }
  }
}

In this example, the role attribute being released is computed in an example.groovy script detailed below.

Custom Groovy Attribute Release

Here is a custom groovy script computing roles for a given user. In this example, the user’s group membership is not to be returned to avoid sending access data to a third party Service Provider (SP). Rather, roles are computed based on the group membership.

import java.util.*
def run(final Object... args) {
    def attributes = args[0]
    def roles = []
    if (attributes["memberOf"].join(", ").contains("CN=exampleA")) {
        roles.add("exampleA")
    }
    if (attributes["memberOf"].join(", ").contains("CN=exampleB")) {
        roles.add("exampleB")
    }
    return roles
}

In this script an array of roles is being returned. CAS will translate the array into multiple AttributeValue elements in the role Attribute. In the SAML response, the role attribute will look like this.

<saml2:Attribute FriendlyName="role"
                             Name="role"
                             NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
                             >
       <saml2:AttributeValue>exampleA</saml2:AttributeValue>
       <saml2:AttributeValue>exampleB</saml2:AttributeValue>
</saml2:Attribute>

Essentially, the roles variable would look like this if the user was a member of both groups.

roles = ['exampleA', 'exampleB']

Conversely, you could configure your script to simply return a comma delimited list which would return a string value in a single AttributeValue element.

Conclusion – Apereo CAS Release Multi-Value Attribute

In conclusion, this article has demonstrated how to release a multi-value attribute in a custom groovy script called by a registered service in the json service registry. Let us know in the comments if you have any questions. If you found this article helpful consider reading more of our content on the Apereo CAS IDP.

Apereo CAS,  Identity Management,  saml

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Popular Posts

PKCS12

openssl s_client

Keytool

Keytool list

ECDSA vs RSA

OpenSSL

PKCS7

Certificate Decoder

PKI for DevOps Engineers – Free Training Series

PKI for DevOps Training Hub

Lesson 1 – How TLS and PKI Work

Lesson 2 – Understanding X.509 Certificates

Lesson 3 – Certificate Chains Explained

Lesson 4 – Debug TLS with OpenSSL

Lesson 5 – Verify Certificate Chains

Lesson 6 – Creating CSRs with OpenSSL

Lesson 7 – Working with PKCS12 Certificates

Lesson 8 – Java Keystores and keytool

Lesson 9 – Certificate Expiration Monitoring

Lesson 10 – Automating Certificate Renewal

Lesson 11 – Common TLS Errors

Lesson 12 – PKI Architecture for DevOps

Recent Posts

  • Apache mod_auth_cas: Protect Web Applications with Apereo CAS and Docker
  • Apache mod_auth_mellon: Configure SAML SSO & Docker
  • Configure OpenID Connect (OIDC) in Apereo CAS 7.3 and 8
  • Certificate Ownership Is an Operating Model Problem, Not a Tooling Problem
  • OpenSSL dgst: Create Checksums and Verify Digital Signatures

Footer

  • Twitter
  • YouTube
Mister PKI

Practical security engineering for the systems that establish trust.

Learn OpenSSL Keytool Free training
Work together PKI consulting CAS consulting Sponsored contributions
Site About Support Mister PKI Cookie policy Search
© 2026 Mister PKI Secure systems. Clear guidance.