/*
 * oxAuth is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.xdi.oxauth.model.common;

import java.util.List;

import org.codehaus.jettison.json.JSONArray;
import org.xdi.oxauth.model.exception.InvalidClaimException;

/**
 * @author Javier Rojas Blum Date: 11.25.2011
 */
public class SimpleUser extends org.xdi.ldap.model.SimpleUser {

    private static final long serialVersionUID = -2634191420188575733L;

    public Object getAttribute(String userAttribute, boolean optional) throws InvalidClaimException {
        Object attribute = null;

        for (org.xdi.ldap.model.CustomAttribute customAttribute : customAttributes) {
            if (customAttribute.getName().equals(userAttribute)) {
                List<String> values = customAttribute.getValues();
                if (values != null) {
                    if (values.size() == 1) {
                        attribute = values.get(0);
                    } else {
                        JSONArray array = new JSONArray();
                        for (String v : values) {
                            array.put(v);
                        }
                        attribute = array;
                    }
                }

                break;
            }
        }

        if (attribute != null) {
            return attribute;
        } else if (optional) {
            return attribute;
        } else {
            throw new InvalidClaimException("The claim " + userAttribute + " was not found.");
        }
    }

}
@@ -246,16 +246,59 @@
 NArray;%0A
+import org.xdi.ldap.model.CustomAttribute;%0A
 import o
@@ -349,16 +349,50 @@
 ception;
+%0Aimport org.xdi.util.StringHelper;
 %0A%0A/**%0A *
@@ -1659,9 +1659,513 @@
 %0A    %7D%0A%0A
+    public List%3CString%3E getAttributeValues(String ldapAttribute) %7B%0A        List%3CString%3E attributes = null;%0A        if (ldapAttribute != null && !ldapAttribute.isEmpty()) %7B%0A            for (CustomAttribute customAttribute : customAttributes) %7B%0A                if (StringHelper.equalsIgnoreCase(ldapAttribute, customAttribute.getName())) %7B%0A                    attributes = customAttribute.getValues();%0A                    break;%0A                %7D%0A            %7D%0A        %7D%0A%0A        return attributes;%0A    %7D%0A%0A
 %7D

Add user utility method to simplify scripts