Search in sources :

Example 6 with Email

use of org.gluu.oxtrust.model.scim2.user.Email in project oxTrust by GluuFederation.

the class ServiceUtil method syncEmailReverse.

/**
 * One-way sync from "mail" to "oxTrustEmail". This method takes current values of "oxTrustEmail" attribute, deletes
 * those that do not match any of those in "mail", and adds new ones that are missing.
 * @param gluuCustomPerson
 * @param isScim2
 * @return
 * @throws Exception
 */
public static GluuCustomPerson syncEmailReverse(GluuCustomPerson gluuCustomPerson, boolean isScim2) throws Exception {
    /*
        Implementation of this method could not be simplified to creating a new empty list for oxTrustEmail and then do
        the respective additions based on current mail values since information such as display, primary, etc. would be lost.
        Instead, it uses set operations to know which existing entries must be removed or retained, and then apply additions
        of new data.
         */
    logger.info(" IN Utils.syncEmailReverse()...");
    GluuCustomAttribute mail = gluuCustomPerson.getGluuCustomAttribute("mail");
    GluuCustomAttribute oxTrustEmail = gluuCustomPerson.getGluuCustomAttribute("oxTrustEmail");
    if (mail == null) {
        gluuCustomPerson.setAttribute("oxTrustEmail", new String[0]);
    } else {
        ObjectMapper mapper = getObjectMapper();
        Set<String> mailSet = new HashSet<String>();
        if (mail.getValues() != null)
            mailSet.addAll(Arrays.asList(mail.getValues()));
        Set<String> mailSetCopy = new HashSet<String>(mailSet);
        Set<String> oxTrustEmailSet = new HashSet<String>();
        List<Email> oxTrustEmails = new ArrayList<Email>();
        if (oxTrustEmail != null && oxTrustEmail.getValues() != null) {
            for (String oxTrustEmailJson : oxTrustEmail.getValues()) oxTrustEmails.add(mapper.readValue(oxTrustEmailJson, Email.class));
            for (Email email : oxTrustEmails) oxTrustEmailSet.add(email.getValue());
        }
        // Keep those in "mail" and not in oxTrustEmail
        mailSetCopy.removeAll(oxTrustEmailSet);
        // Keep those in oxTrustEmail and not in "mail"
        oxTrustEmailSet.removeAll(mailSet);
        List<Integer> delIndexes = new ArrayList<Integer>();
        // Build a list of indexes that should be removed in oxTrustEmails
        for (int i = 0; i < oxTrustEmails.size(); i++) {
            if (oxTrustEmailSet.contains(oxTrustEmails.get(i).getValue()))
                delIndexes.add(0, i);
        }
        // Delete unmatched oxTrustEmail entries from highest index to lowest
        for (Integer idx : delIndexes) // must not pass an Integer directly
        oxTrustEmails.remove(idx.intValue());
        List<String> newValues = new ArrayList<String>();
        for (Email email : oxTrustEmails) newValues.add(mapper.writeValueAsString(email));
        for (String mailStr : mailSetCopy) {
            Email email = new Email();
            email.setValue(mailStr);
            email.setPrimary(false);
            newValues.add(mapper.writeValueAsString(email));
        }
        gluuCustomPerson.setAttribute("oxTrustEmail", newValues.toArray(new String[0]));
    }
    logger.info(" LEAVING Utils.syncEmailReverse()...");
    return gluuCustomPerson;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) Email(org.gluu.oxtrust.model.scim2.user.Email) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 7 with Email

use of org.gluu.oxtrust.model.scim2.user.Email 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;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) GroupRef(org.gluu.oxtrust.model.scim2.GroupRef) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException)

Example 8 with Email

use of org.gluu.oxtrust.model.scim2.user.Email in project oxTrust by GluuFederation.

the class UserCoreLoadingStrategy method createDummyUser.

