use of org.gluu.oxtrust.model.scim2.Meta in project oxTrust by GluuFederation.
the class CopyUtils2 method copy.
/**
* Copy data from ScimPerson object to GluuCustomPerson object "Reda"
*
* @param source
* @param destination
* @return
* @throws Exception
*/
public GluuCustomPerson copy(User source, GluuCustomPerson destination, boolean isUpdate) throws Exception {
if (source == null || !isValidData(source, isUpdate)) {
return null;
}
if (destination == null) {
log.trace(" creating a new GluuCustomPerson instant ");
destination = new GluuCustomPerson();
}
log.trace(" setting schemas ");
destination.setSchemas(source.getSchemas());
if (isUpdate) {
personService.addCustomObjectClass(destination);
log.trace(" setting userName ");
if (source.getUserName() != null && source.getUserName().length() > 0) {
destination.setUid(source.getUserName());
}
if (source.getName() != null) {
log.trace(" setting givenname ");
if (source.getName().getGivenName() != null && source.getName().getGivenName().length() > 0) {
destination.setGivenName(source.getName().getGivenName());
}
log.trace(" setting famillyname ");
if (source.getName().getFamilyName() != null && source.getName().getFamilyName().length() > 0) {
destination.setSurname(source.getName().getFamilyName());
}
log.trace(" setting middlename ");
if (source.getName().getMiddleName() != null && source.getName().getMiddleName().length() > 0) {
// destination.setAttribute("oxTrustMiddleName", source.getName().getMiddleName());
destination.setAttribute("middleName", source.getName().getMiddleName());
}
log.trace(" setting honor");
if (source.getName().getHonorificPrefix() != null && source.getName().getHonorificPrefix().length() > 0) {
destination.setAttribute("oxTrusthonorificPrefix", source.getName().getHonorificPrefix());
}
if (source.getName().getHonorificSuffix() != null && source.getName().getHonorificSuffix().length() > 0) {
destination.setAttribute("oxTrusthonorificSuffix", source.getName().getHonorificSuffix());
}
}
log.trace(" setting displayname ");
if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
destination.setDisplayName(source.getDisplayName());
}
log.trace(" setting externalID ");
if (source.getExternalId() != null && source.getExternalId().length() > 0) {
destination.setAttribute("oxTrustExternalId", source.getExternalId());
}
log.trace(" setting nickname ");
if (source.getNickName() != null && source.getNickName().length() > 0) {
// destination.setAttribute("oxTrustNickName", source.getNickName());
destination.setAttribute("nickname", source.getNickName());
}
log.trace(" setting profileURL ");
if (source.getProfileUrl() != null && source.getProfileUrl().length() > 0) {
destination.setAttribute("oxTrustProfileURL", source.getProfileUrl());
}
// getting emails
log.trace(" setting emails ");
if (source.getEmails() != null && source.getEmails().size() > 0) {
/*
List<Email> emails = source.getEmails();
// StringWriter listOfEmails = new StringWriter();
// mapper.writeValue(listOfEmails, emails);
List<String> emailList = new ArrayList<String>();
for (Email email : emails) {
emailList.add(mapper.writeValueAsString(email));
}
// destination.setAttribute("oxTrustEmail", listOfEmails.toString());
destination.setAttribute("oxTrustEmail", emailList.toArray(new String[]{}));
*/
setAttributeListValue(destination, source.getEmails(), "oxTrustEmail");
}
// getting addresses
log.trace(" setting addresses ");
if (source.getAddresses() != null && source.getAddresses().size() > 0) {
setAttributeListValue(destination, source.getAddresses(), "oxTrustAddresses");
}
// getting phone numbers;
log.trace(" setting phoneNumbers ");
if (source.getPhoneNumbers() != null && source.getPhoneNumbers().size() > 0) {
setAttributeListValue(destination, source.getPhoneNumbers(), "oxTrustPhoneValue");
}
// getting ims
log.trace(" setting ims ");
if (source.getIms() != null && source.getIms().size() > 0) {
setAttributeListValue(destination, source.getIms(), "oxTrustImsValue");
}
// getting Photos
log.trace(" setting photos ");
if (source.getPhotos() != null && source.getPhotos().size() > 0) {
setAttributeListValue(destination, source.getPhotos(), "oxTrustPhotos");
}
if (source.getUserType() != null && source.getUserType().length() > 0) {
destination.setAttribute("oxTrustUserType", source.getUserType());
}
if (source.getTitle() != null && source.getTitle().length() > 0) {
destination.setAttribute("oxTrustTitle", source.getTitle());
}
if (source.getPreferredLanguage() != null && source.getPreferredLanguage().length() > 0) {
destination.setPreferredLanguage(source.getPreferredLanguage());
}
if (source.getLocale() != null && source.getLocale().length() > 0) {
// destination.setAttribute("oxTrustLocale", source.getLocale());
destination.setAttribute("locale", source.getLocale());
}
if (source.getTimezone() != null && source.getTimezone().length() > 0) {
destination.setTimezone(source.getTimezone());
}
if (source.isActive() != null) {
destination.setAttribute("oxTrustActive", source.isActive().toString());
}
if (source.getPassword() != null && source.getPassword().length() > 0) {
destination.setUserPassword(source.getPassword());
}
// getting user groups
log.trace(" setting groups ");
if (source.getGroups() != null && source.getGroups().size() > 0) {
List<GroupRef> listGroups = source.getGroups();
List<String> members = new ArrayList<String>();
for (GroupRef group : listGroups) {
members.add(groupService.getDnForGroup(group.getValue()));
}
destination.setMemberOf(members);
}
// getting roles
log.trace(" setting roles ");
if (source.getRoles() != null && source.getRoles().size() > 0) {
setAttributeListValue(destination, source.getRoles(), "oxTrustRole");
}
// getting entitlements
log.trace(" setting entitlements ");
if (source.getEntitlements() != null && source.getEntitlements().size() > 0) {
setAttributeListValue(destination, source.getEntitlements(), "oxTrustEntitlements");
}
// getting x509Certificates
log.trace(" setting certs ");
if (source.getX509Certificates() != null && source.getX509Certificates().size() > 0) {
setAttributeListValue(destination, source.getX509Certificates(), "oxTrustx509Certificate");
}
log.trace(" setting extensions ");
if (source.getExtensions() != null && (source.getExtensions().size() > 0)) {
destination.setExtensions(source.getExtensions());
}
/*
// getting customAttributes
log.trace("getting custom attributes");
if (source.getCustomAttributes() != null) {
log.trace("source.getCustomAttributes() != null");
log.trace("getting a list of ScimCustomAttributes");
List<CustomAttributes> customAttr = source.getCustomAttributes();
log.trace("checling every attribute in the request");
for (CustomAttributes oneAttr : customAttr) {
if (oneAttr == null) {
continue;
}
int countValues = oneAttr.getValues().size();
if (countValues == 0) {
log.trace("setting a empty attribute");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), oneAttr.getValues().toArray(new String[0]));
} else if (countValues == 1) {
log.trace("setting a single attribute");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), oneAttr.getValues().get(0));
} else if (countValues > 1) {
log.trace("setting a multivalued attribute");
List<String> listOfAttr = oneAttr.getValues();
String[] AttrArray = new String[listOfAttr.size()];
int i = 0;
for (String oneValue : listOfAttr) {
if (oneValue != null && oneValue.length() > 0) {
log.trace("setting a value");
AttrArray[i] = oneValue;
i++;
}
}
log.trace("setting the list of multivalued attributes");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), AttrArray);
}
}
}
*/
// log.trace("getting meta attributes");
/*
if (source.getMeta()!=null && source.getMeta().getAttributes() != null) {
log.trace("source.getCustomAttributes() != null");
log.trace("getting a list of ScimCustomAttributes");
Set<String> customAttr = source.getMeta().getAttributes();
log.trace("checling every attribute in the request");
for (String oneAttr : customAttr) {
if (oneAttr == null) {
continue;
}
destination.setAttribute(oneAttr.replaceAll(" ", ""), "");
*/
/* NOTE : WRITE CODE FOR THIS
int countValues = oneAttr.getValues().size();
if (countValues == 0) {
log.trace("setting a empty attribute");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), oneAttr.getValues().toArray(new String[0]));
} else if (countValues == 1) {
log.trace("setting a single attribute");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), oneAttr.getValues().get(0));
} else if (countValues > 1) {
log.trace("setting a multivalued attribute");
List<String> listOfAttr = oneAttr.getValues();
String[] AttrArray = new String[listOfAttr.size()];
int i = 0;
for (String oneValue : listOfAttr) {
if (oneValue != null && oneValue.length() > 0) {
log.trace("setting a value");
AttrArray[i] = oneValue;
i++;
}
}
log.trace("setting the list of multivalued attributes");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), AttrArray);
}
*/
/*
}
}
*/
} else {
try {
if (personService.getPersonByUid(source.getUserName()) != null) {
throw new DuplicateEntryException("Duplicate UID value: " + source.getUserName());
}
personService.addCustomObjectClass(destination);
log.trace(" setting userName ");
if (source.getUserName() != null && source.getUserName().length() > 0) {
destination.setUid(source.getUserName());
}
if (source.getName() != null) {
log.trace(" setting givenname ");
if (source.getName().getGivenName() != null && source.getName().getGivenName().length() > 0) {
destination.setGivenName(source.getName().getGivenName());
}
log.trace(" setting famillyname ");
if (source.getName().getFamilyName() != null && source.getName().getFamilyName().length() > 0) {
destination.setSurname(source.getName().getFamilyName());
}
log.trace(" setting middlename ");
if (source.getName().getMiddleName() != null && source.getName().getMiddleName().length() > 0) {
destination.setAttribute("middleName", source.getName().getMiddleName());
}
log.trace(" setting honor");
if (source.getName().getHonorificPrefix() != null && source.getName().getHonorificPrefix().length() > 0) {
destination.setAttribute("oxTrusthonorificPrefix", source.getName().getHonorificPrefix());
}
if (source.getName().getHonorificSuffix() != null && source.getName().getHonorificSuffix().length() > 0) {
destination.setAttribute("oxTrusthonorificSuffix", source.getName().getHonorificSuffix());
}
}
log.trace(" setting displayname ");
if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
destination.setDisplayName(source.getDisplayName());
}
log.trace(" setting externalID ");
if (source.getExternalId() != null && source.getExternalId().length() > 0) {
destination.setAttribute("oxTrustExternalId", source.getExternalId());
}
log.trace(" setting nickname ");
if (source.getNickName() != null && source.getNickName().length() > 0) {
destination.setAttribute("nickname", source.getNickName());
}
log.trace(" setting profileURL ");
if (source.getProfileUrl() != null && source.getProfileUrl().length() > 0) {
destination.setAttribute("oxTrustProfileURL", source.getProfileUrl());
}
// getting emails
log.trace(" setting emails ");
if (source.getEmails() != null && source.getEmails().size() > 0) {
/*
List<Email> emails = source.getEmails();
// StringWriter listOfEmails = new StringWriter();
// mapper.writeValue(listOfEmails, emails);
List<String> emailList = new ArrayList<String>();
for (Email email : emails) {
emailList.add(mapper.writeValueAsString(email));
}
// destination.setAttribute("oxTrustEmail", listOfEmails.toString());
destination.setAttribute("oxTrustEmail", emailList.toArray(new String[]{}));
*/
setAttributeListValue(destination, source.getEmails(), "oxTrustEmail");
}
// getting addresses
log.trace(" setting addresses ");
if (source.getAddresses() != null && source.getAddresses().size() > 0) {
setAttributeListValue(destination, source.getAddresses(), "oxTrustAddresses");
}
// getting phone numbers;
log.trace(" setting phoneNumbers ");
if (source.getPhoneNumbers() != null && source.getPhoneNumbers().size() > 0) {
setAttributeListValue(destination, source.getPhoneNumbers(), "oxTrustPhoneValue");
}
// getting ims
log.trace(" setting ims ");
if (source.getIms() != null && source.getIms().size() > 0) {
setAttributeListValue(destination, source.getIms(), "oxTrustImsValue");
}
// getting Photos
log.trace(" setting photos ");
if (source.getPhotos() != null && source.getPhotos().size() > 0) {
setAttributeListValue(destination, source.getPhotos(), "oxTrustPhotos");
}
if (source.getUserType() != null && source.getUserType().length() > 0) {
destination.setAttribute("oxTrustUserType", source.getUserType());
}
if (source.getTitle() != null && source.getTitle().length() > 0) {
destination.setAttribute("oxTrustTitle", source.getTitle());
}
if (source.getPreferredLanguage() != null && source.getPreferredLanguage().length() > 0) {
destination.setPreferredLanguage(source.getPreferredLanguage());
}
if (source.getLocale() != null && source.getLocale().length() > 0) {
// destination.setAttribute("oxTrustLocale", source.getLocale());
destination.setAttribute("locale", source.getLocale());
}
if (source.getTimezone() != null && source.getTimezone().length() > 0) {
destination.setTimezone(source.getTimezone());
}
if (source.isActive() != null) {
destination.setAttribute("oxTrustActive", source.isActive().toString());
}
if (source.getPassword() != null && source.getPassword().length() > 0) {
destination.setUserPassword(source.getPassword());
}
// getting user groups
log.trace(" setting groups ");
if (source.getGroups() != null && source.getGroups().size() > 0) {
List<GroupRef> listGroups = source.getGroups();
List<String> members = new ArrayList<String>();
for (GroupRef group : listGroups) {
members.add(groupService.getDnForGroup(group.getValue()));
}
destination.setMemberOf(members);
}
// getting roles
log.trace(" setting roles ");
if (source.getRoles() != null && source.getRoles().size() > 0) {
setAttributeListValue(destination, source.getRoles(), "oxTrustRole");
}
// getting entitlements
log.trace(" setting entitlements ");
if (source.getEntitlements() != null && source.getEntitlements().size() > 0) {
setAttributeListValue(destination, source.getEntitlements(), "oxTrustEntitlements");
}
// getting x509Certificates
log.trace(" setting certs ");
if (source.getX509Certificates() != null && source.getX509Certificates().size() > 0) {
setAttributeListValue(destination, source.getX509Certificates(), "oxTrustx509Certificate");
}
log.trace(" setting extensions ");
if (source.getExtensions() != null && (source.getExtensions().size() > 0)) {
destination.setExtensions(source.getExtensions());
}
/*
// getting customAttributes
log.trace("getting custom attributes");
if (source.getCustomAttributes() != null && source.getCustomAttributes().size() > 0) {
log.trace("source.getCustomAttributes() != null");
log.trace("getting a list of CustomAttributes");
List<CustomAttributes> customAttr = source.getCustomAttributes();
log.trace("checling every attribute in the request");
for (CustomAttributes oneAttr : customAttr) {
if (oneAttr != null && oneAttr.getValues().size() == 1) {
log.trace("setting a single attribute");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), oneAttr.getValues().get(0));
} else if (oneAttr != null && oneAttr.getValues().size() > 1) {
log.trace("setting a multivalued attribute");
List<String> listOfAttr = oneAttr.getValues();
String[] AttrArray = new String[listOfAttr.size()];
int i = 0;
for (String oneValue : listOfAttr) {
if (oneValue != null && oneValue.length() > 0) {
log.trace("setting a value");
AttrArray[i] = oneValue;
i++;
}
}
log.trace("setting the list of multivalued attributes");
destination.setAttribute(oneAttr.getName().replaceAll(" ", ""), AttrArray);
}
}
}
*/
} catch (DuplicateEntryException e) {
throw e;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
setGluuStatus(source, destination);
return destination;
}
use of org.gluu.oxtrust.model.scim2.Meta in project oxTrust by GluuFederation.
the class CopyUtils2 method copy.
public FidoDevice copy(GluuCustomFidoDevice source, FidoDevice destination) {
if (source == null) {
return null;
}
if (destination == null) {
destination = new FidoDevice();
}
destination.setId(source.getId());
destination.setCreationDate(source.getCreationDate());
destination.setApplication(source.getApplication());
destination.setCounter(source.getCounter());
destination.setDeviceData(source.getDeviceData());
destination.setDeviceHashCode(source.getDeviceHashCode());
destination.setDeviceKeyHandle(source.getDeviceKeyHandle());
destination.setDeviceRegistrationConf(source.getDeviceRegistrationConf());
destination.setLastAccessTime(source.getLastAccessTime());
destination.setStatus(source.getStatus());
destination.setDisplayName(source.getDisplayName());
destination.setDescription(source.getDescription());
if (source.getDn() != null) {
String[] dnArray = source.getDn().split("\\,");
for (String e : dnArray) {
if (e.startsWith("inum=")) {
String[] inumArray = e.split("\\=");
if (inumArray.length > 1) {
destination.setUserId(inumArray[1]);
}
}
}
}
Meta meta = (destination.getMeta() != null) ? destination.getMeta() : new Meta();
if (source.getMetaVersion() != null) {
meta.setVersion(source.getMetaVersion());
}
String location = source.getMetaLocation();
if (location != null && !location.isEmpty()) {
if (!location.startsWith("https://") && !location.startsWith("http://")) {
location = appConfiguration.getBaseEndpoint() + location;
}
} else {
location = appConfiguration.getBaseEndpoint() + "/scim/v2/FidoDevices/" + source.getId();
}
meta.setLocation(location);
if (source.getCreationDate() != null && !source.getCreationDate().isEmpty()) {
try {
meta.setCreated(new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'").parse(source.getCreationDate()));
} catch (Exception e) {
log.error(" Date parse exception (OLD format)", e);
}
}
if (source.getMetaLastModified() != null && !source.getMetaLastModified().isEmpty()) {
try {
DateTime dateTimeUtc = new DateTime(source.getMetaLastModified(), DateTimeZone.UTC);
meta.setLastModified(dateTimeUtc.toDate());
} catch (Exception e) {
log.error(" Date parse exception (NEW format), continuing...", e);
try {
meta.setLastModified(new SimpleDateFormat("yyyyMMddHHmmss.SSS'Z'").parse(source.getMetaLastModified()));
} catch (Exception ex) {
log.error(" Date parse exception (OLD format)", ex);
}
}
}
destination.setMeta(meta);
return destination;
}
use of org.gluu.oxtrust.model.scim2.Meta in project oxTrust by GluuFederation.
the class GroupCoreLoadingStrategy 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);
// Use serializer to walk the class structure
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule groupCoreLoadingStrategyModule = new SimpleModule("GroupCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
SchemaTypeGroupSerializer serializer = new SchemaTypeGroupSerializer();
serializer.setSchemaType(schemaType);
groupCoreLoadingStrategyModule.addSerializer(Group.class, serializer);
mapper.registerModule(groupCoreLoadingStrategyModule);
mapper.writeValueAsString(createDummyGroup());
return serializer.getSchemaType();
}
use of org.gluu.oxtrust.model.scim2.Meta in project oxTrust by GluuFederation.
the class UserCoreLoadingStrategy 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);
// Use serializer to walk the class structure
ObjectMapper mapper = new ObjectMapper();
mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
SimpleModule userCoreLoadingStrategyModule = new SimpleModule("UserCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
SchemaTypeUserSerializer serializer = new SchemaTypeUserSerializer();
serializer.setSchemaType(schemaType);
userCoreLoadingStrategyModule.addSerializer(User.class, serializer);
mapper.registerModule(userCoreLoadingStrategyModule);
mapper.writeValueAsString(createDummyUser());
return serializer.getSchemaType();
}
use of org.gluu.oxtrust.model.scim2.Meta 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;
}
Aggregations