use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.
the class CopyUtils method copy.
/**
* Copy data from GluuCustomPerson object to ScimPerson object "Reda"
*
* @param source
* @param destination
* @return
* @throws Exception
*/
public ScimPerson copy(GluuCustomPerson source, ScimPerson destination) throws Exception {
if (source == null) {
return null;
}
if (destination == null) {
log.trace(" creating a new GluuCustomPerson instant ");
destination = new ScimPerson();
}
destination.getSchemas().add(Constants.SCIM1_CORE_SCHEMA_ID);
log.trace(" setting ID ");
if (source.getInum() != null) {
destination.setId(source.getInum());
}
log.trace(" setting userName ");
if (source.getUid() != null) {
destination.setUserName(source.getUid());
}
log.trace(" setting ExternalID ");
if (source.getAttribute(OX_TRUST_EXTERNAL_ID) != null) {
destination.setExternalId(source.getAttribute(OX_TRUST_EXTERNAL_ID));
}
log.trace(" setting givenname ");
if (source.getGivenName() != null) {
destination.getName().setGivenName(source.getGivenName());
}
log.trace(" getting family name ");
if (source.getSurname() != null) {
destination.getName().setFamilyName(source.getSurname());
}
log.trace(" getting middlename ");
if (source.getAttribute(OX_TRUST_MIDDLE_NAME) != null) {
destination.getName().setMiddleName(source.getAttribute(OX_TRUST_MIDDLE_NAME));
}
;
log.trace(" getting honorificPrefix ");
if (source.getAttribute(OX_TRUSTHONORIFIC_PREFIX) != null) {
destination.getName().setHonorificPrefix(source.getAttribute(OX_TRUSTHONORIFIC_PREFIX));
}
;
log.trace(" getting honorificSuffix ");
if (source.getAttribute(OX_TRUSTHONORIFIC_SUFFIX) != null) {
destination.getName().setHonorificSuffix(source.getAttribute(OX_TRUSTHONORIFIC_SUFFIX));
}
;
log.trace(" getting displayname ");
if (source.getDisplayName() != null) {
destination.setDisplayName(source.getDisplayName());
}
log.trace(" getting nickname ");
if (source.getAttribute(OX_TRUST_NICK_NAME) != null) {
destination.setNickName(source.getAttribute(OX_TRUST_NICK_NAME));
}
log.trace(" getting profileURL ");
if (source.getAttribute(OX_TRUST_PROFILE_URL) != null) {
destination.setProfileUrl(source.getAttribute(OX_TRUST_PROFILE_URL));
}
log.trace(" getting emails ");
// if (source.getAttribute(OX_TRUST_EMAIL) != null) {
if (source.getAttributeArray(OX_TRUST_EMAIL) != null) {
// List<ScimPersonEmails> listOfEmails = mapper.readValue(source.getAttribute(OX_TRUST_EMAIL), new TypeReference<List<ScimPersonEmails>>(){});
/*
* List<ScimPersonEmails> emails = new
* ArrayList<ScimPersonEmails>(); String[] listEmails =
* source.getAttributes("oxTrustEmail"); String[] listEmailTyps =
* source.getAttributes("oxTrustEmailType"); String[]
* listEmailPrimary = source.getAttributes("oxTrustEmailPrimary");
* for(int i = 0 ; i<listEmails.length ; i++ ){ ScimPersonEmails
* oneEmail = new ScimPersonEmails();
* oneEmail.setValue(listEmails[i]);
* oneEmail.setType(listEmailTyps[i]);
* oneEmail.setPrimary(listEmailPrimary[i]); emails.add(oneEmail); }
*/
// destination.setEmails(listOfEmails);
/*
String[] emailArray = source.getAttributeArray(OX_TRUST_EMAIL);
List<ScimPersonEmails> emails = new ArrayList<ScimPersonEmails>();
for (String emailStr : emailArray) {
ScimPersonEmails email = mapper.readValue(emailStr, ScimPersonEmails.class);
emails.add(email);
}
*/
List<ScimPersonEmails> emails = getAttributeListValue(source, ScimPersonEmails.class, OX_TRUST_EMAIL);
destination.setEmails(emails);
}
log.trace(" getting addresses ");
// getting addresses
if (source.getAttribute(OX_TRUST_ADDRESSES) != null) {
// List<ScimPersonAddresses> listOfAddresses = mapper.readValue(source.getAttribute(OX_TRUST_ADDRESSES), new TypeReference<List<ScimPersonAddresses>>(){});
/*
* List<ScimPersonAddresses> addresses = new
* ArrayList<ScimPersonAddresses>(); String[] listStreets =
* source.getAttributes("oxTrustStreet"); String[] listAddressTypes
* = source.getAttributes("oxTrustAddressType"); String[]
* listLocalities = source.getAttributes("oxTrustLocality");
* String[] listRegions = source.getAttributes("oxTrustRegion");
* String[] listPostalCodes =
* source.getAttributes("oxTrustPostalCode"); String[] listCountries
* = source.getAttributes("oxTrustCountry"); String[]
* listAddressFormatted =
* source.getAttributes("oxTrustAddressFormatted"); String[]
* listAddressPrimary =
* source.getAttributes("oxTrustAddressPrimary");
* if(listStreets.length > 0){ for(int i = 0 ; i <
* listStreets.length ; i++ ){ ScimPersonAddresses address = new
* ScimPersonAddresses();
*
* if(!listAddressFormatted[i].equalsIgnoreCase("empty")){address.
* setFormatted
* (listAddressFormatted[i]);}else{address.setFormatted("");}
* if(!listStreets
* [i].equalsIgnoreCase("empty")){address.setStreetAddress
* (listStreets[i]);}else{address.setStreetAddress("");}
* if(!listAddressTypes
* [i].equalsIgnoreCase("empty")){address.setType
* (listAddressTypes[i]);}else{address.setType("");}
* if(!listLocalities
* [i].equalsIgnoreCase("empty")){address.setLocality
* (listLocalities[i]);}else{address.setLocality("");}
* if(!listRegions
* [i].equalsIgnoreCase("empty")){address.setRegion(listRegions
* [i]);}else{address.setRegion("");}
* if(!listPostalCodes[i].equalsIgnoreCase
* ("empty")){address.setPostalCode
* (listPostalCodes[i]);}else{address.setPostalCode("");}
* if(!listCountries
* [i].equalsIgnoreCase("empty")){address.setCountry
* (listCountries[i]);}else{address.setCountry("");}
* if(!listAddressPrimary
* [i].equalsIgnoreCase("empty")){address.setPrimary
* (listAddressPrimary[i]);}else{address.setPrimary("");}
* addresses.add(address);
*
* } }
*/
// destination.setAddresses(listOfAddresses);
List<ScimPersonAddresses> addresses = getAttributeListValue(source, ScimPersonAddresses.class, OX_TRUST_ADDRESSES);
destination.setAddresses(addresses);
}
log.trace(" setting phoneNumber ");
// getting user's PhoneNumber
if (source.getAttribute(OX_TRUST_PHONE_VALUE) != null) {
// List<ScimPersonPhones> listOfPhones = mapper.readValue(source.getAttribute(OX_TRUST_PHONE_VALUE), new TypeReference<List<ScimPersonPhones>>(){});
/*
* List<ScimPersonPhones> phones = new
* ArrayList<ScimPersonPhones>(); String[] listNumbers =
* source.getAttributes("oxTrustPhoneValue"); String[]
* listPhoneTypes = source.getAttributes("oxTrustPhoneType");
* if(listNumbers.length > 0){ for(int i = 0 ; i <
* listNumbers.length ; i++){ ScimPersonPhones phone = new
* ScimPersonPhones();
* if(!listNumbers[i].equalsIgnoreCase("empty")){
* phone.setValue(listNumbers[i]);}else{phone.setValue("");}
* if(!listPhoneTypes
* [i].equalsIgnoreCase("empty")){phone.setType(listPhoneTypes
* [i]);}else{phone.setType("");} phones.add(phone);
*
* } }
*/
// destination.setPhoneNumbers(listOfPhones);
List<ScimPersonPhones> phoneNumbers = getAttributeListValue(source, ScimPersonPhones.class, OX_TRUST_PHONE_VALUE);
destination.setPhoneNumbers(phoneNumbers);
}
log.trace(" getting ims ");
// getting ims
if (source.getAttribute(OX_TRUST_IMS_VALUE) != null) {
// List<ScimPersonIms> listOfIms = mapper.readValue(source.getAttribute(OX_TRUST_IMS_VALUE), new TypeReference<List<ScimPersonIms>>(){});
/*
* List<ScimPersonIms> ims = new ArrayList<ScimPersonIms>();
* String[] imValues = source.getAttributes("oxTrustImsValue");
* String[] imTypes = source.getAttributes("oxTrustImsType");
* if(imValues.length > 0){ for(int i = 0 ; i < imValues.length ;
* i++){ ScimPersonIms im = new ScimPersonIms(); if(imValues[i] !=
* null){im.setValue(imValues[i]);im.setType(imTypes[i]);}
* ims.add(im); } }
*/
// destination.setIms(listOfIms);
List<ScimPersonIms> ims = getAttributeListValue(source, ScimPersonIms.class, OX_TRUST_IMS_VALUE);
destination.setIms(ims);
}
log.trace(" setting photos ");
// getting photos
if (source.getAttribute(OX_TRUST_PHOTOS) != null) {
// List<ScimPersonPhotos> listOfPhotos = mapper.readValue(source.getAttribute(OX_TRUST_PHOTOS), new TypeReference<List<ScimPersonPhotos>>(){});
/*
* List<ScimPersonPhotos> photos = new
* ArrayList<ScimPersonPhotos>(); String[] photoList =
* source.getAttributes("oxTrustPhotos"); String[] photoTypes =
* source.getAttributes("oxTrustPhotosType");
*
* if(photoList.length > 0){ for(int i = 0 ; i < photoList.length ;
* i++){
*
* ScimPersonPhotos photo = new ScimPersonPhotos(); if(photoList[i]
* !=
* null){photo.setValue(photoList[i]);photo.setType(photoTypes[i]);}
* photos.add(photo); } }
*/
// destination.setPhotos(listOfPhotos);
List<ScimPersonPhotos> photos = getAttributeListValue(source, ScimPersonPhotos.class, OX_TRUST_PHOTOS);
destination.setPhotos(photos);
}
log.trace(" setting userType ");
if (source.getAttribute(OX_TRUST_USER_TYPE) != null) {
destination.setUserType(source.getAttribute(OX_TRUST_USER_TYPE));
}
log.trace(" setting title ");
if (source.getAttribute(OX_TRUST_TITLE) != null) {
destination.setTitle(source.getAttribute(OX_TRUST_TITLE));
}
log.trace(" setting Locale ");
if (source.getAttribute(OX_TRUST_LOCALE) != null) {
destination.setLocale(source.getAttribute(OX_TRUST_LOCALE));
}
log.trace(" setting preferredLanguage ");
if (source.getPreferredLanguage() != null) {
destination.setPreferredLanguage(source.getPreferredLanguage());
}
log.trace(" setting timeZone ");
if (source.getTimezone() != null) {
destination.setTimezone(source.getTimezone());
}
log.trace(" setting active ");
if (source.getAttribute(OX_TRUST_ACTIVE) != null) {
destination.setActive(source.getAttribute(OX_TRUST_ACTIVE));
}
log.trace(" setting password ");
destination.setPassword("Hidden for Privacy Reasons");
// getting user groups
log.trace(" setting groups ");
if (source.getMemberOf() != null) {
List<String> listOfGroups = source.getMemberOf();
List<ScimPersonGroups> groupsList = new ArrayList<ScimPersonGroups>();
for (String groupDN : listOfGroups) {
ScimPersonGroups group = new ScimPersonGroups();
GluuGroup gluuGroup = groupService.getGroupByDn(groupDN);
group.setValue(gluuGroup.getInum());
group.setDisplay(gluuGroup.getDisplayName());
groupsList.add(group);
}
destination.setGroups(groupsList);
}
// getting roles
if (source.getAttribute(OX_TRUST_ROLE) != null) {
// List<ScimRoles> listOfRoles = mapper.readValue(source.getAttribute(OX_TRUST_ROLE), new TypeReference<List<ScimRoles>>(){});
/*
* List<ScimRoles> roles = new ArrayList<ScimRoles>(); String[]
* listRoles = source.getAttributes("oxTrustRole");
* if(listRoles.length > 0){ for(int i = 0 ; i < listRoles.length
* ;i++){ ScimRoles role = new ScimRoles(); if(listRoles[i] !=
* null){role.setValue(listRoles[i]);} roles.add(role); } }
*/
// destination.setRoles(listOfRoles);
List<ScimRoles> roles = getAttributeListValue(source, ScimRoles.class, OX_TRUST_ROLE);
destination.setRoles(roles);
}
log.trace(" getting entitlements ");
// getting entitlements
if (source.getAttribute(OX_TRUST_ENTITLEMENTS) != null) {
// List<ScimEntitlements> listOfEnts = mapper.readValue(source.getAttribute(OX_TRUST_ENTITLEMENTS), new TypeReference<List<ScimEntitlements>>(){});
/*
* List<ScimEntitlements> entitlements = new
* ArrayList<ScimEntitlements>(); String[] listEntitlements =
* source.getAttributes("oxTrustEntitlements");
* if(listEntitlements.length > 0){ for(int i = 0 ; i <
* listEntitlements.length ; i++ ){ ScimEntitlements ent = new
* ScimEntitlements(); if(listEntitlements[i] !=
* null){ent.setValue(listEntitlements[i]);} entitlements.add(ent);
* } }
*/
// destination.setEntitlements(listOfEnts);
List<ScimEntitlements> entitlements = getAttributeListValue(source, ScimEntitlements.class, OX_TRUST_ENTITLEMENTS);
destination.setEntitlements(entitlements);
}
// getting x509Certificates
log.trace(" setting certs ");
if (source.getAttribute(OX_TRUSTX509_CERTIFICATE) != null) {
// List<Scimx509Certificates> listOfCerts = mapper.readValue(source.getAttribute(OX_TRUSTX509_CERTIFICATE), new TypeReference<List<Scimx509Certificates>>(){});
/*
* List<Scimx509Certificates> certificates = new
* ArrayList<Scimx509Certificates>(); String[] listCertif =
* source.getAttributes("oxTrustx509Certificate");
* if(listCertif.length > 0){ for(int i = 0 ; i < listCertif.length
* ; i++){ Scimx509Certificates cert = new Scimx509Certificates();
* if(listCertif[i] != null){cert.setValue(listCertif[i]);}
* certificates.add(cert);
*
* } }
*/
// destination.setX509Certificates(listOfCerts);
List<Scimx509Certificates> x509Certificates = getAttributeListValue(source, Scimx509Certificates.class, OX_TRUSTX509_CERTIFICATE);
destination.setX509Certificates(x509Certificates);
}
log.trace(" setting meta ");
// getting meta data
if (source.getAttribute(OX_TRUST_META_CREATED) != null) {
destination.getMeta().setCreated(source.getAttribute(OX_TRUST_META_CREATED));
}
if (source.getAttribute(OX_TRUST_META_LAST_MODIFIED) != null) {
destination.getMeta().setLastModified(source.getAttribute(OX_TRUST_META_LAST_MODIFIED));
}
if (source.getAttribute(OX_TRUST_META_VERSION) != null) {
destination.getMeta().setVersion(source.getAttribute(OX_TRUST_META_VERSION));
}
// if (source.getAttribute(OX_TRUST_META_LOCATION) != null) {
// destination.getMeta().setLocation(source.getAttribute(OX_TRUST_META_LOCATION));
String location = source.getAttribute(OX_TRUST_META_LOCATION);
if (location != null && !location.isEmpty()) {
if (!location.startsWith("https://") && !location.startsWith("http://")) {
location = appConfiguration.getBaseEndpoint() + location;
}
} else {
location = appConfiguration.getBaseEndpoint() + "/scim/v1/Users/" + source.getInum();
}
destination.getMeta().setLocation(location);
// }
log.trace(" getting custom Attributes ");
// getting custom Attributes
List<GluuAttribute> listOfAttr = attributeService.getSCIMRelatedAttributes();
if (listOfAttr != null && listOfAttr.size() > 0) {
List<ScimCustomAttributes> listOfCustomAttr = new ArrayList<ScimCustomAttributes>();
for (GluuAttribute attr : listOfAttr) {
boolean isEmpty = attr.getOxMultivaluedAttribute() == null;
if (!isEmpty && attr.getOxMultivaluedAttribute().getValue().equalsIgnoreCase("true")) {
boolean isAttrEmpty = source.getAttributes(attr.getName()) == null;
if (!isAttrEmpty) {
String[] arrayValues = source.getAttributes(attr.getName());
List<String> values = new ArrayList<String>(Arrays.asList(arrayValues));
ScimCustomAttributes scimAttr = new ScimCustomAttributes();
scimAttr.setName(attr.getName());
scimAttr.setValues(values);
listOfCustomAttr.add(scimAttr);
}
} else {
boolean isAttrEmpty = source.getAttributes(attr.getName()) == null;
if (!isAttrEmpty) {
List<String> values = new ArrayList<String>();
values.add(source.getAttribute(attr.getName()));
ScimCustomAttributes scimAttr = new ScimCustomAttributes();
scimAttr.setName(attr.getName());
scimAttr.setValues(values);
listOfCustomAttr.add(scimAttr);
}
}
}
if (listOfCustomAttr.size() > 0) {
destination.setCustomAttributes(listOfCustomAttr);
}
}
log.trace(" returning destination ");
return destination;
}
use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.
the class CopyUtils2 method copy.
/**
* Copy data from GluuCustomPerson object to Person object
*
* @param source
* @param destination
* @return
* @throws Exception
*/
public Person copy(GluuCustomPerson source, Person destination, List<GluuAttribute> attributes) {
if (source == null) {
return null;
}
if (destination == null) {
destination = new Person();
}
destination.setInum(source.getInum());
destination.setIname(source.getIname());
destination.setUserId(source.getUid());
destination.setFirstName(source.getGivenName());
destination.setDisplayName(source.getDisplayName());
destination.setLastName(source.getSurname());
destination.setEmail(source.getMail());
destination.setPassword(source.getUserPassword());
destination.setCommonName(source.getGivenName() + " " + source.getDisplayName());
List<PersonAttribute> personAttrList = new ArrayList<PersonAttribute>();
for (GluuAttribute attribute : attributes) {
PersonAttribute personAttr = new PersonAttribute(attribute.getName(), source.getAttribute(attribute.getName()), attribute.getDisplayName());
personAttrList.add(personAttr);
}
destination.setPersonAttrList(personAttrList);
return destination;
}
use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.
the class UserExtensionLoadingStrategy method load.
@Override
public SchemaType load(AppConfiguration appConfiguration, SchemaType schemaType) throws Exception {
log.info(" load() ");
Meta meta = new Meta();
meta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
meta.setResourceType("Schema");
schemaType.setMeta(meta);
// List<GluuAttribute> scimCustomAttributes = attributeService.getSCIMRelatedAttributesImpl(attributeService.getCustomAttributes());
List<GluuAttribute> scimCustomAttributes = attributeService.getSCIMRelatedAttributes();
List<AttributeHolder> attributeHolders = new ArrayList<AttributeHolder>();
for (GluuAttribute scimCustomAttribute : scimCustomAttributes) {
AttributeHolder attributeHolder = new AttributeHolder();
attributeHolder.setName(scimCustomAttribute.getName());
if (scimCustomAttribute.getDataType() != null) {
String typeStr = "";
GluuAttributeDataType attributeDataType = scimCustomAttribute.getDataType();
if (attributeDataType.equals(GluuAttributeDataType.STRING)) {
typeStr = "string";
} else if (attributeDataType.equals(GluuAttributeDataType.PHOTO)) {
typeStr = "reference";
attributeHolder.getReferenceTypes().add("external");
} else if (attributeDataType.equals(GluuAttributeDataType.DATE)) {
typeStr = "dateTime";
} else if (attributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
typeStr = "decimal";
} else {
log.info(" NO MATCH: scimCustomAttribute.getDataType().getDisplayName() = " + scimCustomAttribute.getDataType().getDisplayName());
typeStr = "string";
}
attributeHolder.setType(typeStr);
}
attributeHolder.setDescription(scimCustomAttribute.getDescription());
attributeHolder.setRequired(scimCustomAttribute.isRequred());
if (scimCustomAttribute.getOxMultivaluedAttribute() != null) {
Boolean multiValued = Boolean.parseBoolean(scimCustomAttribute.getOxMultivaluedAttribute().getValue());
attributeHolder.setMultiValued(multiValued);
}
attributeHolders.add(attributeHolder);
}
UserExtensionSchema userExtensionSchema = (UserExtensionSchema) schemaType;
userExtensionSchema.setAttributeHolders(attributeHolders);
return userExtensionSchema;
}
use of org.xdi.model.GluuAttribute in project oxAuth by GluuFederation.
the class AttributeService method getAttributeByDn.
/**
* returns GluuAttribute by Dn
*
* @return GluuAttribute
*/
public GluuAttribute getAttributeByDn(String dn) {
GluuAttribute gluuAttribute = (GluuAttribute) cacheService.get(CACHE_ATTRIBUTE, dn);
if (gluuAttribute == null) {
gluuAttribute = ldapEntryManager.find(GluuAttribute.class, dn);
cacheService.put(CACHE_ATTRIBUTE, dn, gluuAttribute);
} else {
log.trace("Get attribute from cache by Dn '{}'", dn);
}
return gluuAttribute;
}
use of org.xdi.model.GluuAttribute in project oxTrust by GluuFederation.
the class TrustRelationshipInventoryAction method setCustomAttributes.
private void setCustomAttributes(List<GluuSAMLTrustRelationship> trustRelationships) {
List<GluuAttribute> attributes = attributeService.getAllPersonAttributes(GluuUserRole.ADMIN);
HashMap<String, GluuAttribute> attributesByDNs = attributeService.getAttributeMapByDNs(attributes);
for (GluuSAMLTrustRelationship trustRelationship : trustRelationships) {
trustRelationship.setReleasedCustomAttributes(attributeService.getCustomAttributesByAttributeDNs(trustRelationship.getReleasedAttributes(), attributesByDNs));
}
}
Aggregations