private User createDummyUser() {
    User user = new User();
    org.gluu.oxtrust.model.scim2.Name name = new org.gluu.oxtrust.model.scim2.Name();
    name.setGivenName("");
    name.setMiddleName("");
    name.setFamilyName("");
    name.setHonorificPrefix("");
    name.setHonorificSuffix("");
    user.setName(name);
    user.setActive(false);
    user.setId("");
    user.setExternalId("");
    user.setUserName("");
    user.setPassword("");
    user.setDisplayName("");
    user.setNickName("");
    user.setProfileUrl("");
    user.setLocale("");
    user.setPreferredLanguage("");
    user.setTimezone("");
    user.setTitle("");
    List<GroupRef> groups = new ArrayList<GroupRef>();
    GroupRef groupRef = new GroupRef();
    groupRef.setOperation("");
    groupRef.setPrimary(false);
    groupRef.setValue("test");
    groupRef.setDisplay("");
    groupRef.setType(GroupRef.Type.DIRECT);
    groupRef.setReference("");
    groups.add(groupRef);
    user.setGroups(groups);
    List<Email> emails = new ArrayList<Email>();
    Email email = new Email();
    email.setOperation("");
    email.setPrimary(false);
    email.setValue("a@b.com");
    email.setDisplay("");
    email.setType(Email.Type.WORK);
    email.setReference("");
    emails.add(email);
    user.setEmails(emails);
    List<PhoneNumber> phoneNumbers = new ArrayList<PhoneNumber>();
    PhoneNumber phoneNumber = new PhoneNumber();
    phoneNumber.setOperation("");
    phoneNumber.setPrimary(false);
    phoneNumber.setValue("123-456-7890");
    phoneNumber.setDisplay("");
    phoneNumber.setType(PhoneNumber.Type.WORK);
    phoneNumber.setReference("");
    phoneNumbers.add(phoneNumber);
    user.setPhoneNumbers(phoneNumbers);
    List<Im> ims = new ArrayList<Im>();
    Im im = new Im();
    im.setOperation("");
    im.setPrimary(false);
    im.setValue("test");
    im.setDisplay("");
    im.setType(Im.Type.SKYPE);
    im.setReference("");
    ims.add(im);
    user.setIms(ims);
    List<Photo> photos = new ArrayList<Photo>();
    Photo photo = new Photo();
    photo.setOperation("");
    photo.setPrimary(false);
    photo.setValue("data:image/jpg;charset=utf-8;base64,dGVzdA==");
    photo.setDisplay("");
    photo.setType(Photo.Type.PHOTO);
    photo.setReference("");
    photos.add(photo);
    user.setPhotos(photos);
    List<Address> addresses = new ArrayList<Address>();
    Address address = new Address();
    address.setOperation("");
    address.setPrimary(false);
    address.setValue("test");
    address.setDisplay("");
    address.setType(Address.Type.WORK);
    address.setReference("");
    address.setStreetAddress("");
    address.setLocality("");
    address.setPostalCode("");
    address.setRegion("");
    address.setCountry("");
    address.setFormatted("");
    addresses.add(address);
    user.setAddresses(addresses);
    List<Entitlement> entitlements = new ArrayList<Entitlement>();
    Entitlement entitlement = new Entitlement();
    entitlement.setOperation("");
    entitlement.setPrimary(false);
    entitlement.setValue("test");
    entitlement.setDisplay("");
    entitlement.setType(new Entitlement.Type("test"));
    entitlement.setReference("");
    entitlements.add(entitlement);
    user.setEntitlements(entitlements);
    List<Role> roles = new ArrayList<Role>();
    Role role = new Role();
    role.setOperation("");
    role.setPrimary(false);
    role.setValue("test");
    role.setDisplay("");
    role.setType(new Role.Type("test"));
    role.setReference("");
    roles.add(role);
    user.setRoles(roles);
    List<X509Certificate> x509Certificates = new ArrayList<X509Certificate>();
    X509Certificate x509Certificate = new X509Certificate();
    x509Certificate.setOperation("");
    x509Certificate.setPrimary(false);
    x509Certificate.setValue("test");
    x509Certificate.setDisplay("");
    x509Certificate.setType(new X509Certificate.Type("test"));
    x509Certificate.setReference("");
    x509Certificates.add(x509Certificate);
    user.setX509Certificates(x509Certificates);
    return user;
}
Also used : User(org.gluu.oxtrust.model.scim2.User) Email(org.gluu.oxtrust.model.scim2.Email) Im(org.gluu.oxtrust.model.scim2.Im) Address(org.gluu.oxtrust.model.scim2.Address) ArrayList(java.util.ArrayList) Photo(org.gluu.oxtrust.model.scim2.Photo) X509Certificate(org.gluu.oxtrust.model.scim2.X509Certificate) Role(org.gluu.oxtrust.model.scim2.Role) PhoneNumber(org.gluu.oxtrust.model.scim2.PhoneNumber) GroupRef(org.gluu.oxtrust.model.scim2.GroupRef) Entitlement(org.gluu.oxtrust.model.scim2.Entitlement)

