Search in sources :

Example 1 with GluuGroup

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

the class CopyUtils2 method copy.

/**
	 * Copy data from GluuCustomPerson object to ScimPerson object "Reda"
	 * 
	 * @param source
	 * @param destination
	 * @return
	 * @throws Exception
	 */
public User copy(GluuCustomPerson source, User destination) throws Exception {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        log.trace(" creating a new GluuCustomPerson instant ");
        destination = new User();
    }
    log.trace(" setting ID ");
    if (source.getInum() != null) {
        destination.setId(source.getInum());
    }
    log.trace(" setting userName ");
    if (source.getUid() != null) {
        destination.setUserName(source.getUid());
    }
    log.trace(" setting ExternalID ");
    if (source.getAttribute("oxTrustExternalId") != null) {
        destination.setExternalId(source.getAttribute("oxTrustExternalId"));
    }
    log.trace(" setting givenname ");
    if (source.getGivenName() != null) {
        org.gluu.oxtrust.model.scim2.Name name = new org.gluu.oxtrust.model.scim2.Name();
        name.setGivenName(source.getGivenName());
        if (source.getSurname() != null)
            name.setFamilyName(source.getSurname());
        if (source.getAttribute("middleName") != null)
            name.setMiddleName(source.getAttribute("middleName"));
        /*
			if (source.getAttribute("oxTrustMiddleName") != null)
				name.setMiddleName(source.getAttribute("oxTrustMiddleName"));
			*/
        if (source.getAttribute("oxTrusthonorificPrefix") != null)
            name.setHonorificPrefix(source.getAttribute("oxTrusthonorificPrefix"));
        if (source.getAttribute("oxTrusthonorificSuffix") != null)
            name.setHonorificSuffix(source.getAttribute("oxTrusthonorificSuffix"));
        name.setFormatted(name.getFormatted());
        destination.setName(name);
    }
    log.trace(" getting displayname ");
    if (source.getDisplayName() != null) {
        destination.setDisplayName(source.getDisplayName());
    }
    log.trace(" getting nickname ");
    /*
		if (source.getAttribute("oxTrustNickName") != null) {
			destination.setNickName(source.getAttribute("oxTrustNickName"));
		}
		*/
    if (source.getAttribute("nickname") != null) {
        destination.setNickName(source.getAttribute("nickname"));
    }
    log.trace(" getting profileURL ");
    if (source.getAttribute("oxTrustProfileURL") != null) {
        destination.setProfileUrl(source.getAttribute("oxTrustProfileURL"));
    }
    log.trace(" getting emails ");
    // source = Utils.syncEmailReverse(source, true);
    if (source.getAttributeArray("oxTrustEmail") != null) {
        /*
			String[] emailArray = source.getAttributeArray("oxTrustEmail");
			List<Email> emails = new ArrayList<Email>();

			for (String emailStr : emailArray) {
				Email email = mapper.readValue(emailStr, Email.class);
				emails.add(email);
			}

			// List<Email> listOfEmails = mapper.readValue(source.getAttribute("oxTrustEmail"), new TypeReference<List<Email>>(){});
			// destination.setEmails(listOfEmails);
			*/
        List<Email> emails = getAttributeListValue(source, Email.class, "oxTrustEmail");
        destination.setEmails(emails);
    }
    log.trace(" getting addresses ");
    // getting addresses
    if (source.getAttribute("oxTrustAddresses") != null) {
        List<Address> addresses = getAttributeListValue(source, Address.class, "oxTrustAddresses");
        destination.setAddresses(addresses);
    }
    log.trace(" setting phoneNumber ");
    // getting user's PhoneNumber
    if (source.getAttribute("oxTrustPhoneValue") != null) {
        List<PhoneNumber> phoneNumbers = getAttributeListValue(source, PhoneNumber.class, "oxTrustPhoneValue");
        destination.setPhoneNumbers(phoneNumbers);
    }
    if ((source.getOxPPID()) != null) {
        destination.setPairwiseIdentitifers(source.getOxPPID());
    }
    log.trace(" getting ims ");
    // getting ims
    if (source.getAttribute("oxTrustImsValue") != null) {
        List<Im> ims = getAttributeListValue(source, Im.class, "oxTrustImsValue");
        destination.setIms(ims);
    }
    log.trace(" setting photos ");
    // getting photos
    if (source.getAttribute("oxTrustPhotos") != null) {
        List<Photo> photos = getAttributeListValue(source, Photo.class, "oxTrustPhotos");
        destination.setPhotos(photos);
    }
    log.trace(" setting userType ");
    if (source.getAttribute("oxTrustUserType") != null) {
        destination.setUserType(source.getAttribute("oxTrustUserType"));
    }
    log.trace(" setting title ");
    if (source.getAttribute("oxTrustTitle") != null) {
        destination.setTitle(source.getAttribute("oxTrustTitle"));
    }
    log.trace(" setting Locale ");
    /*
		if (source.getAttribute("oxTrustLocale") != null) {
			destination.setLocale(source.getAttribute("oxTrustLocale"));
		}
		*/
    if (source.getAttribute("locale") != null) {
        destination.setLocale(source.getAttribute("locale"));
    }
    log.trace(" setting preferredLanguage ");
    if (source.getPreferredLanguage() != null) {
        destination.setPreferredLanguage(source.getPreferredLanguage());
    }
    log.trace(" setting timeZone ");
    if (source.getTimezone() != null) {
        destination.setTimezone(source.getTimezone());
    }
    log.trace(" setting active ");
    if (source.getAttribute("oxTrustActive") != null) {
        destination.setActive(Boolean.parseBoolean(source.getAttribute("oxTrustActive")));
    }
    log.trace(" setting password ");
    destination.setPassword("Hidden for Privacy Reasons");
    // getting user groups
    log.trace(" setting  groups ");
    if (source.getMemberOf() != null) {
        List<String> listOfGroups = source.getMemberOf();
        List<GroupRef> groupRefList = new ArrayList<GroupRef>();
        for (String groupDN : listOfGroups) {
            GluuGroup gluuGroup = groupService.getGroupByDn(groupDN);
            GroupRef groupRef = new GroupRef();
            groupRef.setDisplay(gluuGroup.getDisplayName());
            groupRef.setValue(gluuGroup.getInum());
            String reference = appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/" + gluuGroup.getInum();
            groupRef.setReference(reference);
            groupRefList.add(groupRef);
        }
        destination.setGroups(groupRefList);
    }
    // getting roles
    if (source.getAttribute("oxTrustRole") != null) {
        List<Role> roles = getAttributeListValue(source, Role.class, "oxTrustRole");
        destination.setRoles(roles);
    }
    log.trace(" getting entitlements ");
    // getting entitlements
    if (source.getAttribute("oxTrustEntitlements") != null) {
        List<Entitlement> entitlements = getAttributeListValue(source, Entitlement.class, "oxTrustEntitlements");
        destination.setEntitlements(entitlements);
    }
    // getting x509Certificates
    log.trace(" setting certs ");
    if (source.getAttribute("oxTrustx509Certificate") != null) {
        List<X509Certificate> x509Certificates = getAttributeListValue(source, X509Certificate.class, "oxTrustx509Certificate");
        destination.setX509Certificates(x509Certificates);
    }
    log.trace(" setting extensions ");
    // List<GluuAttribute> scimCustomAttributes = attributeService.getSCIMRelatedAttributesImpl(attributeService.getCustomAttributes());
    List<GluuAttribute> scimCustomAttributes = attributeService.getSCIMRelatedAttributes();
    if (scimCustomAttributes != null && !scimCustomAttributes.isEmpty()) {
        Map<String, Extension> extensionMap = new HashMap<String, Extension>();
        Extension.Builder extensionBuilder = new Extension.Builder(Constants.USER_EXT_SCHEMA_ID);
        boolean hasExtension = false;
        outer: for (GluuCustomAttribute customAttribute : source.getCustomAttributes()) {
            for (GluuAttribute scimCustomAttribute : scimCustomAttributes) {
                if (customAttribute.getName().equals(scimCustomAttribute.getName())) {
                    hasExtension = true;
                    GluuAttributeDataType scimCustomAttributeDataType = scimCustomAttribute.getDataType();
                    if ((scimCustomAttribute.getOxMultivaluedAttribute() != null) && scimCustomAttribute.getOxMultivaluedAttribute().equals(OxMultivalued.TRUE)) {
                        extensionBuilder.setFieldAsList(customAttribute.getName(), Arrays.asList(customAttribute.getValues()));
                    } else {
                        if (scimCustomAttributeDataType.equals(GluuAttributeDataType.STRING) || scimCustomAttributeDataType.equals(GluuAttributeDataType.PHOTO)) {
                            String value = ExtensionFieldType.STRING.fromString(customAttribute.getValue());
                            extensionBuilder.setField(customAttribute.getName(), value);
                        } else if (scimCustomAttributeDataType.equals(GluuAttributeDataType.DATE)) {
                            Date value = ExtensionFieldType.DATE_TIME.fromString(customAttribute.getValue());
                            extensionBuilder.setField(customAttribute.getName(), value);
                        } else if (scimCustomAttributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
                            BigDecimal value = ExtensionFieldType.DECIMAL.fromString(customAttribute.getValue());
                            extensionBuilder.setField(customAttribute.getName(), value);
                        }
                    }
                    continue outer;
                }
            }
        }
        if (hasExtension) {
            extensionMap.put(Constants.USER_EXT_SCHEMA_ID, extensionBuilder.build());
            destination.getSchemas().add(Constants.USER_EXT_SCHEMA_ID);
            destination.setExtensions(extensionMap);
        }
    }
    log.trace(" getting meta ");
    Meta meta = (destination.getMeta() != null) ? destination.getMeta() : new Meta();
    if (source.getAttribute("oxTrustMetaVersion") != null) {
        meta.setVersion(source.getAttribute("oxTrustMetaVersion"));
    }
    String location = source.getAttribute("oxTrustMetaLocation");
    if (location != null && !location.isEmpty()) {
        if (!location.startsWith("https://") && !location.startsWith("http://")) {
            location = appConfiguration.getBaseEndpoint() + location;
        }
    } else {
        location = appConfiguration.getBaseEndpoint() + "/scim/v2/Users/" + source.getInum();
    }
    meta.setLocation(location);
    if (source.getAttribute("oxTrustMetaCreated") != null && !source.getAttribute("oxTrustMetaCreated").isEmpty()) {
        try {
            DateTime dateTimeUtc = new DateTime(source.getAttribute("oxTrustMetaCreated"), DateTimeZone.UTC);
            meta.setCreated(dateTimeUtc.toDate());
        } catch (Exception e) {
            log.error(" Date parse exception (NEW format), continuing...", e);
            // For backward compatibility
            try {
                meta.setCreated(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(source.getAttribute("oxTrustMetaCreated")));
            } catch (Exception ex) {
                log.error(" Date parse exception (OLD format)", ex);
            }
        }
    }
    if (source.getAttribute("oxTrustMetaLastModified") != null && !source.getAttribute("oxTrustMetaLastModified").isEmpty()) {
        try {
            DateTime dateTimeUtc = new DateTime(source.getAttribute("oxTrustMetaLastModified"), DateTimeZone.UTC);
            meta.setLastModified(dateTimeUtc.toDate());
        } catch (Exception e) {
            log.error(" Date parse exception (NEW format), continuing...", e);
            // For backward compatibility
            try {
                meta.setLastModified(new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(source.getAttribute("oxTrustMetaLastModified")));
            } catch (Exception ex) {
                log.error(" Date parse exception (OLD format)", ex);
            }
        }
    }
    destination.setMeta(meta);
    return destination;
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) User(org.gluu.oxtrust.model.scim2.User) Email(org.gluu.oxtrust.model.scim2.Email) Address(org.gluu.oxtrust.model.scim2.Address) Im(org.gluu.oxtrust.model.scim2.Im) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Photo(org.gluu.oxtrust.model.scim2.Photo) DateTime(org.joda.time.DateTime) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuAttributeDataType(org.xdi.model.GluuAttributeDataType) GluuGroup(org.gluu.oxtrust.model.GluuGroup) X509Certificate(org.gluu.oxtrust.model.scim2.X509Certificate) Date(java.util.Date) BigDecimal(java.math.BigDecimal) 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) GluuAttribute(org.xdi.model.GluuAttribute) GluuUserRole(org.xdi.model.GluuUserRole) Role(org.gluu.oxtrust.model.scim2.Role) Extension(org.gluu.oxtrust.model.scim2.Extension) PhoneNumber(org.gluu.oxtrust.model.scim2.PhoneNumber) GroupRef(org.gluu.oxtrust.model.scim2.GroupRef) Entitlement(org.gluu.oxtrust.model.scim2.Entitlement) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with GluuGroup

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

