Search in sources :

Example 26 with Group

use of org.gluu.oxtrust.model.scim2.Group in project ORCID-Source by ORCID.

the class Api2_0_rc4_LastModifiedDatesHelper method calculateLastModified.

public static void calculateLastModified(GroupsContainer groupsContainerRc4) {
    if (groupsContainerRc4.retrieveGroups() != null && !groupsContainerRc4.retrieveGroups().isEmpty()) {
        List<? extends Group> groupsRc1 = new ArrayList<>(groupsContainerRc4.retrieveGroups());
        List<org.orcid.jaxb.model.record_rc4.Group> groupsRc4 = new ArrayList<>(groupsContainerRc4.retrieveGroups());
        if (groupsRc1.get(0).getActivities() != null && !groupsRc1.get(0).getActivities().isEmpty()) {
            LastModifiedDate latest = null;
            for (Group group : groupsRc4) {
                calculateLastModified(group);
                if (group.getLastModifiedDate() != null && group.getLastModifiedDate().after(latest)) {
                    latest = group.getLastModifiedDate();
                }
            }
            groupsContainerRc4.setLastModifiedDate(latest);
        }
    }
}
Also used : Group(org.orcid.jaxb.model.record_rc4.Group) LastModifiedDate(org.orcid.jaxb.model.common_rc4.LastModifiedDate) ArrayList(java.util.ArrayList)

Example 27 with Group

use of org.gluu.oxtrust.model.scim2.Group 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 28 with Group

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

the class SchemaTypeGroupSerializer method serialize.

