use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.
the class CopyUtils2 method copy.
/**
* Copy data from Person object to GluuCustomPerson object
*
* @param source
* @param destination
* @return
* @throws Exception
*/
public GluuCustomPerson copy(Person source, GluuCustomPerson destination, List<GluuAttribute> attributes, GluuUserRole role, boolean isUpdate) {
if (source == null || !isValidData(source, isUpdate)) {
return null;
}
if (destination == null) {
destination = new GluuCustomPerson();
}
if (source.getPersonAttrList() != null) {
for (PersonAttribute personAttr : source.getPersonAttrList()) {
GluuAttribute attribute = getAttribute(attributes, personAttr.getName());
if (attribute == null || attribute.getEditType() == null || !containsRole(attribute.getEditType(), role))
continue;
destination.setAttribute(personAttr.getName(), personAttr.getValue());
}
}
if (!isUpdate) {
destination.setUid(source.getUserId());
destination.setUserPassword(source.getPassword());
destination.setGivenName(source.getFirstName());
destination.setDisplayName(source.getDisplayName());
destination.setSurname(source.getLastName());
destination.setMail(source.getEmail());
destination.setCommonName(source.getFirstName() + " " + source.getDisplayName());
} else {
if (!isEmpty(source.getFirstName()))
destination.setGivenName(source.getFirstName());
if (!isEmpty(source.getDisplayName()))
destination.setDisplayName(source.getDisplayName());
if (!isEmpty(source.getLastName()))
destination.setSurname(source.getLastName());
if (!isEmpty(source.getEmail()))
destination.setMail(source.getEmail());
if (!isEmpty(source.getFirstName()) && !isEmpty(source.getDisplayName()))
destination.setCommonName(source.getFirstName() + " " + source.getDisplayName());
}
return destination;
}
use of org.xdi.model.GluuAttribute in project oxCore by GluuFederation.
the class AttributeService method getAttributesByAttribute.
public List<GluuAttribute> getAttributesByAttribute(String attributeName, String attributeValue, String baseDn) {
String[] targetArray = new String[] { attributeValue };
Filter filter = Filter.createSubstringFilter(attributeName, null, targetArray, null);
List<GluuAttribute> result = ldapEntryManager.findEntries(baseDn, GluuAttribute.class, filter);
return result;
}
use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.
the class UserExtensionsTest method testCreatePersonFromUserObject.
@Test(dependsOnMethods = "testCreatePersonFromJsonString")
@Parameters
public void testCreatePersonFromUserObject() throws Exception {
System.out.println(" testCreatePersonFromUserObject() ");
// Create custom attributes
// String, not
GluuAttribute scimCustomFirst = null;
// multi-valued
if (attributeService.getAttributeByName("scimCustomFirst") == null) {
scimCustomFirst = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomFirst", "Custom First", "First custom attribute", GluuAttributeDataType.STRING, OxMultivalued.FALSE);
}
// Date, multi-valued
GluuAttribute scimCustomSecond = null;
if (attributeService.getAttributeByName("scimCustomSecond") == null) {
scimCustomSecond = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomSecond", "Custom Second", "Second custom attribute", GluuAttributeDataType.DATE, OxMultivalued.TRUE);
}
// Numeric, not
GluuAttribute scimCustomThird = null;
// multi-valued
if (attributeService.getAttributeByName("scimCustomThird") == null) {
scimCustomThird = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomThird", "Custom Third", "Third custom attribute", GluuAttributeDataType.NUMERIC, OxMultivalued.FALSE);
}
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
User user = createUserObject();
// Create Person
GluuCustomPerson gluuPerson = copyUtils2.copy(user, null, false);
assertNotNull(gluuPerson, "gluuPerson is null!");
System.out.println(">>>>>>>>>> gluuPerson.getUid() = " + gluuPerson.getUid());
String inum = personService.generateInumForNewPerson();
String dn = personService.getDnForPerson(inum);
String iname = personService.generateInameForNewPerson(user.getUserName());
gluuPerson.setDn(dn);
gluuPerson.setInum(inum);
gluuPerson.setIname(iname);
gluuPerson.setCommonName(gluuPerson.getGivenName() + " " + gluuPerson.getSurname());
personService.addPerson(gluuPerson);
// Retrieve Person
GluuCustomPerson retrievedPerson = personService.getPersonByUid(gluuPerson.getUid());
assertNotNull(retrievedPerson, "Failed to find person.");
User newPerson = copyUtils2.copy(retrievedPerson, null);
Extension extension = newPerson.getExtension(Constants.USER_EXT_SCHEMA_ID);
assertNotNull(extension, "(Persistence) Custom extension not persisted.");
Extension.Field customFirstField = extension.getFields().get("scimCustomFirst");
assertNotNull(customFirstField, "(Persistence) \"scimCustomFirst\" field not persisted.");
assertEquals(customFirstField.getValue(), "customFirstValue");
System.out.println("##### (Persistence) customFirstField.getValue() = " + customFirstField.getValue());
Extension.Field customSecondField = extension.getFields().get("scimCustomSecond");
assertNotNull(customSecondField, "(Persistence) \"scimCustomSecond\" field not persisted.");
List<Date> dateList = Arrays.asList(mapper.readValue(customSecondField.getValue(), Date[].class));
assertEquals(dateList.size(), 2);
System.out.println("##### (Persistence) dateList.get(0) = " + dateList.get(0));
System.out.println("##### (Persistence) dateList.get(1) = " + dateList.get(1));
Extension.Field customThirdField = extension.getFields().get("scimCustomThird");
assertNotNull(customThirdField, "(Persistence) \"scimCustomThird\" field not persisted.");
assertEquals(new BigDecimal(customThirdField.getValue()), new BigDecimal(3000));
System.out.println("##### (Persistence) customThirdField.getValue() = " + customThirdField.getValue());
// Remove Person
memberService.removePerson(retrievedPerson);
// Remove custom attributes
// schemaService.removeAttributeTypeFromObjectClass(scimCustomFirst.getOrigin(),
// scimCustomFirst.getName());
// schemaService.removeStringAttribute(scimCustomFirst.getName());
// attributeService.removeAttribute(scimCustomFirst);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomSecond.getOrigin(),
// scimCustomSecond.getName());
// schemaService.removeStringAttribute(scimCustomSecond.getName());
// attributeService.removeAttribute(scimCustomSecond);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomThird.getOrigin(),
// scimCustomThird.getName());
// schemaService.removeStringAttribute(scimCustomThird.getName());
// attributeService.removeAttribute(scimCustomThird);
}
use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.
the class UserExtensionsTest method createCustomAttribute.
private GluuAttribute createCustomAttribute(AttributeService attributeService, SchemaService schemaService, AppConfiguration appConfiguration, String name, String displayName, String description, GluuAttributeDataType gluuAttributeDataType, OxMultivalued oxMultivalued) throws Exception {
System.out.println(" createCustomAttribute() ");
String objectClassName = attributeService.getCustomOrigin();
String ldapAttributedName = attributeService.generateRandomOid();
String inum = attributeService.generateInumForNewAttribute();
String dn = attributeService.getDnForAttribute(inum);
GluuAttribute gluuAttribute = new GluuAttribute();
gluuAttribute.setRequred(false);
gluuAttribute.setName(name);
gluuAttribute.setDisplayName(displayName);
gluuAttribute.setDescription(description);
gluuAttribute.setOrigin(objectClassName);
gluuAttribute.setStatus(GluuStatus.ACTIVE);
gluuAttribute.setEditType(new GluuUserRole[] { GluuUserRole.ADMIN, GluuUserRole.MANAGER, GluuUserRole.OWNER, GluuUserRole.USER });
gluuAttribute.setDataType(gluuAttributeDataType);
gluuAttribute.setCustom(true);
gluuAttribute.setOxSCIMCustomAttribute(ScimCustomAtribute.TRUE);
gluuAttribute.setOxMultivaluedAttribute(oxMultivalued);
gluuAttribute.setInum(inum);
gluuAttribute.setDn(dn);
if (gluuAttribute.getSaml1Uri() == null || gluuAttribute.getSaml1Uri().equals("")) {
gluuAttribute.setSaml1Uri("urn:gluu:dir:attribute-def:" + gluuAttribute);
}
if (gluuAttribute.getSaml2Uri() == null || gluuAttribute.getSaml2Uri().equals("")) {
gluuAttribute.setSaml2Uri("urn:oid:" + gluuAttribute);
}
// We don't support schema update at runtime
// schemaService.addStringAttribute(ldapAttributedName, name,
// appConfiguration.getSchemaAddAttributeDefinition());
schemaService.addAttributeTypeToObjectClass(objectClassName, name);
attributeService.addAttribute(gluuAttribute);
return gluuAttribute;
}
use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.
the class UpdateAttributeAction method add.
public String add() {
if (this.attribute != null) {
return OxTrustConstants.RESULT_SUCCESS;
}
this.update = false;
this.showAttributeDeleteConfirmation = false;
this.attribute = new GluuAttribute();
attribute.setAttributeValidation(new AttributeValidation());
this.attribute.setStatus(GluuStatus.ACTIVE);
this.attribute.setEditType(new GluuUserRole[] { GluuUserRole.ADMIN });
this.canEdit = true;
return OxTrustConstants.RESULT_SUCCESS;
}
Aggregations