the class CopyUtils2 method copy.

/**
	 * Copy data from ScimGroup object to GluuGroupn object
	 * 
	 * @param source
	 * @param destination
	 * @param isUpdate
	 * @return
	 * @throws IOException
	 * @throws JsonMappingException
	 * @throws JsonGenerationException
	 * @throws Exception
	 */
public GluuGroup copy(Group source, GluuGroup destination, boolean isUpdate) throws Exception {
    if (source == null || !isValidData(source, isUpdate)) {
        return null;
    }
    if (destination == null) {
        log.trace(" creating a new GluuGroup instant ");
        destination = new GluuGroup();
    }
    if (isUpdate) {
        if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
            destination.setDisplayName(source.getDisplayName());
        }
        if (source.getMembers() != null && source.getMembers().size() > 0) {
            Set<MemberRef> members = source.getMembers();
            List<String> listMembers = new ArrayList<String>();
            for (MemberRef member : members) {
                listMembers.add(personService.getDnForPerson(member.getValue()));
            }
            destination.setMembers(listMembers);
        }
    } else {
        log.trace(" creating a new GroupService instant ");
        log.trace(" source.getDisplayName() : ", source.getDisplayName());
        if (groupService.getGroupByDisplayName(source.getDisplayName()) != null) {
            log.trace(" groupService1.getGroupByDisplayName(source.getDisplayName() != null : ");
            return null;
        }
        if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
            destination.setDisplayName(source.getDisplayName());
        }
        log.trace(" source.getMembers() : ", source.getMembers());
        log.trace(" source.getMembers().size() : ", source.getMembers().size());
        if (source.getMembers() != null && source.getMembers().size() > 0) {
            Set<MemberRef> members = source.getMembers();
            List<String> listMembers = new ArrayList<String>();
            for (MemberRef member : members) {
                listMembers.add(personService.getDnForPerson(member.getValue()));
            }
            destination.setMembers(listMembers);
        }
        /*GluuCustomPerson authUser = (GluuCustomPerson) identity.getSessionMap().get(OxTrustConstants.CURRENT_PERSON);
			destination.setOwner(authUser.getDn());
			log.trace(" authUser.getDn() : ", authUser.getDn());*/
        destination.setStatus(GluuStatus.ACTIVE);
        destination.setOrganization(organizationService.getDnForOrganization());
    }
    return destination;
}
Also used : ArrayList(java.util.ArrayList) MemberRef(org.gluu.oxtrust.model.scim2.MemberRef) GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Example 3 with GluuGroup

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