Example 9 with Email

use of org.gluu.oxtrust.model.scim2.user.Email in project oxTrust by GluuFederation.

the class PatchUtil method replacePatch.

public GluuCustomPerson replacePatch(User source, GluuCustomPerson destination) throws Exception {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        log.trace(" creating a new GluuCustomPerson instant ");
        destination = new GluuCustomPerson();
    }
    log.trace(" setting schemas ");
    destination.setSchemas(source.getSchemas());
    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 = copyUtils2.getAttributeListValue(destination, Email.class, "oxTrustEmail");
        if (emails != null) {
            List<Email> newemails = source.getEmails();
            for (Email email : emails) {
                if (email != null && email.getType() != null) {
                    for (Email newEmail : newemails) {
                        if ((newEmail.getType() != null) && newEmail.getType().getValue().equals(email.getType().getValue())) {
                            emails.remove(email);
                            emails.add(newEmail);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, emails, "oxTrustEmail");
        }
    }
    // getting addresses
    log.trace(" setting addresses ");
    if (source.getAddresses() != null && source.getAddresses().size() > 0) {
        List<Address> addresses = copyUtils2.getAttributeListValue(destination, Address.class, "oxTrustAddresses");
        if (addresses != null) {
            List<Address> newaddresses = source.getAddresses();
            for (Address address : addresses) {
                if (address != null && address.getType() != null) {
                    for (Address newAddress : newaddresses) {
                        if ((newAddress.getType() != null) && newAddress.getType().getValue().equals(address.getType().getValue())) {
                            addresses.remove(address);
                            addresses.add(newAddress);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, addresses, "oxTrustAddresses");
        }
    }
    // getting phone numbers;
    log.trace(" setting phoneNumbers ");
    if (source.getPhoneNumbers() != null && source.getPhoneNumbers().size() > 0) {
        List<PhoneNumber> phoneNumbers = copyUtils2.getAttributeListValue(destination, PhoneNumber.class, "oxTrustPhoneValue");
        if (phoneNumbers != null) {
            List<PhoneNumber> newPhoneNumbers = source.getPhoneNumbers();
            for (PhoneNumber phoneNumber : phoneNumbers) {
                if (phoneNumber != null && phoneNumber.getType() != null) {
                    for (PhoneNumber newPhoneNumber : newPhoneNumbers) {
                        if ((newPhoneNumber.getType() != null) && (phoneNumber.getType().getValue() != null) && newPhoneNumber.getType().getValue().equals(phoneNumber.getType().getValue())) {
                            phoneNumbers.remove(phoneNumber);
                            phoneNumbers.add(newPhoneNumber);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, phoneNumbers, "oxTrustPhoneValue");
        }
    }
    // getting ims
    log.trace(" setting ims ");
    if (source.getIms() != null && source.getIms().size() > 0) {
        List<Im> ims = copyUtils2.getAttributeListValue(destination, Im.class, "oxTrustImsValue");
        if (ims != null && ims.size() > 0) {
            List<Im> newims = source.getIms();
            for (Im im : ims) {
                if (im != null && im.getType() != null) {
                    for (Im newIm : newims) {
                        if (newIm.getType() != null && newIm.getType().getValue().equals(im.getType().getValue())) {
                            ims.remove(im);
                            ims.add(newIm);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, ims, "oxTrustImsValue");
        }
    }
    // getting Photos
    log.trace(" setting photos ");
    if (source.getPhotos() != null && source.getPhotos().size() > 0) {
        List<Photo> photos = copyUtils2.getAttributeListValue(destination, Photo.class, "oxTrustPhotos");
        if (photos != null && photos.size() > 0) {
            List<Photo> newPhotos = source.getPhotos();
            for (Photo photo : photos) {
                if (photo != null && photo.getType() != null) {
                    for (Photo newPhoto : newPhotos) {
                        if (newPhoto.getType() != null && newPhoto.getType().getValue().equals(photo.getType().getValue())) {
                            photos.remove(photo);
                            photos.add(newPhoto);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, photos, "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) {
        List<Role> roles = copyUtils2.getAttributeListValue(destination, Role.class, "oxTrustRole");
        if (roles != null && roles.size() > 0) {
            List<Role> newRoles = source.getRoles();
            for (Role role : roles) {
                if (role != null && role.getType() != null) {
                    for (Role newRole : newRoles) {
                        if ((newRole.getType() != null) && newRole.getType().getValue().equals(role.getType().getValue())) {
                            roles.remove(role);
                            roles.add(newRole);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, roles, "oxTrustRole");
        }
    }
    // getting entitlements
    log.trace(" setting entitlements ");
    if (source.getEntitlements() != null && source.getEntitlements().size() > 0) {
        List<Entitlement> entitlements = copyUtils2.getAttributeListValue(destination, Entitlement.class, "oxTrustEntitlements");
        if (entitlements != null && entitlements.size() > 0) {
            List<Entitlement> newEentitlements = source.getEntitlements();
            for (Entitlement entitlement : entitlements) {
                if (entitlement != null && entitlement.getType() != null) {
                    for (Entitlement newEntitlement : newEentitlements) {
                        if ((newEntitlement.getType() != null) && newEntitlement.getType().getValue().equals(entitlement.getType().getValue())) {
                            entitlements.remove(entitlement);
                            entitlements.add(newEntitlement);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, entitlements, "oxTrustEntitlements");
        }
    }
    // getting x509Certificates
    log.trace(" setting certs ");
    if (source.getX509Certificates() != null && source.getX509Certificates().size() > 0) {
        List<X509Certificate> X509Certificates = copyUtils2.getAttributeListValue(destination, X509Certificate.class, "oxTrustx509Certificate");
        if (X509Certificates != null) {
            List<X509Certificate> newX509Certificates = source.getX509Certificates();
            for (X509Certificate X509Certificate : X509Certificates) {
                if (X509Certificate != null && X509Certificate.getType() != null) {
                    for (X509Certificate newX509Certificate : newX509Certificates) {
                        if ((newX509Certificate.getType() != null) && newX509Certificate.getType().getValue().equals(X509Certificate.getType().getValue())) {
                            X509Certificates.remove(X509Certificate);
                            X509Certificates.add(newX509Certificate);
                        }
                    }
                }
            }
            copyUtils2.setAttributeListValue(destination, X509Certificates, "oxTrustx509Certificate");
        }
    }
    log.trace(" setting extensions ");
    if (source.getExtensions() != null && (source.getExtensions().size() > 0)) {
        destination.setExtensions(source.getExtensions());
    }
    if (source.isActive() != null) {
        copyUtils2.setGluuStatus(source, destination);
    }
    return destination;
}
Also used : Email(org.gluu.oxtrust.model.scim2.Email) Address(org.gluu.oxtrust.model.scim2.Address) Im(org.gluu.oxtrust.model.scim2.Im) ArrayList(java.util.ArrayList) Photo(org.gluu.oxtrust.model.scim2.Photo) X509Certificate(org.gluu.oxtrust.model.scim2.X509Certificate) Role(org.gluu.oxtrust.model.scim2.Role) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) PhoneNumber(org.gluu.oxtrust.model.scim2.PhoneNumber) GroupRef(org.gluu.oxtrust.model.scim2.GroupRef) Entitlement(org.gluu.oxtrust.model.scim2.Entitlement)

Example 10 with Email

use of org.gluu.oxtrust.model.scim2.user.Email in project oxTrust by GluuFederation.

the class Scim2UserService method createUser.

public User createUser(User user) throws Exception {
    log.debug(" copying gluuperson ");
    GluuCustomPerson gluuPerson = copyUtils2.copy(user, null, false);
    if (gluuPerson == null) {
        throw new Exception("Scim2UserService.createUser(): Failed to create user; GluuCustomPerson is null");
    }
    log.debug(" generating inum ");
    // inumService.generateInums(Configuration.INUM_TYPE_PEOPLE_SLUG);
    String inum = personService.generateInumForNewPerson();
    // //personService.generateInumForNewPerson();
    log.debug(" getting DN ");
    String dn = personService.getDnForPerson(inum);
    log.debug(" getting iname ");
    String iname = personService.generateInameForNewPerson(user.getUserName());
    log.debug(" setting dn ");
    gluuPerson.setDn(dn);
    log.debug(" setting inum ");
    gluuPerson.setInum(inum);
    log.debug(" setting iname ");
    gluuPerson.setIname(iname);
    log.debug(" setting commonName ");
    gluuPerson.setCommonName(gluuPerson.getGivenName() + " " + gluuPerson.getSurname());
    log.info("gluuPerson.getMemberOf().size() : " + gluuPerson.getMemberOf().size());
    if (user.getGroups().size() > 0) {
        log.info(" jumping to groupMembersAdder ");
        log.info("gluuPerson.getDn() : " + gluuPerson.getDn());
        serviceUtil.groupMembersAdder(gluuPerson, gluuPerson.getDn());
    }
    // As per spec, the SP must be the one to assign the meta attributes
    log.info(" Setting meta: create user ");
    // Date should be in UTC format
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
    Date dateCreated = DateTime.now().toDate();
    String relativeLocation = "/scim/v2/Users/" + inum;
    gluuPerson.setAttribute("oxTrustMetaCreated", dateTimeFormatter.print(dateCreated.getTime()));
    gluuPerson.setAttribute("oxTrustMetaLastModified", dateTimeFormatter.print(dateCreated.getTime()));
    gluuPerson.setAttribute("oxTrustMetaLocation", relativeLocation);
    // Sync email, forward ("oxTrustEmail" -> "mail")
    gluuPerson = serviceUtil.syncEmailForward(gluuPerson, true);
    // For custom script: create user
    if (externalScimService.isEnabled()) {
        externalScimService.executeScimCreateUserMethods(gluuPerson);
    }
    log.debug("adding new GluuPerson");
    personService.addPerson(gluuPerson);
    User createdUser = copyUtils2.copy(gluuPerson, null);
    return createdUser;
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) User(org.gluu.oxtrust.model.scim2.User) ScimPatchUser(org.gluu.oxtrust.model.scim2.ScimPatchUser) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) Date(java.util.Date)

Aggregations

GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)6 Email (org.gluu.oxtrust.model.scim2.Email)6 PhoneNumber (org.gluu.oxtrust.model.scim2.PhoneNumber)6 Address (org.gluu.oxtrust.model.scim2.Address)5 Entitlement (org.gluu.oxtrust.model.scim2.Entitlement)5 GroupRef (org.gluu.oxtrust.model.scim2.GroupRef)5 Im (org.gluu.oxtrust.model.scim2.Im)5 Photo (org.gluu.oxtrust.model.scim2.Photo)5 Role (org.gluu.oxtrust.model.scim2.Role)5 User (org.gluu.oxtrust.model.scim2.User)5 X509Certificate (org.gluu.oxtrust.model.scim2.X509Certificate)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)4 Extension (org.gluu.oxtrust.model.scim2.Extension)3 IOException (java.io.IOException)2 BigDecimal (java.math.BigDecimal)2 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)2 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)2 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)2