Search in sources :

Example 1 with MemberRef

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

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

the class CopyUtils2 method copy.

/**
	 * Copy data from GluuGroup object to ScimGroup object
	 * 
	 * @param source
	 * @param destination
	 * @return
	 * @throws Exception
	 */
public Group copy(GluuGroup source, Group destination) throws Exception {
    if (source == null) {
        return null;
    }
    if (destination == null) {
        destination = new Group();
    }
    destination.setDisplayName(source.getDisplayName());
    destination.setId(source.getInum());
    if (source.getMembers() != null) {
        if (source.getMembers().size() > 0) {
            Set<MemberRef> memberRefSet = new HashSet<MemberRef>();
            List<String> membersList = source.getMembers();
            for (String oneMember : membersList) {
                if (oneMember != null && !oneMember.isEmpty()) {
                    GluuCustomPerson gluuCustomPerson = personService.getPersonByDn(oneMember);
                    MemberRef memberRef = new MemberRef();
                    memberRef.setValue(gluuCustomPerson.getInum());
                    memberRef.setDisplay(gluuCustomPerson.getDisplayName());
                    String reference = appConfiguration.getBaseEndpoint() + "/scim/v2/Users/" + gluuCustomPerson.getInum();
                    memberRef.setReference(reference);
                    memberRefSet.add(memberRef);
                }
            }
            destination.setMembers(memberRefSet);
        }
    }
    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/Groups/" + 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 : ScimGroup(org.gluu.oxtrust.model.scim.ScimGroup) GluuGroup(org.gluu.oxtrust.model.GluuGroup) Group(org.gluu.oxtrust.model.scim2.Group) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Meta(org.gluu.oxtrust.model.scim2.Meta) MemberRef(org.gluu.oxtrust.model.scim2.MemberRef) SimpleDateFormat(java.text.SimpleDateFormat) DateTime(org.joda.time.DateTime) 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) HashSet(java.util.HashSet)

Example 3 with MemberRef

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

the class GroupCoreLoadingStrategy method createDummyGroup.

private Group createDummyGroup() {
    Group group = new Group();
    group.setId("");
    group.setExternalId("");
    group.setDisplayName("");
    Set<MemberRef> members = new HashSet<MemberRef>();
    MemberRef memberRef = new MemberRef();
    memberRef.setOperation("");
    memberRef.setPrimary(false);
    memberRef.setValue("test");
    memberRef.setDisplay("");
    memberRef.setType(MemberRef.Type.USER);
    memberRef.setReference("");
    members.add(memberRef);
    group.setMembers(members);
    return group;
}
Also used : Group(org.gluu.oxtrust.model.scim2.Group) MemberRef(org.gluu.oxtrust.model.scim2.MemberRef) HashSet(java.util.HashSet)

Aggregations

MemberRef (org.gluu.oxtrust.model.scim2.MemberRef)3 HashSet (java.util.HashSet)2 GluuGroup (org.gluu.oxtrust.model.GluuGroup)2 Group (org.gluu.oxtrust.model.scim2.Group)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)1 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)1 ScimGroup (org.gluu.oxtrust.model.scim.ScimGroup)1 Meta (org.gluu.oxtrust.model.scim2.Meta)1 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)1 DateTime (org.joda.time.DateTime)1