Search in sources :

Example 21 with GluuAttribute

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

the class Shibboleth3ConfService method generateGluuAttributeRulesFile.

public boolean generateGluuAttributeRulesFile(List<GluuAttribute> attributes) {
    boolean ret = false;
    log.info(">>>>>>>>>> IN Shibboleth3ConfService.generateGluuAttributeRulesFile() ...");
    if (appConfiguration.getShibboleth3IdpRootDir() == null) {
        throw new InvalidConfigurationException("Failed to update configuration due to undefined IDP root folder");
    }
    VelocityContext context = new VelocityContext();
    List<String> attributeNames = new ArrayList<String>();
    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();
        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 false;
            }
            saml2String = String.format("urn:oid:%s", attributeTypeDefinition.getOID());
        }
        attributeSaml2Strings.put(attributeName, saml2String);
    }
    context.put("attributes", attributes);
    context.put("attributeSaml1Strings", attributeSaml1Strings);
    context.put("attributeSaml2Strings", attributeSaml2Strings);
    String gluuAttributesRules = generateConfFile(SHIB_IDP_GLUU_ATTRIBUTE_RULES_FILE, context);
    log.info("Gluu attributes rules file path is {}", getGluuAttributesRulesFilePath());
    ret = writeConfFile(getGluuAttributesRulesFilePath(), gluuAttributesRules);
    log.info(">>>>>>>>>>> LEAVING Shibboleth3ConfService.generateGluuAttributeRulesFile() ...");
    return ret;
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition) HashMap(java.util.HashMap) VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) SchemaEntry(org.gluu.model.SchemaEntry) InvalidConfigurationException(org.gluu.util.exception.InvalidConfigurationException) GluuAttribute(org.gluu.model.GluuAttribute)

Example 22 with GluuAttribute

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

the class ImportPersonConfiguration method prepareAttributes.

private List<GluuAttribute> prepareAttributes() throws Exception {
    List<GluuAttribute> result = new ArrayList<GluuAttribute>();
    List<ImportPerson> mappings = configurationFactory.getImportPersonConfig().getMappings();
    Iterator<ImportPerson> it = mappings.iterator();
    while (it.hasNext()) {
        ImportPerson importPerson = (ImportPerson) it.next();
        String attributeName = importPerson.getLdapName();
        boolean required = importPerson.getRequired();
        if (StringHelper.isNotEmpty(attributeName)) {
            GluuAttribute attr = null;
            try {
                attr = attributeService.getAttributeByName(attributeName);
            } catch (EntryPersistenceException ex) {
                log.error("Failed to load attribute '{}' definition from LDAP", attributeName, ex);
            }
            if (attr == null) {
                log.warn("Failed to find attribute '{}' definition in LDAP", attributeName);
                attr = createAttributeFromConfig(importPerson);
                if (attr == null) {
                    log.error("Failed to find attribute '{}' definition in '{}'", attributeName, GLUU_IMPORT_PERSON_PROPERTIES_FILE);
                    continue;
                }
            } else {
                attr.setRequred(required);
            }
            result.add(attr);
        }
    // }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) EntryPersistenceException(org.gluu.persist.exception.EntryPersistenceException) ImportPerson(org.gluu.config.oxtrust.ImportPerson) GluuAttribute(org.gluu.model.GluuAttribute)

Example 23 with GluuAttribute

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

the class AttributeWebResourceTest method searchAttributesTest.

@Test
public void searchAttributesTest() {
    String searchPattern = "country";
    String SEARCH_QUERY = "?" + ApiConstants.SEARCH_PATTERN + "=" + searchPattern + "&size=5";
    HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.ATTRIBUTES + ApiConstants.SEARCH + SEARCH_QUERY);
    HttpResponse response = handle(request);
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    HttpEntity entity = response.getEntity();
    try {
        String content = EntityUtils.toString(entity);
        GluuAttribute[] gluuAttributes = mapper.readValue(content, GluuAttribute[].class);
        Assert.assertTrue(gluuAttributes.length >= 1);
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) GluuAttribute(org.gluu.model.GluuAttribute) Test(org.junit.Test)

Example 24 with GluuAttribute

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

the class AttributeWebResourceTest method getGluuAtrribute.

private GluuAttribute getGluuAtrribute(String name) {
    GluuAttribute attribute = new GluuAttribute();
    attribute.setName(name);
    attribute.setDisplayName(name);
    attribute.setDescription("custom attribute");
    attribute.setDataType(AttributeDataType.STRING);
    attribute.setStatus(GluuStatus.ACTIVE);
    attribute.setOxMultiValuedAttribute(Boolean.FALSE);
    return attribute;
}
Also used : GluuAttribute(org.gluu.model.GluuAttribute)

Example 25 with GluuAttribute

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

the class AttributeWebResourceTest method getInActiveAttributesTest.

@Test
public void getInActiveAttributesTest() {
    HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.ATTRIBUTES + ApiConstants.INACTIVE);
    HttpResponse response = handle(request);
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    HttpEntity entity = response.getEntity();
    try {
        String content = EntityUtils.toString(entity);
        GluuAttribute[] gluuAttributes = mapper.readValue(content, GluuAttribute[].class);
        Assert.assertTrue(gluuAttributes.length > 10);
        for (GluuAttribute gluuAttribute : gluuAttributes) {
            Assert.assertTrue(gluuAttribute.getStatus().getValue().equalsIgnoreCase("inactive"));
        }
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) GluuAttribute(org.gluu.model.GluuAttribute) Test(org.junit.Test)

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