Search in sources :

Example 51 with GluuAttribute

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

the class Shibboleth3ConfService method initAttributes.

/*
     * Init attributes
     */
private void initAttributes(List<GluuSAMLTrustRelationship> trustRelationships) {
    List<GluuAttribute> attributes = attributeService.getAllPersonAttributes(GluuUserRole.ADMIN);
    HashMap<String, GluuAttribute> attributesByDNs = attributeService.getAttributeMapByDNs(attributes);
    GluuAttribute uid = attributeService.getAttributeByName(OxConstants.UID);
    // Load attributes definition
    for (GluuSAMLTrustRelationship trustRelationship : trustRelationships) {
        // Add first attribute uid
        List<String> oldAttributes = trustRelationship.getReleasedAttributes();
        List<String> releasedAttributes = new ArrayList<String>();
        if (oldAttributes != null) {
            releasedAttributes.addAll(oldAttributes);
        }
        if (uid != null) {
            if (releasedAttributes.remove(uid.getDn())) {
                releasedAttributes.add(0, uid.getDn());
            }
        }
        // Resolve custom attributes by DNs
        trustRelationship.setReleasedCustomAttributes(attributeService.getCustomAttributesByAttributeDNs(releasedAttributes, attributesByDNs));
        // Set attribute meta-data
        attributeService.setAttributeMetadata(trustRelationship.getReleasedCustomAttributes(), attributes);
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) ArrayList(java.util.ArrayList) GluuAttribute(org.gluu.model.GluuAttribute)

Example 52 with GluuAttribute

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

the class Shibboleth3ConfService method createAttributeMap.

private HashMap<String, Object> createAttributeMap(Set<GluuAttribute> attributes) {
    HashMap<String, Object> resolver = new HashMap<String, Object>();
    List<String> attributeNames = new ArrayList<>();
    for (GluuAttribute attribute : attributes) attributeNames.add(attribute.getName());
    SchemaEntry schemaEntry = shemaService.getSchema();
    List<AttributeTypeDefinition> attributeTypes = shemaService.getAttributeTypeDefinitions(schemaEntry, attributeNames);
    Map<String, String> attributeSAML1Strings = new HashMap<String, String>();
    Map<String, String> attributeSAML2Strings = new HashMap<String, String>();
    for (GluuAttribute metadata : attributes) {
        String attributeName = metadata.getName();
        // urn::dir:attribute-def:$attribute.name
        // urn:oid:$attrParams.attributeOids.get($attribute.name)
        String saml1String = metadata.getSaml1Uri();
        if (StringHelper.isEmpty(saml1String)) {
            boolean standard = metadata.isCustom() || StringHelper.isEmpty(metadata.getUrn()) || (!StringHelper.isEmpty(metadata.getUrn()) && metadata.getUrn().startsWith("urn:gluu:dir:attribute-def:"));
            saml1String = String.format("urn:%s:dir:attribute-def:%s", standard ? "gluu" : "mace", attributeName);
        }
        attributeSAML1Strings.put(attributeName, saml1String);
        String saml2String = metadata.getSaml2Uri();
        if (StringHelper.isEmpty(saml2String)) {
            AttributeTypeDefinition attributeTypeDefinition = shemaService.getAttributeTypeDefinition(attributeTypes, attributeName);
            if (attributeTypeDefinition == null) {
                log.error("Failed to get OID for attribute name {}", attributeName);
                return null;
            }
            saml2String = String.format("urn:oid:%s", attributeTypeDefinition.getOID());
        }
        attributeSAML2Strings.put(attributeName, saml2String);
    }
    resolver.put("attributes", attributes);
    resolver.put("attributeSAML1Strings", attributeSAML1Strings);
    resolver.put("attributeSAML2Strings", attributeSAML2Strings);
    return resolver;
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SchemaEntry(org.gluu.model.SchemaEntry) GluuAttribute(org.gluu.model.GluuAttribute)

Example 53 with GluuAttribute

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

the class AttributeService method searchAttributes.

/**
 * Search groups by pattern
 *
 * @param pattern
 *            Pattern
 * @param sizeLimit
 *            Maximum count of results
 * @return List of groups
 * @throws Exception
 */
public List<GluuAttribute> searchAttributes(String pattern, int sizeLimit) throws Exception {
    String[] targetArray = new String[] { pattern };
    Filter displayNameFilter = Filter.createSubstringFilter(OxTrustConstants.displayName, null, targetArray, null);
    Filter descriptionFilter = Filter.createSubstringFilter(OxTrustConstants.description, null, targetArray, null);
    Filter nameFilter = Filter.createSubstringFilter(OxTrustConstants.attributeName, null, targetArray, null);
    Filter searchFilter = Filter.createORFilter(displayNameFilter, descriptionFilter, nameFilter);
    List<GluuAttribute> result = persistenceEntryManager.findEntries(getDnForAttribute(null), GluuAttribute.class, searchFilter, sizeLimit);
    String customOrigin = getCustomOrigin();
    for (GluuAttribute attribute : result) {
        attribute.setCustom(customOrigin.equals(attribute.getOrigin()));
    }
    return result;
}
Also used : Filter(org.gluu.search.filter.Filter) GluuAttribute(org.gluu.model.GluuAttribute)

Example 54 with GluuAttribute

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

the class AttributeService method getAllActiveAtributesImpl.

/**
 * @return
 * @throws LDAPException
 */
private List<GluuAttribute> getAllActiveAtributesImpl(GluuUserRole gluuUserRole) {
    Filter filter = Filter.createEqualityFilter("gluuStatus", "active");
    List<GluuAttribute> attributeList = persistenceEntryManager.findEntries(getDnForAttribute(null), GluuAttribute.class, filter);
    String customOrigin = getCustomOrigin();
    String[] objectClassTypes = appConfiguration.getPersonObjectClassTypes();
    log.debug("objectClassTypes={}", Arrays.toString(objectClassTypes));
    List<GluuAttribute> returnAttributeList = new ArrayList<GluuAttribute>();
    for (GluuAttribute attribute : attributeList) {
        if (StringHelper.equalsIgnoreCase(attribute.getOrigin(), appConfiguration.getPersonCustomObjectClass()) && (GluuUserRole.ADMIN == gluuUserRole)) {
            attribute.setCustom(true);
            returnAttributeList.add(attribute);
            continue;
        }
        for (String objectClassType : objectClassTypes) {
            if (attribute.getOrigin().equals(objectClassType)) {
                attribute.setCustom(customOrigin.equals(attribute.getOrigin()));
                returnAttributeList.add(attribute);
                break;
            }
        }
    }
    return returnAttributeList;
}
Also used : Filter(org.gluu.search.filter.Filter) ArrayList(java.util.ArrayList) GluuAttribute(org.gluu.model.GluuAttribute)

Example 55 with GluuAttribute

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

the class AttributeService method getAllContactAtributesImpl.

/**
 * Get all contact attributes
 *
 * @param attributes
 *            List of attributes
 * @return List of contact attributes
 */
private List<GluuAttribute> getAllContactAtributesImpl(GluuUserRole gluuUserRole, Collection<GluuAttribute> attributes) {
    List<GluuAttribute> returnAttributeList = new ArrayList<GluuAttribute>();
    String[] objectClassTypes = appConfiguration.getContactObjectClassTypes();
    for (GluuAttribute attribute : attributes) {
        if (StringHelper.equalsIgnoreCase(attribute.getOrigin(), appConfiguration.getPersonCustomObjectClass()) && (GluuUserRole.ADMIN == gluuUserRole)) {
            attribute.setCustom(true);
            returnAttributeList.add(attribute);
            continue;
        }
        for (String objectClassType : objectClassTypes) {
            if (attribute.getOrigin().equals(objectClassType) && (attribute.allowViewBy(gluuUserRole) || attribute.allowEditBy(gluuUserRole))) {
                returnAttributeList.add(attribute);
                break;
            }
        }
    }
    return returnAttributeList;
}
Also used : ArrayList(java.util.ArrayList) GluuAttribute(org.gluu.model.GluuAttribute)

Aggregations

GluuAttribute (org.gluu.model.GluuAttribute)68 ArrayList (java.util.ArrayList)21 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)10 IOException (java.io.IOException)8 Scope (org.oxauth.persistence.model.Scope)8 HttpEntity (org.apache.http.HttpEntity)7 HttpResponse (org.apache.http.HttpResponse)7 ParseException (org.apache.http.ParseException)7 Test (org.junit.Test)7 HttpGet (org.apache.http.client.methods.HttpGet)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 Filter (org.gluu.search.filter.Filter)5 JSONObject (org.json.JSONObject)4 Operation (io.swagger.v3.oas.annotations.Operation)3 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 FacesMessage (javax.faces.application.FacesMessage)3 UIInput (javax.faces.component.UIInput)3 AttributeValidation (org.gluu.model.attribute.AttributeValidation)3