Search in sources :

Example 31 with GluuAttribute

use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.

the class UserSerializer method serializeUserExtension.

protected void serializeUserExtension(Map.Entry<String, JsonNode> rootNodeEntry, ObjectMapper mapper, User user, JsonGenerator jsonGenerator) throws Exception {
    Extension extension = user.getExtension(rootNodeEntry.getKey());
    Map<String, Object> list = new HashMap<String, Object>();
    boolean enclosingWritten = false;
    for (Map.Entry<String, Extension.Field> extEntry : extension.getFields().entrySet()) {
        if (attributes != null && attributes.size() > 0) {
            for (String attribute : attributes) {
                attribute = FilterUtil.stripScim2Schema(attribute);
                if (extEntry.getKey().equalsIgnoreCase(attribute)) {
                    if (!enclosingWritten) {
                        jsonGenerator.writeFieldName(rootNodeEntry.getKey());
                        enclosingWritten = true;
                    }
                    break;
                }
            }
        } else {
            if (!enclosingWritten) {
                jsonGenerator.writeFieldName(rootNodeEntry.getKey());
                enclosingWritten = true;
            }
        }
        if (enclosingWritten) {
            GluuAttribute gluuAttribute = attributeService.getAttributeByName(extEntry.getKey());
            GluuAttributeDataType attributeDataType = gluuAttribute.getDataType();
            if ((gluuAttribute.getOxMultivaluedAttribute() != null) && gluuAttribute.getOxMultivaluedAttribute().equals(OxMultivalued.TRUE)) {
                if (attributeDataType.equals(GluuAttributeDataType.STRING) || attributeDataType.equals(GluuAttributeDataType.PHOTO)) {
                    List<String> stringList = Arrays.asList(mapper.readValue(extEntry.getValue().getValue(), String[].class));
                    list.put(extEntry.getKey(), stringList);
                } else if (attributeDataType.equals(GluuAttributeDataType.DATE)) {
                    List<Date> dateList = Arrays.asList(mapper.readValue(extEntry.getValue().getValue(), Date[].class));
                    List<String> stringList = new ArrayList<String>();
                    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
                    for (Date date : dateList) {
                        String dateString = dateTimeFormatter.print(date.getTime());
                        stringList.add(dateString);
                    }
                    list.put(extEntry.getKey(), stringList);
                } else if (attributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
                    List<BigDecimal> numberList = Arrays.asList(mapper.readValue(extEntry.getValue().getValue(), BigDecimal[].class));
                    list.put(extEntry.getKey(), numberList);
                }
            } else {
                list.put(extEntry.getKey(), extEntry.getValue().getValue());
            }
        }
    }
    if (enclosingWritten) {
        jsonGenerator.writeObject(list);
    }
}
Also used : HashMap(java.util.HashMap) GluuAttributeDataType(org.xdi.model.GluuAttributeDataType) Date(java.util.Date) BigDecimal(java.math.BigDecimal) GluuAttribute(org.xdi.model.GluuAttribute) Extension(org.gluu.oxtrust.model.scim2.Extension) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 32 with GluuAttribute

use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.

the class AttributeService method generateInumForNewAttribute.

/**
	 * Generate new inum for attribute
	 * 
	 * @return New inum for attribute
	 */
public String generateInumForNewAttribute() {
    GluuAttribute attribute = null;
    String newInum = null;
    do {
        newInum = generateInumForNewAttributeImpl();
        String newDn = getDnForAttribute(newInum);
        attribute = new GluuAttribute();
        attribute.setDn(newDn);
    } while (containsAttribute(attribute));
    return newInum;
}
Also used : GluuAttribute(org.xdi.model.GluuAttribute)

Example 33 with GluuAttribute

use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.

the class AttributeService method removeAttribute.

/**
	 * Remove attribute with specified Inum
	 * 
	 * @param inum
	 *            Inum
	 */
