Search in sources :

Example 6 with GluuCustomAttribute

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

the class CustomAttributeAction method deselectCustomAttributes.

private void deselectCustomAttributes(List<GluuCustomAttribute> customAttributes) {
    for (GluuCustomAttribute customAttribute : customAttributes) {
        String id = this.attributeIds.get(customAttribute);
        this.availableAttributeIds.add(id);
    }
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute)

Example 7 with GluuCustomAttribute

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

the class CustomAttributeAction method addMultiValuesInAttributes.

public void addMultiValuesInAttributes(String inum, boolean mandatory) {
    if (StringHelper.isEmpty(inum)) {
        return;
    }
    GluuAttribute tmpAttribute = this.attributeInums.get(inum);
    if (tmpAttribute == null) {
        return;
    }
    String id = this.attributeIds.get(tmpAttribute);
    this.availableAttributeIds.remove(id);
    String[] values = null;
    int index = 0;
    for (GluuCustomAttribute customAttribute : this.customAttributes) {
        if (tmpAttribute.equals(customAttribute.getMetadata())) {
            values = customAttribute.getValues();
            break;
        }
        index++;
    }
    String[] newValues = new String[values.length + 1];
    System.arraycopy(values, 0, newValues, 0, values.length);
    removeCustomAttribute(inum);
    GluuCustomAttribute tmpGluuPersonAttribute = new GluuCustomAttribute(tmpAttribute.getName(), newValues, true, mandatory);
    tmpGluuPersonAttribute.setMetadata(tmpAttribute);
    this.customAttributes.add(index, tmpGluuPersonAttribute);
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuAttribute(org.xdi.model.GluuAttribute)

Example 8 with GluuCustomAttribute

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

the class CustomAttributeAction method initCustomAttributes.

public void initCustomAttributes(List<GluuAttribute> attributes, List<GluuCustomAttribute> customAttributes, List<String> origins, String[] objectClassTypes, String[] objectClassDisplayNames) {
    this.attributes = new ArrayList<GluuAttribute>(attributes);
    this.customAttributes = customAttributes;
    this.origCustomAttributes = new ArrayList<GluuCustomAttribute>(customAttributes);
    // Set meta-data and sort by metadata.displayName
    attributeService.setAttributeMetadata(customAttributes, this.attributes);
    attributeService.sortCustomAttributes(customAttributes, "metadata.displayName");
    // Prepare map which allows to build tab
    this.attributeByOrigin = groupAttributesByOrigin(attributes);
    // Init special list and maps
    this.availableAttributeIds = new ArrayList<String>();
    this.attributeIds = new IdentityHashMap<GluuAttribute, String>();
    this.attributeInums = new HashMap<String, GluuAttribute>();
    int componentId = 1;
    for (GluuAttribute attribute : attributes) {
        log.debug("attribute: {}", attribute.getName());
        String id = "a" + String.valueOf(componentId++) + "Id";
        this.availableAttributeIds.add(id);
        this.attributeInums.put(attribute.getInum(), attribute);
        this.attributeIds.put(attribute, id);
    }
    // Init origin display names
    this.originDisplayNames = attributeService.getAllAttributeOriginDisplayNames(origins, objectClassTypes, objectClassDisplayNames);
    this.activeOrigin = this.originDisplayNames.get(origins.get(0));
    // Sync Ids map
    for (GluuCustomAttribute personAttribute : customAttributes) {
        if (personAttribute.getMetadata() != null) {
            String id = this.attributeIds.get(personAttribute.getMetadata());
            this.availableAttributeIds.remove(id);
        }
    }
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuAttribute(org.xdi.model.GluuAttribute)

Example 9 with GluuCustomAttribute

use of org.gluu.oxtrust.model.GluuCustomAttribute 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 10 with GluuCustomAttribute

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

the class ServiceUtil method syncEmailReverse.

/**
	 * One-way sync from "mail" to "oxTrustEmail". This will persist the email in "oxTrustEmail"
	 * in SCIM 2.0 format since the SCIM 1.1 format is a subset of SCIM 2.0.
	 *
	 * @param gluuCustomPerson
	 * @param isScim2
	 * @return
	 * @throws Exception
     */
public static GluuCustomPerson syncEmailReverse(GluuCustomPerson gluuCustomPerson, boolean isScim2) throws Exception {
    logger.info(" IN Utils.syncEmailReverse()...");
    GluuCustomAttribute mail = gluuCustomPerson.getGluuCustomAttribute("mail");
    GluuCustomAttribute oxTrustEmail = gluuCustomPerson.getGluuCustomAttribute("oxTrustEmail");
    if (mail != null && mail.getValues().length > 0) {
        // String array
        String[] mails = mail.getValues();
        String[] oxTrustEmails = null;
        if (oxTrustEmail != null) {
            // In the old format, JSON array is in element 0
            oxTrustEmails = oxTrustEmail.getValues();
        }
        ObjectMapper mapper = getObjectMapper();
        // Retain the switch just in case this will be useful in the future
        // if (isScim2) {
        List<String> newOxTrustEmails = new ArrayList<String>();
        Email[] emails = null;
        if (oxTrustEmails != null && oxTrustEmails.length > 0) {
            // emails = mapper.readValue(oxTrustEmails[0], Email[].class);
            emails = new Email[oxTrustEmails.length];
            for (int i = 0; i < oxTrustEmails.length; i++) {
                Email email = mapper.readValue(oxTrustEmails[i], Email.class);
                emails[i] = email;
            }
        }
        for (int i = 0; i < mails.length; i++) {
            if (emails != null && (i < emails.length) && (emails[i] != null)) {
                Email email = emails[i];
                email.setDisplay((email.getDisplay() != null && !email.getDisplay().equalsIgnoreCase(email.getValue())) ? email.getDisplay() : mails[i]);
                email.setValue(mails[i]);
                newOxTrustEmails.add(mapper.writeValueAsString(email));
            } else {
                Email email = new Email();
                email.setValue(mails[i]);
                email.setPrimary(i == 0 ? true : false);
                email.setDisplay(mails[i]);
                email.setType(Email.Type.OTHER);
                newOxTrustEmails.add(mapper.writeValueAsString(email));
            }
        }
        /*
				StringWriter stringWriter = new StringWriter();
				getObjectMapper().writeValue(stringWriter, newOxTrustEmails);
				String newOxTrustEmail = stringWriter.toString();
				*/
        gluuCustomPerson.setAttribute("oxTrustEmail", newOxTrustEmails.toArray(new String[] {}));
    /*
			} else {

				List<ScimPersonEmails> newOxTrustEmails = new ArrayList<ScimPersonEmails>();
				ScimPersonEmails[] scimPersonEmails = new ScimPersonEmails[mails.length];

				if (oxTrustEmails != null && oxTrustEmails.length > 0) {
					scimPersonEmails = getObjectMapper().readValue(oxTrustEmails[0], ScimPersonEmails[].class);
				}

				for (int i = 0; i < mails.length; i++) {

					if (i < scimPersonEmails.length && (scimPersonEmails[i] != null)) {

						ScimPersonEmails scimPersonEmail = scimPersonEmails[i];
						scimPersonEmail.setValue(mails[i]);

						newOxTrustEmails.add(scimPersonEmail);

					} else {

						ScimPersonEmails scimPersonEmail = new ScimPersonEmails();
						scimPersonEmail.setValue(mails[i]);
						scimPersonEmail.setPrimary(i == 0 ? "true" : "false");
						scimPersonEmail.setType(Email.Type.OTHER.getValue());

						newOxTrustEmails.add(scimPersonEmail);
					}
				}

				StringWriter stringWriter = new StringWriter();
				getObjectMapper().writeValue(stringWriter, newOxTrustEmails);
				String newOxTrustEmail = stringWriter.toString();

				gluuCustomPerson.setAttribute("oxTrustEmail", newOxTrustEmail);
			}
			*/
    }
    logger.info(" LEAVING Utils.syncEmailReverse()...");
    return gluuCustomPerson;
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) Email(org.gluu.oxtrust.model.scim2.Email) ArrayList(java.util.ArrayList) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)42 ArrayList (java.util.ArrayList)19 GluuAttribute (org.xdi.model.GluuAttribute)15 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)12 ScimPersonEmails (org.gluu.oxtrust.model.scim.ScimPersonEmails)5 HashSet (java.util.HashSet)4 ConfigurableTest (org.gluu.oxtrust.action.test.ConfigurableTest)4 GluuAppliance (org.gluu.oxtrust.model.GluuAppliance)4 PersonMeta (org.gluu.oxtrust.model.scim.PersonMeta)4 ScimCustomAttributes (org.gluu.oxtrust.model.scim.ScimCustomAttributes)4 ScimName (org.gluu.oxtrust.model.scim.ScimName)4 ScimPerson (org.gluu.oxtrust.model.scim.ScimPerson)4 ScimPersonAddresses (org.gluu.oxtrust.model.scim.ScimPersonAddresses)4 ScimPersonGroups (org.gluu.oxtrust.model.scim.ScimPersonGroups)4 ScimPersonIms (org.gluu.oxtrust.model.scim.ScimPersonIms)4 ScimPersonPhones (org.gluu.oxtrust.model.scim.ScimPersonPhones)4 ScimPersonPhotos (org.gluu.oxtrust.model.scim.ScimPersonPhotos)4 ScimRoles (org.gluu.oxtrust.model.scim.ScimRoles)4 Scimx509Certificates (org.gluu.oxtrust.model.scim.Scimx509Certificates)4 IOException (java.io.IOException)3