Sending multi-value attributes
The Agent Toolkit for Java allows your application to send multi-value attributes to PingFederate. Each attributes appears in its own <AttributeValue> element in the SAML 2.0 assertion.
Using the Agent Toolkit with Apache Commons MultiMap
Multi-value attributes are passed using the org.apache.commons.collections.map.MultiValueMap
collection.
String username = (String)request.getSession().getAttribute("username"); MultiMap userInfo = new MultiValueMap(); userInfo.put(Agent.TOKEN_SUBJECT, username); // Add an attribute GROUP with multiple values userInfo.put("GROUP", "Administrators"); userInfo.put("GROUP", "Users"); String returnUrl = "https://<PingFederate_DNS>:9031" + request.getParameter("resume"); . . . . try { UrlHelper urlHelper = new UrlHelper(returnUrl); //see "Using the Agent API" section for sample code //that instantiates and configures an Agent instance agent.writeToken(userInfo,response,urlHelper,false); returnUrl = (String)urlHelper.toString(); } catch(TokenException e) { // Handle exception }
Using the PingFederate MultiMap equivalent
String username = (String) request.getSession().getAttribute("username"); PingFederateMultiMap userInfo = new PingFederateMultiMap(); userInfo.put(Agent.TOKEN_SUBJECT, username); // Add an attribute GROUP with multiple values userInfo.put("GROUP", "Administrators"); userInfo.put("GROUP", "Users"); String returnUrl = "https://<PingFederate_DNS>:9031" + request.getParameter("resume"); . . . . try { UrlHelper urlHelper = new UrlHelper(returnUrl); //see "Using the Agent API" section for sample code //that instantiates and configures an Agent instance agent.writeToken(userInfo, response, urlHelper, false); returnUrl = (String) urlHelper.toString(); } catch (TokenException | IOException e) { // Handle exception }