public void removeAttribute(String inum) {
    GluuAttribute attribute = new GluuAttribute();
    attribute.setDn(getDnForAttribute(inum));
    removeAttribute(attribute);
}
Also used : GluuAttribute(org.xdi.model.GluuAttribute)

Example 34 with GluuAttribute

use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.

the class AttributeService method searchPersonAttributes.

public List<GluuAttribute> searchPersonAttributes(String pattern, int sizeLimit) throws Exception {
    String[] objectClassTypes = appConfiguration.getPersonObjectClassTypes();
    String[] targetArray = new String[] { pattern };
    List<Filter> originFilters = new ArrayList<Filter>();
    Filter displayNameFilter = Filter.createSubstringFilter(OxTrustConstants.displayName, null, targetArray, null);
    Filter descriptionFilter = Filter.createSubstringFilter(OxTrustConstants.description, null, targetArray, null);
    Filter inameFilter = Filter.createSubstringFilter(OxTrustConstants.iname, null, targetArray, null);
    for (String objectClassType : objectClassTypes) {
        Filter originFilter = Filter.createEqualityFilter(OxTrustConstants.origin, objectClassType);
        originFilters.add(originFilter);
    }
    Filter searchFilter = Filter.createORFilter(displayNameFilter, descriptionFilter, inameFilter);
    Filter originFilter = Filter.createORFilter(originFilters.toArray(new Filter[0]));
    Filter filter = Filter.createANDFilter(searchFilter, originFilter);
    List<GluuAttribute> result = ldapEntryManager.findEntries(getDnForAttribute(null), GluuAttribute.class, filter, 0, sizeLimit);
    return result;
}
Also used : Filter(com.unboundid.ldap.sdk.Filter) ArrayList(java.util.ArrayList) GluuAttribute(org.xdi.model.GluuAttribute)

Example 35 with GluuAttribute

use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.

the class AttributeService method getCustomAttributesByAttributeDNs.

/**
	 * Get custom attributes by attribute DNs
	 * 
	 * @param customAttributes
	 *            List of attribute DNs
	 * @param attributes
	 *            List of custom attributes
	 */
public List<GluuCustomAttribute> getCustomAttributesByAttributeDNs(List<String> attributeDNs, HashMap<String, GluuAttribute> attributesByDNs) {
    List<GluuCustomAttribute> customAttributes = new ArrayList<GluuCustomAttribute>();
    if (attributeDNs == null) {
        return customAttributes;
    }
    for (String releasedAttributeDn : attributeDNs) {
        GluuAttribute attribute = attributesByDNs.get(releasedAttributeDn);
        if (attribute != null) {
            GluuCustomAttribute customAttribute = new GluuCustomAttribute(attribute.getName(), releasedAttributeDn);
            customAttribute.setMetadata(attribute);
            customAttributes.add(customAttribute);
        }
    }
    return customAttributes;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) ArrayList(java.util.ArrayList) GluuAttribute(org.xdi.model.GluuAttribute)

Aggregations

GluuAttribute (org.xdi.model.GluuAttribute)64 ArrayList (java.util.ArrayList)24 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)15 JSONObject (org.codehaus.jettison.json.JSONObject)9 JSONArray (org.codehaus.jettison.json.JSONArray)8 GluuAttributeDataType (org.xdi.model.GluuAttributeDataType)6 IOException (java.io.IOException)5 BigDecimal (java.math.BigDecimal)5 Date (java.util.Date)5 HashMap (java.util.HashMap)5 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)5 Extension (org.gluu.oxtrust.model.scim2.Extension)5 JwtSubClaimObject (org.xdi.oxauth.model.jwt.JwtSubClaimObject)5 Filter (com.unboundid.ldap.sdk.Filter)4 List (java.util.List)4 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)4 Claim (org.xdi.oxauth.model.authorize.Claim)4 Scope (org.xdi.oxauth.model.common.Scope)4 PairwiseIdentifier (org.xdi.oxauth.model.ldap.PairwiseIdentifier)4 DynamicScopeExternalContext (org.xdi.oxauth.service.external.context.DynamicScopeExternalContext)4