the class BulkWebService method deleteGroup.

private boolean deleteGroup(String id) throws Exception {
    try {
        GluuGroup gluuGroup = groupService.getGroupByInum(id);
        if (gluuGroup == null) {
            return false;
        } else {
            // For custom script: delete group
            if (externalScimService.isEnabled()) {
                externalScimService.executeScimDeleteGroupMethods(gluuGroup);
            }
            if (gluuGroup.getMembers() != null) {
                if (gluuGroup.getMembers().size() > 0) {
                    String dn = groupService.getDnForGroup(id);
                    serviceUtil.deleteGroupFromPerson(gluuGroup, dn);
                }
            }
            groupService.removeGroup(gluuGroup);
        }
        return true;
    } catch (EntryPersistenceException ex) {
        log.error("Exception: ", ex);
        return false;
    } catch (Exception ex) {
        log.error("Exception: ", ex);
        return false;
    }
}
Also used : EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) GluuGroup(org.gluu.oxtrust.model.GluuGroup) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException)

Example 4 with GluuGroup

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

the class BulkWebService method bulkOperation.

@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response bulkOperation(@Context HttpServletRequest request, @HeaderParam("Authorization") String authorization, ScimBulkOperation operation) throws Exception {
    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    String domain;
    URL reconstructedURL;
    reconstructedURL = new URL(request.getScheme(), request.getServerName(), request.getServerPort(), "");
    domain = reconstructedURL.toString();
    log.info(" getting list of BulkRequest ");
    List<BulkRequests> bulkRequests = operation.getOperations();
    ScimBulkResponse scimBulkResponse = new ScimBulkResponse();
    List<BulkResponses> listResponses = new ArrayList<BulkResponses>();
    for (BulkRequests oneRequest : bulkRequests) {
        log.info(" checking operations ");
        if (oneRequest.getPath().contains("Users")) {
            log.info("  operations is for Users ");
            log.info(" method : " + oneRequest.getMethod());
            if (oneRequest.getMethod().equalsIgnoreCase("POST")) {
                log.info(" method is post ");
                String bulkId = oneRequest.getBulkId();
                String method = oneRequest.getMethod();
                ScimPerson person = oneRequest.getData();
                boolean status = createUser(person);
                if (status) {
                    log.info(" POST status is true ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setBulkId(bulkId);
                    bulkResponses.setMethod(method);
                    GluuCustomPerson gluuPerson = personService.getPersonByUid(person.getUserName());
                    String iD = gluuPerson.getInum();
                    String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Users/").append(iD).toString();
                    bulkResponses.setLocation(location);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("201");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                } else if (!status) {
                    log.info(" POST status is false ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setBulkId(bulkId);
                    bulkResponses.setMethod(method);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("400");
                    result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                }
            } else if (oneRequest.getMethod().equalsIgnoreCase("PUT")) {
                log.info(" Status is PUT ");
                String method = oneRequest.getMethod();
                String version = oneRequest.getVersion();
                String path = oneRequest.getPath();
                ScimPerson person = oneRequest.getData();
                String personiD = getId(path);
                log.info(" Inum :  " + getId(path));
                boolean status = updateUser(personiD, person);
                if (status) {
                    log.info(" PUT status is true ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    String iD = personiD;
                    String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Users/").append(iD).toString();
                    bulkResponses.setLocation(location);
                    EntityTag eTag = new EntityTag(version, true);
                    String newVersion = eTag.getValue();
                    bulkResponses.setVersion(newVersion);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("200");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                } else if (!status) {
                    log.info(" PUT status is false ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    bulkResponses.setVersion(version);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("400");
                    result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                }
            } else if (oneRequest.getMethod().equalsIgnoreCase("DELETE")) {
                log.info(" Operation is DELETE ");
                String method = oneRequest.getMethod();
                String path = oneRequest.getPath();
                String personiD = getId(path);
                boolean status = deleteUser(personiD);
                if (status) {
                    log.info(" DELETE operation is true ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Users/").append(personiD).toString();
                    bulkResponses.setLocation(location);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("200");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                } else if (!status) {
                    log.info(" DELETE operation is False ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("400");
                    result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                }
            }
        //
        } else if (oneRequest.getPath().contains("Groups")) {
            if (oneRequest.getMethod().equalsIgnoreCase("POST")) {
                log.info(" method is post ");
                String bulkId = oneRequest.getBulkId();
                String method = oneRequest.getMethod();
                ScimGroup group = copyUtils.copy(oneRequest.getData(), null);
                boolean status = createGroup(group);
                if (status) {
                    log.info(" POST status is true ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setBulkId(bulkId);
                    bulkResponses.setMethod(method);
                    GluuGroup gluuGroup = groupService.getGroupByDisplayName(group.getDisplayName());
                    String iD = gluuGroup.getInum();
                    String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Groups/").append(iD).toString();
                    bulkResponses.setLocation(location);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("201");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                } else if (!status) {
                    log.info(" POST status is false ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setBulkId(bulkId);
                    bulkResponses.setMethod(method);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("400");
                    result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                }
            } else if (oneRequest.getMethod().equalsIgnoreCase("PUT")) {
                log.info(" Status is PUT ");
                String method = oneRequest.getMethod();
                String version = oneRequest.getVersion();
                String path = oneRequest.getPath();
                ScimGroup group = copyUtils.copy(oneRequest.getData(), null);
                String groupiD = getId(path);
                boolean status = updateGroup(groupiD, group);
                if (status) {
                    log.info(" PUT status is true ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    String iD = groupiD;
                    String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Groups/").append(iD).toString();
                    bulkResponses.setLocation(location);
                    EntityTag eTag = new EntityTag(version, true);
                    String newVersion = eTag.getValue();
                    bulkResponses.setVersion(newVersion);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("200");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                } else if (!status) {
                    log.info(" PUT status is false ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    bulkResponses.setVersion(version);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("400");
                    result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                }
            } else if (oneRequest.getMethod().equalsIgnoreCase("DELETE")) {
                log.info(" Operation is DELETE ");
                String method = oneRequest.getMethod();
                String path = oneRequest.getPath();
                String groupiD = getId(path);
                boolean status = deleteGroup(groupiD);
                if (status) {
                    log.info(" DELETE operation is true ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    String location = (new StringBuilder()).append(domain).append("/oxTrust/seam/resource/restv1/Groups/").append(groupiD).toString();
                    bulkResponses.setLocation(location);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("200");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                } else if (!status) {
                    log.info(" DELETE operation is False ");
                    BulkResponses bulkResponses = new BulkResponses();
                    bulkResponses.setMethod(method);
                    BulkResponseStatus result = new BulkResponseStatus();
                    result.setCode("400");
                    result.setDescription("Request is unparseable, syntactically incorrect, or violates schema.");
                    bulkResponses.setStatus(result);
                    listResponses.add(bulkResponses);
                }
            }
        }
    }
    List<String> schemas = new ArrayList<String>();
    schemas.add(Constants.SCIM1_CORE_SCHEMA_ID);
    scimBulkResponse.setSchemas(schemas);
    scimBulkResponse.setOperations(listResponses);
    URI location = new URI("/Bulk/");
    return Response.ok(scimBulkResponse).location(location).build();
}
Also used : BulkResponseStatus(org.gluu.oxtrust.model.scim.BulkResponseStatus) BulkResponses(org.gluu.oxtrust.model.scim.BulkResponses) BulkRequests(org.gluu.oxtrust.model.scim.BulkRequests) ScimBulkResponse(org.gluu.oxtrust.model.scim.ScimBulkResponse) ArrayList(java.util.ArrayList) GluuGroup(org.gluu.oxtrust.model.GluuGroup) URI(java.net.URI) URL(java.net.URL) ScimBulkResponse(org.gluu.oxtrust.model.scim.ScimBulkResponse) Response(javax.ws.rs.core.Response) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ScimPerson(org.gluu.oxtrust.model.scim.ScimPerson) EntityTag(javax.ws.rs.core.EntityTag) ScimGroup(org.gluu.oxtrust.model.scim.ScimGroup) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 5 with GluuGroup

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

the class CopyUtils method copy.

/**
	 * Copy data from ScimGroup object to GluuGroupn object
	 * 
	 * @param source
	 * @param destination
	 * @param isUpdate
	 * @return
	 * @throws IOException
	 * @throws JsonMappingException
	 * @throws JsonGenerationException
	 * @throws Exception
	 */
public GluuGroup copy(ScimGroup source, GluuGroup destination, boolean isUpdate) throws Exception {
    if (source == null || !isValidData(source, isUpdate)) {
        return null;
    }
    if (destination == null) {
        log.trace(" creating a new GluuGroup instant ");
        destination = new GluuGroup();
    }
    if (isUpdate) {
        if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
            destination.setDisplayName(source.getDisplayName());
        }
        if (source.getMembers() != null && source.getMembers().size() > 0) {
            List<ScimGroupMembers> members = source.getMembers();
            List<String> listMembers = new ArrayList<String>();
            for (ScimGroupMembers member : members) {
                listMembers.add(personService.getDnForPerson(member.getValue()));
            }
            destination.setMembers(listMembers);
        }
    } else {
        log.trace(" creating a new GroupService instant ");
        log.trace(" source.getDisplayName() : ", source.getDisplayName());
        if (groupService.getGroupByDisplayName(source.getDisplayName()) != null) {
            log.trace(" groupService1.getGroupByDisplayName(source.getDisplayName() != null : ");
            return null;
        }
        if (source.getDisplayName() != null && source.getDisplayName().length() > 0) {
            destination.setDisplayName(source.getDisplayName());
        }
        log.trace(" source.getMembers() : ", source.getMembers());
        log.trace(" source.getMembers().size() : ", source.getMembers().size());
        if (source.getMembers() != null && source.getMembers().size() > 0) {
            List<ScimGroupMembers> members = source.getMembers();
            List<String> listMembers = new ArrayList<String>();
            for (ScimGroupMembers member : members) {
                listMembers.add(personService.getDnForPerson(member.getValue()));
            }
            destination.setMembers(listMembers);
        }
        destination.setStatus(GluuStatus.ACTIVE);
        destination.setOrganization(organizationService.getDnForOrganization());
    }
    return destination;
}
Also used : ScimGroupMembers(org.gluu.oxtrust.model.scim.ScimGroupMembers) ArrayList(java.util.ArrayList) GluuGroup(org.gluu.oxtrust.model.GluuGroup)

Aggregations

GluuGroup (org.gluu.oxtrust.model.GluuGroup)56 ArrayList (java.util.ArrayList)15 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)13 Produces (javax.ws.rs.Produces)11 Response (javax.ws.rs.core.Response)11 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)11 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)10 Operation (io.swagger.v3.oas.annotations.Operation)7 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)7 URI (java.net.URI)7 Path (javax.ws.rs.Path)7 ScimGroup (org.gluu.oxtrust.model.scim.ScimGroup)6 VirtualListViewResponse (org.xdi.ldap.model.VirtualListViewResponse)6 DefaultValue (javax.ws.rs.DefaultValue)5 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)5 Group (org.gluu.oxtrust.model.scim2.Group)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 Date (java.util.Date)4 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)4 Consumes (javax.ws.rs.Consumes)4