@Override
public void serialize(Group group, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    log.info(" serialize() ");
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
        JsonNode rootNode = mapper.convertValue(group, JsonNode.class);
        Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.getFields();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonNode> rootNodeEntry = iterator.next();
            if (rootNodeEntry.getValue() instanceof ObjectNode) {
            // Definitely maybe in the near future
            } else if (rootNodeEntry.getValue() instanceof ArrayNode) {
                AttributeHolder arrayNodeAttributeHolder = new AttributeHolder();
                arrayNodeAttributeHolder.setName(rootNodeEntry.getKey());
                if (rootNodeEntry.getKey().equalsIgnoreCase("members")) {
                    arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list; using sub-attributes in a query filter is not supported (cross-querying)");
                    arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
                    List<String> referenceTypes = new ArrayList<String>();
                    referenceTypes.add("User");
                    arrayNodeAttributeHolder.setReferenceTypes(referenceTypes);
                } else {
                    arrayNodeAttributeHolder.setDescription(rootNodeEntry.getKey() + " list");
                    arrayNodeAttributeHolder.setCaseExact(Boolean.FALSE);
                }
                arrayNodeAttributeHolder.setRequired(Boolean.FALSE);
                arrayNodeAttributeHolder.setMultiValued(Boolean.TRUE);
                if (rootNodeEntry.getKey().equalsIgnoreCase("schemas")) {
                    arrayNodeAttributeHolder.setUniqueness("server");
                    arrayNodeAttributeHolder.setType("string");
                    arrayNodeAttributeHolder.setCaseExact(Boolean.TRUE);
                    arrayNodeAttributeHolder.setMutability("readOnly");
                    arrayNodeAttributeHolder.setReturned("always");
                } else {
                    arrayNodeAttributeHolder.setType("complex");
                }
                List<AttributeHolder> arrayNodeMapAttributeHolders = new ArrayList<AttributeHolder>();
                Iterator<JsonNode> arrayNodeIterator = rootNodeEntry.getValue().getElements();
                while (arrayNodeIterator.hasNext()) {
                    JsonNode jsonNode = arrayNodeIterator.next();
                    Iterator<Map.Entry<String, JsonNode>> arrayNodeMapIterator = jsonNode.getFields();
                    while (arrayNodeMapIterator.hasNext()) {
                        Map.Entry<String, JsonNode> arrayNodeMapRootNodeEntry = arrayNodeMapIterator.next();
                        AttributeHolder arrayNodeMapAttributeHolder = new AttributeHolder();
                        if (rootNodeEntry.getKey().equalsIgnoreCase("members") && arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("reference")) {
                            arrayNodeMapAttributeHolder.setName("$ref");
                        } else {
                            arrayNodeMapAttributeHolder.setName(arrayNodeMapRootNodeEntry.getKey());
                        }
                        arrayNodeMapAttributeHolder.setType("string");
                        arrayNodeMapAttributeHolder.setDescription(arrayNodeMapRootNodeEntry.getKey());
                        if (arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("value") || arrayNodeMapRootNodeEntry.getKey().equalsIgnoreCase("type")) {
                            arrayNodeMapAttributeHolder.setRequired(Boolean.TRUE);
                        } else {
                            arrayNodeMapAttributeHolder.setRequired(Boolean.FALSE);
                        }
                        arrayNodeMapAttributeHolders.add(arrayNodeMapAttributeHolder);
                    }
                    arrayNodeAttributeHolder.setSubAttributes(arrayNodeMapAttributeHolders);
                    attributeHolders.add(arrayNodeAttributeHolder);
                }
            } else {
                if (!rootNodeEntry.getKey().equalsIgnoreCase("externalId")) {
                    AttributeHolder attributeHolder = new AttributeHolder();
                    attributeHolder.setName(rootNodeEntry.getKey());
                    if (rootNodeEntry.getValue().isBoolean()) {
                        attributeHolder.setType("boolean");
                    } else {
                        attributeHolder.setType("string");
                    }
                    attributeHolder.setDescription(rootNodeEntry.getKey());
                    attributeHolder.setRequired(Boolean.FALSE);
                    if (rootNodeEntry.getKey().equalsIgnoreCase("id")) {
                        attributeHolder.setUniqueness("server");
                        attributeHolder.setCaseExact(Boolean.TRUE);
                        attributeHolder.setMutability("readOnly");
                        attributeHolder.setReturned("always");
                    }
                    if (rootNodeEntry.getKey().equalsIgnoreCase("displayName")) {
                        attributeHolder.setReturned("always");
                    }
                    attributeHolders.add(attributeHolder);
                }
            }
        }
        GroupCoreSchema groupCoreSchema = (GroupCoreSchema) schemaType;
        groupCoreSchema.setAttributeHolders(attributeHolders);
        schemaType = groupCoreSchema;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException("Unexpected processing error; please check the Group class structure.");
    }
}
Also used : AttributeHolder(org.gluu.oxtrust.model.scim2.schema.AttributeHolder) ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) GroupCoreSchema(org.gluu.oxtrust.model.scim2.schema.core.GroupCoreSchema) IOException(java.io.IOException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ArrayNode(org.codehaus.jackson.node.ArrayNode) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 29 with Group

use of org.gluu.oxtrust.model.scim2.Group 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 30 with Group

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

the class BulkWebService method processBulkOperations.

@POST
@Consumes({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8", MediaType.APPLICATION_JSON + "; charset=utf-8" })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Bulk Operations", notes = "Bulk Operations (https://tools.ietf.org/html/rfc7644#section-3.7)", response = BulkResponse.class)
public Response processBulkOperations(// @Context HttpServletResponse response,
@HeaderParam("Authorization") String authorization, @HeaderParam("Content-Length") int contentLength, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @ApiParam(value = "BulkRequest", required = true) BulkRequest bulkRequest) throws Exception {
    Response authorizationResponse;
    if (jsonConfigurationService.getOxTrustappConfiguration().isScimTestMode()) {
        log.info(" ##### SCIM Test Mode is ACTIVE");
        authorizationResponse = processTestModeAuthorization(token);
    } else {
        authorizationResponse = processAuthorization(authorization);
    }
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        /*
			 * J2EContext context = new J2EContext(request, response); int
			 * removePathLength = "/Bulk".length(); String domain =
			 * context.getFullRequestURL(); if (domain.endsWith("/")) {
			 * removePathLength++; } domain = domain.substring(0,
			 * domain.length() - removePathLength);
			 */
        log.info("##### Operation count = " + bulkRequest.getOperations().size());
        log.info("##### Content-Length = " + contentLength);
        if (bulkRequest.getOperations().size() > MAX_BULK_OPERATIONS || contentLength > MAX_BULK_PAYLOAD_SIZE) {
            StringBuilder message = new StringBuilder("The size of the bulk operation exceeds the ");
            if (bulkRequest.getOperations().size() > MAX_BULK_OPERATIONS && contentLength <= MAX_BULK_PAYLOAD_SIZE) {
                message.append("maxOperations (").append(MAX_BULK_OPERATIONS).append(")");
            } else if (bulkRequest.getOperations().size() <= MAX_BULK_OPERATIONS && contentLength > MAX_BULK_PAYLOAD_SIZE) {
                message.append("maxPayloadSize (").append(MAX_BULK_PAYLOAD_SIZE).append(")");
            } else if (bulkRequest.getOperations().size() > MAX_BULK_OPERATIONS && contentLength > MAX_BULK_PAYLOAD_SIZE) {
                message.append("maxOperations (").append(MAX_BULK_OPERATIONS).append(") ");
                message.append("and ");
                message.append("maxPayloadSize (").append(MAX_BULK_PAYLOAD_SIZE).append(")");
            }
            log.info("Payload Too Large: " + message.toString());
            return getErrorResponse(413, message.toString());
        }
        int failOnErrorsLimit = (bulkRequest.getFailOnErrors() != null) ? bulkRequest.getFailOnErrors() : 0;
        int failOnErrorsCount = 0;
        List<BulkOperation> bulkOperations = bulkRequest.getOperations();
        BulkResponse bulkResponse = new BulkResponse();
        Map<String, String> processedBulkIds = new LinkedHashMap<String, String>();
        operationsLoop: for (BulkOperation operation : bulkOperations) {
            log.info(" Checking operations... ");
            if (operation.getPath().startsWith("/Users")) {
                // operation = processUserOperation(operation, domain);
                operation = processUserOperation(operation, processedBulkIds);
            } else if (operation.getPath().startsWith("/Groups")) {
                // operation = processGroupOperation(operation, domain);
                operation = processGroupOperation(operation, processedBulkIds);
            }
            bulkResponse.getOperations().add(operation);
            // Error handling
            String okCode = String.valueOf(Response.Status.OK.getStatusCode());
            String createdCode = String.valueOf(Response.Status.CREATED.getStatusCode());
            if (!operation.getStatus().equalsIgnoreCase(okCode) && !operation.getStatus().equalsIgnoreCase(createdCode)) {
                failOnErrorsCount++;
                if ((failOnErrorsLimit > 0) && (failOnErrorsCount >= failOnErrorsLimit)) {
                    break operationsLoop;
                }
            }
        }
        URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Bulk");
        // Serialize to JSON
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
        SimpleModule customBulkOperationsModule = new SimpleModule("CustomBulkOperationsModule", new Version(1, 0, 0, ""));
        // Custom serializers for both User and Group
        ListResponseUserSerializer userSerializer = new ListResponseUserSerializer();
        ListResponseGroupSerializer groupSerializer = new ListResponseGroupSerializer();
        customBulkOperationsModule.addSerializer(User.class, userSerializer);
        customBulkOperationsModule.addSerializer(Group.class, groupSerializer);
        mapper.registerModule(customBulkOperationsModule);
        String json = mapper.writeValueAsString(bulkResponse);
        return Response.ok(json).location(location).build();
    } catch (Exception ex) {
        log.error("Error in processBulkOperations", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : ListResponseUserSerializer(org.gluu.oxtrust.service.antlr.scimFilter.util.ListResponseUserSerializer) BulkOperation(org.gluu.oxtrust.model.scim2.BulkOperation) BulkResponse(org.gluu.oxtrust.model.scim2.BulkResponse) URI(java.net.URI) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) LinkedHashMap(java.util.LinkedHashMap) Response(javax.ws.rs.core.Response) BulkResponse(org.gluu.oxtrust.model.scim2.BulkResponse) ErrorResponse(org.gluu.oxtrust.model.scim2.ErrorResponse) Version(org.codehaus.jackson.Version) ListResponseGroupSerializer(org.gluu.oxtrust.service.antlr.scimFilter.util.ListResponseGroupSerializer) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Aggregations

ArrayList (java.util.ArrayList)12 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)12 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)10 DefaultValue (javax.ws.rs.DefaultValue)9 HeaderParam (javax.ws.rs.HeaderParam)9 Produces (javax.ws.rs.Produces)9 GluuGroup (org.gluu.oxtrust.model.GluuGroup)9 Group (org.gluu.oxtrust.model.scim2.Group)9 URI (java.net.URI)8 Group (org.openstack4j.model.identity.v3.Group)8 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)7 Response (javax.ws.rs.core.Response)7 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)7 Group (com.google.monitoring.v3.Group)5 Path (javax.ws.rs.Path)5 Test (org.junit.Test)5 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)5 IOException (java.io.IOException)4 Map (java.util.Map)4 GET (javax.ws.rs.GET)4