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;
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations