From 88388d1203d6ed83c871070f60011b3f52839a67 Mon Sep 17 00:00:00 2001 From: Mike Conway Date: Tue, 25 Sep 2018 14:13:46 -0400 Subject: [PATCH] #315 remove old user-profile submodule --- README.md | 4 + .../jargon/core/pub/domain/Collection.java | 11 + .../jargon/core/pub/CollectionAOImplTest.java | 2 + jargon-user-profile/README.TXT | 4 - jargon-user-profile/pom.xml | 134 ---- .../irods/jargon/userprofile/UserProfile.java | 94 --- .../userprofile/UserProfileConstants.java | 39 - .../UserProfileProtectedFields.java | 51 -- .../userprofile/UserProfilePublicFields.java | 389 ---------- .../userprofile/UserProfileService.java | 105 --- .../UserProfileServiceConfiguration.java | 127 --- .../userprofile/UserProfileServiceImpl.java | 654 ---------------- .../UserProfileValidationException.java | 89 --- .../userprofile/UserProfileValidatorImpl.java | 19 - .../UserProfileServiceImplTest.java | 724 ------------------ .../jargon/userprofile/unittest/AllTests.java | 16 - .../userprofile/unittest/package-info.java | 8 - .../src/test/resources/log4j.properties | 10 - pom.xml | 1 - 19 files changed, 17 insertions(+), 2464 deletions(-) delete mode 100644 jargon-user-profile/README.TXT delete mode 100644 jargon-user-profile/pom.xml delete mode 100644 jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfile.java delete mode 100644 jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileConstants.java delete mode 100644 jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileProtectedFields.java delete mode 100644 jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfilePublicFields.java delete mode 100644 jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileService.java delete mode 100644 jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileServiceConfiguration.java delete mode 100644 jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileServiceImpl.java delete mode 100644 jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileValidationException.java delete mode 100644 jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileValidatorImpl.java delete mode 100644 jargon-user-profile/src/test/java/org/irods/jargon/userprofile/UserProfileServiceImplTest.java delete mode 100644 jargon-user-profile/src/test/java/org/irods/jargon/userprofile/unittest/AllTests.java delete mode 100644 jargon-user-profile/src/test/java/org/irods/jargon/userprofile/unittest/package-info.java delete mode 100644 jargon-user-profile/src/test/resources/log4j.properties diff --git a/README.md b/README.md index 5d40eca3a..cadcd5e27 100644 --- a/README.md +++ b/README.md @@ -43,3 +43,7 @@ Note that the following bug and feature requests are logged in GitHub with relat The collection listing utilities have an ability to 'guess' through the top directories when StrictACLs are turned on. This was masking otherwise visible paths under 'home' when turned on. This is corrected to better reflect the available directories under 'home' + +#### Remove user profile subproject and migrate over to jargon-extensions #315 + +Remove user-profile submodule as old idrop-web legacy, this functionality is being revised and added to jargon-extensions-if for the purposes of standardizing MetaLnx diff --git a/jargon-core/src/main/java/org/irods/jargon/core/pub/domain/Collection.java b/jargon-core/src/main/java/org/irods/jargon/core/pub/domain/Collection.java index 8a1cb0818..a17e36466 100644 --- a/jargon-core/src/main/java/org/irods/jargon/core/pub/domain/Collection.java +++ b/jargon-core/src/main/java/org/irods/jargon/core/pub/domain/Collection.java @@ -68,6 +68,17 @@ public void setCollectionId(final int collectionId) { this.collectionId = collectionId; } + /** + * Handy method to check if inherit permissions are set + * + * @return {@code boolean} of {@code true} if inheritance is set on the + * collection. NB that the {@code getCollectionInheritance} will return + * a raw "1" in the string value. This method is for convenience. + */ + public boolean inheritanceSet() { + return collectionInheritance.equals("1"); + } + public String getCollectionName() { return collectionName; } diff --git a/jargon-core/src/test/java/org/irods/jargon/core/pub/CollectionAOImplTest.java b/jargon-core/src/test/java/org/irods/jargon/core/pub/CollectionAOImplTest.java index a6b8cd3da..1d4ebd6c7 100644 --- a/jargon-core/src/test/java/org/irods/jargon/core/pub/CollectionAOImplTest.java +++ b/jargon-core/src/test/java/org/irods/jargon/core/pub/CollectionAOImplTest.java @@ -1343,6 +1343,7 @@ public void findByAbsolutePath() throws Exception { collFile.mkdirs(); CollectionAO collectionAO = accessObjectFactory.getCollectionAO(irodsAccount); + collectionAO.setAccessPermissionInherit("", collFile.getAbsolutePath(), false); Collection collection = collectionAO.findByAbsolutePath(targetIrodsCollection); Assert.assertNotNull("did not find the collection, was null", collection); @@ -1351,6 +1352,7 @@ public void findByAbsolutePath() throws Exception { collection.getCollectionName()); Assert.assertEquals("collection Name should be same as requested path", targetIrodsCollection, collection.getCollectionName()); + Assert.assertTrue("inheritance should be true", collection.inheritanceSet()); Assert.assertFalse("is set as a proxy", collection.isProxy()); } diff --git a/jargon-user-profile/README.TXT b/jargon-user-profile/README.TXT deleted file mode 100644 index f6b8ebb9d..000000000 --- a/jargon-user-profile/README.TXT +++ /dev/null @@ -1,4 +0,0 @@ -README - - -based partly on eduPerson schema values: http://middleware.internet2.edu/eduperson/docs/internet2-mace-dir-eduperson-200806.html \ No newline at end of file diff --git a/jargon-user-profile/pom.xml b/jargon-user-profile/pom.xml deleted file mode 100644 index e677ca4f8..000000000 --- a/jargon-user-profile/pom.xml +++ /dev/null @@ -1,134 +0,0 @@ - - - 4.0.0 - - jargon - org.irods - 4.3.0.1-SNAPSHOT - - org.irods.jargon - jargon-user-profile - User Profile Service - Utilities for working with iRODS data. These are higher level utilities that complement the jargon-core libraries for working with trees, data objects, collections, and metadata in iRODS - - - junit - junit - test - - - org.irods.jargon - jargon-core - ${project.version} - - - - - - maven-antrun-plugin - - - 0 - validate - - - - - - test.confirm=${jargon.test.confirm} - test.data.directory=${jargon.test.data.directory} - test.irods.admin=${jargon.test.irods.admin} - test.irods.admin.password=${jargon.test.irods.admin.password} - test.irods.user=${jargon.test.irods.user} - test.irods.password=${jargon.test.irods.password} - test.irods.resource=${jargon.test.irods.resource} - test2.irods.user=${jargon.test.irods.user2} - test2.irods.password=${jargon.test.irods.password2} - test2.irods.resource=${jargon.test.irods.resource2} - test3.irods.user=${jargon.test.irods.user3} - test3.irods.password=${jargon.test.irods.password3} - test3.irods.resource=${jargon.test.irods.resource3} - test.irods.host=${jargon.test.irods.host} - test.irods.port=${jargon.test.irods.port} - test.irods.zone=${jargon.test.irods.zone} - test.resource.group=${jargon.test.resource.group} - test.irods.userDN=${jargon.test.irods.userDN} - test.irods.scratch.subdir=${jargon.test.irods.scratch.subdir} - test.mac.icommand.path=${jargon.test.mac.icommand.path} - test.option.exercise.remoteexecstream=${jargon.test.option.exercise.remoteexecstream} - - - - - run - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - true - - - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.apache.maven.plugins - - - maven-antrun-plugin - - - [1.3,) - - - run - - - - - - - - - - org.apache.maven.plugins - - - maven-compiler-plugin - - - [2.3.2,) - - - testCompile - compile - - - - - - - - - - - - - - diff --git a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfile.java b/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfile.java deleted file mode 100644 index d3827c211..000000000 --- a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfile.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * - */ -package org.irods.jargon.userprofile; - -/** - * Represents profile information kept about iRODS users. This is divided into - * public and protected fields. It is up to the profile service to enforce the - * necessary protection levels for this data. - * - * @author Mike Conway - DICE (www.irods.org) - * - */ -public class UserProfile { - - private String zone = ""; - private String userName = ""; - private UserProfilePublicFields userProfilePublicFields = new UserProfilePublicFields(); - private UserProfileProtectedFields userProfileProtectedFields = new UserProfileProtectedFields(); - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("UserProfile:"); - sb.append("\n zone:"); - sb.append(zone); - sb.append("\n userName:"); - sb.append(userName); - sb.append(userProfilePublicFields); - sb.append(userProfileProtectedFields); - return sb.toString(); - } - - /** - * @return the zone - */ - public String getZone() { - return zone; - } - - /** - * @param zone - * the zone to set - */ - public void setZone(final String zone) { - this.zone = zone; - } - - /** - * @return the userName - */ - public String getUserName() { - return userName; - } - - /** - * @param userName - * the userName to set - */ - public void setUserName(final String userName) { - this.userName = userName; - } - - /** - * @return the userProfilePublicFields - */ - public UserProfilePublicFields getUserProfilePublicFields() { - return userProfilePublicFields; - } - - /** - * @param userProfilePublicFields - * the userProfilePublicFields to set - */ - public void setUserProfilePublicFields(final UserProfilePublicFields userProfilePublicFields) { - this.userProfilePublicFields = userProfilePublicFields; - } - - /** - * @return the userProfileProtectedFields - */ - public UserProfileProtectedFields getUserProfileProtectedFields() { - return userProfileProtectedFields; - } - - /** - * @param userProfileProtectedFields - * the userProfileProtectedFields to set - */ - public void setUserProfileProtectedFields(final UserProfileProtectedFields userProfileProtectedFields) { - this.userProfileProtectedFields = userProfileProtectedFields; - } - -} diff --git a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileConstants.java b/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileConstants.java deleted file mode 100644 index e4cb4cdf1..000000000 --- a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileConstants.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * - */ -package org.irods.jargon.userprofile; - -/** - * Constants for serializing user profile data - * - * @author Mike Conway - DICE (www.irods.org) - * - */ -public class UserProfileConstants { - - public static final String ZONE = "zone"; - public static final String USER_NAME = "userName"; - public static final String DESCRIPTION = "description"; - public static final String NICK_NAME = "nickName"; - public static final String CN = "cn"; - public static final String GIVEN_NAME = "givenName"; - public static final String SN = "sn"; - public static final String POSTAL_ADDRESS = "postalAddress"; - public static final String POSTAL_CODE = "postalCode"; - public static final String POST_OFFICE_BOX = "postOfficeBox"; - public static final String LOCALITY_NAME = "localityName"; - public static final String STREET = "street"; - public static final String JPEG_PHOTO = "jpegPhoto"; - public static final String LABELED_URL = "labeledURL"; - public static final String STATE = "st"; - public static final String TITLE = "title"; - public static final String TELEPHONE_NUMBER = "telephoneNumber"; - public static final String EMAIL = "email"; - - /** - * Prevent construction - */ - private UserProfileConstants() { - } - -} diff --git a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileProtectedFields.java b/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileProtectedFields.java deleted file mode 100644 index 7870bb0d3..000000000 --- a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileProtectedFields.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * - */ -package org.irods.jargon.userprofile; - -/** - * Non public fields for user profile information that is not allowed by default - * to the public. This is actually controlled by controlling the visibility of - * the source of this information to the inquiring user, so that protection is - * optional. - *

- * Note that some of the base attributes are based on the RFC for eduPerson at: - * http://middleware.internet2.edu/eduperson/docs/internet2-mace-dir-eduperson- - * 200806.html And going forward more attributes may be added. - * - * @author Mike Conway - DICE (www.irods.org) - * - */ -public class UserProfileProtectedFields { - - /** - * From RFC 4524: The 'mail' (rfc822mailbox) attribute type holds Internet mail - * addresses in Mailbox [RFC2821] form (e.g., user@example.com). - */ - private String mail = ""; - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("UserProfileProtectedFields:"); - sb.append("\n mail:"); - sb.append(mail); - return sb.toString(); - } - - /** - * @return the mail - */ - public String getMail() { - return mail; - } - - /** - * @param mail - * the mail to set - */ - public void setMail(final String mail) { - this.mail = mail; - } - -} diff --git a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfilePublicFields.java b/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfilePublicFields.java deleted file mode 100644 index dffd62b13..000000000 --- a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfilePublicFields.java +++ /dev/null @@ -1,389 +0,0 @@ -package org.irods.jargon.userprofile; - -/** - * Represents standard conventions for user demographic and application - * configuration data. This object represents public data that should be visible - * to all through querying via the user profile service. - *

- * Note that some of the base attributes are based on the RFC for eduPerson at: - * http://middleware.internet2.edu/eduperson/docs/internet2-mace-dir-eduperson- - * 200806.html And going forward more attributes may be added. - * - * @author Mike Conway - DICE (www.irods.org) - * - */ -public class UserProfilePublicFields { - - /** - * Open-ended; whatever the person or the directory manager puts here. According - * to RFC 4519, "The 'description' attribute type contains human-readable - * descriptive phrases about the object. Each description is one value of this - * multi-valued attribute." - */ - private String description = ""; - - /** - * Person's nickname, or the informal name by which they are accustomed to be - * hailed. - */ - private String nickName = ""; - - /** - * The 'cn' ('commonName' in X.500) attribute type contains names of an object. - * Each name is one value of this multi-valued attribute. If the object - * corresponds to a person, it is typically the person's full name." - */ - private String cn = ""; - - /** - * Part of name not surname - */ - private String givenName = ""; - - /** - * Surname or family name. From RFC 4519: "The 'sn' ('surname' in X.500) - * attribute type contains name strings for the family names of a person. Each - * string is one value of this multi-valued attribute." - */ - private String sn = ""; - - /** - * Campus or office address. inetOrgPerson has a homePostalAddress that - * complements this attribute. X.520(2000) reads: "The Postal Address attribute - * type specifies the address information required for the physical postal - * delivery to an object." - */ - private String postalAddress = ""; - - /** - * Follow X.500(2001): "The postal code attribute type specifies the postal code - * of the named object. If this attribute - *

- * value is present, it will be part of the object's postal address." Zip code - * in USA, postal code for other countries. - */ - private String postalCode = ""; - - /** - * From RFC 4519: "The 'postOfficeBox' attribute type contains postal box - * identifiers that a Postal Service uses when a customer arranges to receive - * mail at a box on the premises of the Postal Service. Each postal box - * identifier is a single value of this multi-valued attribute." - */ - private String postOfficeBox = ""; - - /** - * According to RFC 4519, "The 'l' ('localityName' in X.500) attribute type - * contains names of a locality or place, such as a city, county, or other - * geographic region. Each name is one value of this multi-valued attribute." - */ - private String localityName = ""; - - /** - * From RFC 4519: "The 'street' ('streetAddress' in X.500) attribute type - * contains site information from a postal address (i.e., the street name, - * place, avenue, and the house number). Each street is one value of this - * multi-valued attribute." - */ - private String street = ""; - - /** - * IRODS URI or URL to a publicly available photo in String form - *

- * Follow inetOrgPerson definition of RFC 2798: "Used to store one or more - * images of a person using the JPEG File Interchange Format [JFIF]." - * - */ - private String jpegPhoto = ""; - - /** - * Follow inetOrgPerson definition of RFC 2079: "Uniform Resource Identifier - * with optional label." - */ - private String labeledURL = ""; - - /** - * Abbreviation for state or province name. - *

- * Format: The values should be coordinated on a national level. If well-known - * shortcuts exist, like the two-letter state abbreviations in the US, these - * abbreviations are preferred over longer full names. - *

- * From RFC 4519: "The 'st' ('stateOrProvinceName' in X.500) attribute type - * contains the full names of states or provinces. Each name is one value of - * this multi-valued attribute." - */ - private String st = ""; - - /** - * From RFC 4519: "The 'title' attribute type contains the title of a person in - * their organizational context. Each title is one value of this multi-valued - * attribute." - */ - private String title = ""; - - /** - * Office/campus phone number. Attribute values should comply with the ITU - * Recommendation E.123 [E.123]: i.e., "+44 71 123 4567." - */ - private String telephoneNumber = ""; - - /** - * @return the description - */ - public String getDescription() { - return description; - } - - /** - * @param description - * the description to set - */ - public void setDescription(final String description) { - this.description = description; - } - - /** - * @return the nickName - */ - public String getNickName() { - return nickName; - } - - /** - * @param nickName - * the nickName to set - */ - public void setNickName(final String nickName) { - this.nickName = nickName; - } - - /** - * @return the cn - */ - public String getCn() { - return cn; - } - - /** - * @param cn - * the cn to set - */ - public void setCn(final String cn) { - this.cn = cn; - } - - /** - * @return the givenName - */ - public String getGivenName() { - return givenName; - } - - /** - * @param givenName - * the givenName to set - */ - public void setGivenName(final String givenName) { - this.givenName = givenName; - } - - /** - * @return the sn - */ - public String getSn() { - return sn; - } - - /** - * @param sn - * the sn to set - */ - public void setSn(final String sn) { - this.sn = sn; - } - - /** - * @return the postalAddress - */ - public String getPostalAddress() { - return postalAddress; - } - - /** - * @param postalAddress - * the postalAddress to set - */ - public void setPostalAddress(final String postalAddress) { - this.postalAddress = postalAddress; - } - - /** - * @return the postalCode - */ - public String getPostalCode() { - return postalCode; - } - - /** - * @param postalCode - * the postalCode to set - */ - public void setPostalCode(final String postalCode) { - this.postalCode = postalCode; - } - - /** - * @return the postOfficeBox - */ - public String getPostOfficeBox() { - return postOfficeBox; - } - - /** - * @param postOfficeBox - * the postOfficeBox to set - */ - public void setPostOfficeBox(final String postOfficeBox) { - this.postOfficeBox = postOfficeBox; - } - - /** - * @return the localityName - */ - public String getLocalityName() { - return localityName; - } - - /** - * @param localityName - * the localityName to set - */ - public void setLocalityName(final String localityName) { - this.localityName = localityName; - } - - /** - * @return the street - */ - public String getStreet() { - return street; - } - - /** - * @param street - * the street to set - */ - public void setStreet(final String street) { - this.street = street; - } - - /** - * @return the jpegPhoto - */ - public String getJpegPhoto() { - return jpegPhoto; - } - - /** - * @param jpegPhoto - * the jpegPhoto to set - */ - public void setJpegPhoto(final String jpegPhoto) { - this.jpegPhoto = jpegPhoto; - } - - /** - * @return the labeledURL - */ - public String getLabeledURL() { - return labeledURL; - } - - /** - * @param labeledURL - * the labeledURL to set - */ - public void setLabeledURL(final String labeledURL) { - this.labeledURL = labeledURL; - } - - /** - * @return the st - */ - public String getSt() { - return st; - } - - /** - * @param st - * the st to set - */ - public void setSt(final String st) { - this.st = st; - } - - /** - * @return the title - */ - public String getTitle() { - return title; - } - - /** - * @param title - * the title to set - */ - public void setTitle(final String title) { - this.title = title; - } - - /** - * @return the telephoneNumber - */ - public String getTelephoneNumber() { - return telephoneNumber; - } - - /** - * @param telephoneNumber - * the telephoneNumber to set - */ - public void setTelephoneNumber(final String telephoneNumber) { - this.telephoneNumber = telephoneNumber; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("UserProfilePublicFields"); - sb.append("\n description:"); - sb.append(description); - sb.append("\n nickName:"); - sb.append(nickName); - sb.append("\n cn:"); - sb.append(cn); - sb.append("\n givenName:"); - sb.append(givenName); - sb.append("\n sn:"); - sb.append(sn); - sb.append("\n postalAddress:"); - sb.append(postalAddress); - sb.append("\n postalCode:"); - sb.append(postalCode); - sb.append("\n postOfficeBox:"); - sb.append(postOfficeBox); - sb.append("\n sn:"); - sb.append(sn); - sb.append("\n st:"); - sb.append(st); - sb.append("\n street:"); - sb.append(street); - sb.append("\n telephoneNumber:"); - sb.append(telephoneNumber); - sb.append("\n title:"); - sb.append(title); - return sb.toString(); - } - -} diff --git a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileService.java b/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileService.java deleted file mode 100644 index 2d130727a..000000000 --- a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileService.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.irods.jargon.userprofile; - -import org.irods.jargon.core.exception.DataNotFoundException; -import org.irods.jargon.core.exception.DuplicateDataException; -import org.irods.jargon.core.exception.JargonException; - -/** - * Interface for a service to query and maintain user profile information. - * - * @author Mike Conway - DICE (www.irods.org) - * - */ -public interface UserProfileService { - - public static final String AVU_UNIT_NAMESPACE = "irods:UserProfileServicePublicAttribute"; - - /** - * Add a profile for the given user. - * - * @param irodsUserName - * {@code String} with the name of the iRODS user in the given zone - * for which a profile will be added - * @param userProfile - * {@link UserProfile} that will be added - * @throws UserProfileValidationException - * if the data in the profile is invalid - * @throws DuplicateDataException - * if the profile already exists - * @throws JargonException - * general exception - */ - void addProfileForUser(final String irodsUserName, final UserProfile userProfile) - throws UserProfileValidationException, DuplicateDataException, JargonException; - - /** - * Get the configuration for the user profile service - * - * @return {@link UserProfileServiceConfiguration} - */ - UserProfileServiceConfiguration getUserProfileServiceConfiguration(); - - /** - * Set the configuration for the user profile service - * - * @param userProfileServiceConfiguration - * {@link UserProfileServiceConfiguration} - */ - void setUserProfileServiceConfiguration(UserProfileServiceConfiguration userProfileServiceConfiguration); - - /** - * Remove the public and protected user profile information - * - * @param irodsUserName - * {@code String} with the name of the iRODS user in the given zone - * for which a profile will be removed - * @throws JargonException - */ - void removeProfileInformation(String irodsUserName) throws JargonException; - - /** - * Given an iRODS user name, retrive the user profile if it exists - * - * @param userName - * {@code String} with the iRODS user name - * @return {@link UserProfile} with available information (may depend on ACL's) - * @throws DataNotFoundException - * if the user profile information does not exist - * @throws JargonException - */ - UserProfile retrieveUserProfile(String userName) throws DataNotFoundException, JargonException; - - /** - * Return the calculated path to the user profile directory based on the user - * name and the {@link UserProfileServiceConfiguration} information. - * - * @param userName - * {@code String} with the iRODS user name for which the profile - * information is kept - * @return {@code String} with the absolute path to the iRODS collection where - * user profile information is kept. - */ - String getUserProfileDir(String userName); - - /** - * Update the user profile information for the given user - * - * @param userProfile - * {@link UserProfile} containing the desired state of the user's - * information - * @throws JargonException - */ - void updateUserProfile(UserProfile userProfile) throws JargonException; - - /** - * Check and see if a group has been configured with read/write access to the - * protected profile. If a group is not configured, then things still operate, - * but that permission is not set and will have to be set by the administrator - * - * @return {@code boolean} of {@code true} if you want to set permissions for a - * protected profile group - * @throws JargonException - */ - boolean isProtectedReadGroupConfigured() throws JargonException; - -} \ No newline at end of file diff --git a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileServiceConfiguration.java b/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileServiceConfiguration.java deleted file mode 100644 index b08d8497d..000000000 --- a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileServiceConfiguration.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * - */ -package org.irods.jargon.userprofile; - -/** - * Configuration settings for the user profile service. Controls behavior and - * defaults of the user profile service - * - * @author Mike Conway - DICE (www.irods.org) - * - */ -public class UserProfileServiceConfiguration { - - public static final String PUBLIC_PROFILE_FILE_NAME = ".profile"; - public static final String PROTECTED_PROFILE_FILE_NAME = ".protected_profile"; - public static final String PROFILE_SUBDIR_NAME = ".irods"; - - private String publicProfileFileName = PUBLIC_PROFILE_FILE_NAME; - private String protectedProfileFileName = PROTECTED_PROFILE_FILE_NAME; - private String profileSubdirName = PROFILE_SUBDIR_NAME; - private String protectedProfileReadWriteGroup = "protected_profile_read_group"; - private boolean protectedProfileGroupHasWriteAccessToPublic = true; - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("userProfileServiceConfiguration"); - sb.append("\n profileSubdirName:"); - sb.append(profileSubdirName); - sb.append("\n publicProfileFileName:"); - sb.append(publicProfileFileName); - sb.append("\n protectedProfileReadWriteGroup:"); - sb.append(protectedProfileReadWriteGroup); - sb.append("\n protectedProfileGroupHasWriteAccessToPublic:"); - sb.append(protectedProfileGroupHasWriteAccessToPublic); - return sb.toString(); - } - - /** - * @return the publicProfileFileName which is the file name of the public - * profile - */ - public String getPublicProfileFileName() { - return publicProfileFileName; - } - - /** - * @param publicProfileFileName - * the publicProfileFileName to set which is the file name of the - * public profile - */ - public void setPublicProfileFileName(final String publicProfileFileName) { - this.publicProfileFileName = publicProfileFileName; - } - - /** - * @return the protectedProfileFileName the name of the protected profile file - */ - public String getProtectedProfileFileName() { - return protectedProfileFileName; - } - - /** - * @param protectedProfileFileName - * the protectedProfileFileName to set - */ - public void setProtectedProfileFileName(final String protectedProfileFileName) { - this.protectedProfileFileName = protectedProfileFileName; - } - - /** - * @return the protectedProfileReadWriteGroup the iRODS user group that will be - * given read/write access to the protected part of the profile - */ - public String getProtectedProfileReadWriteGroup() { - return protectedProfileReadWriteGroup; - } - - /** - * @param protectedProfileReadWriteGroup - * the protectedProfileReadWriteGroup to set the iRODS user group - * that will be given read/write access to the protected part of the - * profile - */ - public void setProtectedProfileReadWriteGroup(final String protectedProfileReadWriteGroup) { - this.protectedProfileReadWriteGroup = protectedProfileReadWriteGroup; - } - - /** - * @return the protectedProfileGroupHasWriteAccessToPublic indicates whether the - * protected profile read/write group has write access to the public - * part of the profile - */ - public boolean isProtectedProfileGroupHasWriteAccessToPublic() { - return protectedProfileGroupHasWriteAccessToPublic; - } - - /** - * @param protectedProfileGroupHasWriteAccessToPublic - * the protectedProfileGroupHasWriteAccessToPublic to set - */ - public void setProtectedProfileGroupHasWriteAccessToPublic( - final boolean protectedProfileGroupHasWriteAccessToPublic) { - this.protectedProfileGroupHasWriteAccessToPublic = protectedProfileGroupHasWriteAccessToPublic; - } - - /** - * Get the subdirectory for the profile. Note that this may be blank, indicating - * that no profile subdir is used - * - * @return the profileSubdirName - */ - public String getProfileSubdirName() { - return profileSubdirName; - } - - /** - * Set the subdirectory for the profile, set to blank if no subdir is needed - * - * @param profileSubdirName - * the profileSubdirName to set - */ - public void setProfileSubdirName(final String profileSubdirName) { - this.profileSubdirName = profileSubdirName; - } -} diff --git a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileServiceImpl.java b/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileServiceImpl.java deleted file mode 100644 index fb7dee13b..000000000 --- a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileServiceImpl.java +++ /dev/null @@ -1,654 +0,0 @@ -/** - * - */ -package org.irods.jargon.userprofile; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import org.irods.jargon.core.connection.IRODSAccount; -import org.irods.jargon.core.exception.DataNotFoundException; -import org.irods.jargon.core.exception.DuplicateDataException; -import org.irods.jargon.core.exception.JargonException; -import org.irods.jargon.core.exception.JargonRuntimeException; -import org.irods.jargon.core.pub.DataObjectAO; -import org.irods.jargon.core.pub.IRODSAccessObjectFactory; -import org.irods.jargon.core.pub.UserGroupAO; -import org.irods.jargon.core.pub.domain.AvuData; -import org.irods.jargon.core.pub.domain.UserGroup; -import org.irods.jargon.core.pub.io.IRODSFile; -import org.irods.jargon.core.query.AVUQueryElement; -import org.irods.jargon.core.query.AVUQueryElement.AVUQueryPart; -import org.irods.jargon.core.query.JargonQueryException; -import org.irods.jargon.core.query.MetaDataAndDomainData; -import org.irods.jargon.core.query.QueryConditionOperators; -import org.irods.jargon.core.service.AbstractJargonService; -import org.irods.jargon.core.utils.MiscIRODSUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Manage the storage and retrieval of {@code UserProfile} information in iRODS. - *

- * This implementation uses a convention of a .profile file in the user home dir - * with the values attached as AVU's, and a .protected file in the user home dir - * with the values in the file as properties. - *

- * This scheme is necessary as AVU's are publicly query-able. Having some data - * in AVU's will help in that they are more easily queried. - * - * @author Mike Conway - DICE (www.irods.org) - * - */ -public class UserProfileServiceImpl extends AbstractJargonService implements UserProfileService { - - public static final Logger log = LoggerFactory.getLogger(UserProfileServiceImpl.class); - - private UserProfileServiceConfiguration userProfileServiceConfiguration = new UserProfileServiceConfiguration(); - private final DataObjectAO dataObjectAO; - - /** - * Constructs a user profile service with references to objects necessary to - * construct jargon access objects and i/o objects - * - * @param irodsAccessObjectFactory - * @param irodsAccount - */ - public UserProfileServiceImpl(final IRODSAccessObjectFactory irodsAccessObjectFactory, - final IRODSAccount irodsAccount) { - super(irodsAccessObjectFactory, irodsAccount); - try { - dataObjectAO = irodsAccessObjectFactory.getDataObjectAO(getIrodsAccount()); - } catch (JargonException e) { - log.error("cannot create dataObjectAO", e); - throw new JargonRuntimeException("error creating DataObjectAO reference", e); - } - } - - /* - * (non-Javadoc) - * - * @see org.irods.jargon.userprofile.UserProfileService#updateUserProfile(org - * .irods.jargon.userprofile.UserProfile) - */ - @Override - public void updateUserProfile(final UserProfile userProfile) throws JargonException { - - log.info("updateUserProfile()"); - if (userProfile == null) { - throw new IllegalArgumentException("null userProfile"); - } - log.info("user profile:{}", userProfile); - - log.info("remove old..."); - removeProfileInformation(userProfile.getUserName()); - log.info("add new..."); - addProfileForUser(userProfile.getUserName(), userProfile); - log.info("profile updated"); - - } - - /* - * (non-Javadoc) - * - * @see org.irods.jargon.userprofile.UserProfileService#retrieveUserProfile(java - * .lang.String) - */ - @Override - public UserProfile retrieveUserProfile(final String userName) throws DataNotFoundException, JargonException { - - log.info("retrieveUserProfile()"); - - if (userName == null || userName.isEmpty()) { - throw new IllegalArgumentException("null or empty userName"); - } - - log.info("userName:{}", userName); - - UserProfile userProfile = new UserProfile(); - userProfile.setUserName(userName); - userProfile.setZone(irodsAccount.getZone()); - - log.info("retreiving the public profile"); - - IRODSFile publicProfileFile = retrieveUserPublicProfileFile(userName); - - if (!publicProfileFile.exists()) { - log.warn("no public profile found at:{}", publicProfileFile.getAbsolutePath()); - throw new DataNotFoundException("no public profile found"); - } - - log.info("getting profile AVUs..."); - - List query = new ArrayList(); - - try { - query.add(AVUQueryElement.instanceForValueQuery(AVUQueryPart.UNITS, QueryConditionOperators.EQUAL, - - UserProfileService.AVU_UNIT_NAMESPACE)); - } catch (JargonQueryException e) { - log.error("error building AVU query", e); - throw new JargonException("error querying for AVUs", e); - } - - List metadataValues = dataObjectAO - .findMetadataValuesForDataObject(publicProfileFile.getAbsolutePath()); - - for (MetaDataAndDomainData metadata : metadataValues) { - log.info("metadata value:{}", metadata); - - if (metadata.getAvuAttribute().equals(UserProfileConstants.DESCRIPTION)) { - userProfile.getUserProfilePublicFields().setDescription(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.NICK_NAME)) { - userProfile.getUserProfilePublicFields().setNickName(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.CN)) { - userProfile.getUserProfilePublicFields().setCn(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.GIVEN_NAME)) { - userProfile.getUserProfilePublicFields().setGivenName(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.SN)) { - userProfile.getUserProfilePublicFields().setSn(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.POSTAL_CODE)) { - userProfile.getUserProfilePublicFields().setPostalCode(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.POSTAL_ADDRESS)) { - userProfile.getUserProfilePublicFields().setPostalAddress(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.POST_OFFICE_BOX)) { - userProfile.getUserProfilePublicFields().setPostOfficeBox(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.LOCALITY_NAME)) { - userProfile.getUserProfilePublicFields().setLocalityName(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.STREET)) { - userProfile.getUserProfilePublicFields().setStreet(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.STATE)) { - userProfile.getUserProfilePublicFields().setSt(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.JPEG_PHOTO)) { - userProfile.getUserProfilePublicFields().setJpegPhoto(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.LABELED_URL)) { - userProfile.getUserProfilePublicFields().setLabeledURL(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.TELEPHONE_NUMBER)) { - userProfile.getUserProfilePublicFields().setTelephoneNumber(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.TITLE)) { - userProfile.getUserProfilePublicFields().setTitle(metadata.getAvuValue()); - continue; - } - - if (metadata.getAvuAttribute().equals(UserProfileConstants.ZONE)) { - userProfile.setZone(metadata.getAvuValue()); - continue; - } - - /* - * right now, quietly log and ignore property that is not anticipated - */ - log.warn("property not recognized: {}", metadata); - - } - - log.info("look for protected profile file info..."); - String userHomeDir = getUserProfileDir(userName); - - IRODSFile protectedProfileFile = getIrodsAccessObjectFactory().getIRODSFileFactory(getIrodsAccount()) - .instanceIRODSFile(userHomeDir, userProfileServiceConfiguration.getProtectedProfileFileName()); - - // tolerate no protected profile info - if (!protectedProfileFile.exists()) { - log.warn("no protected profile info, ignore and return public info:{}", userProfile); - return userProfile; - } - - InputStream userProfileInputStream = new BufferedInputStream(getIrodsAccessObjectFactory() - .getIRODSFileFactory(getIrodsAccount()).instanceIRODSFileInputStream(protectedProfileFile)); - Properties protectedProperties = new Properties(); - try { - protectedProperties.load(userProfileInputStream); - } catch (IOException e) { - log.error("error loading protected properties from stream:{}", userProfileInputStream, e); - throw new JargonException("error loading protected properties", e); - } finally { - try { - userProfileInputStream.close(); - } catch (Exception e) { - } - } - - if (protectedProperties.get(UserProfileConstants.EMAIL) != null) { - userProfile.getUserProfileProtectedFields() - .setMail((String) protectedProperties.get(UserProfileConstants.EMAIL)); - } - - log.info("completed user profile:{}", userProfile); - return userProfile; - - } - - /* - * (non-Javadoc) - * - * @see org.irods.jargon.userprofile.UserProfileService#removeProfileInformation - * (java.lang.String) - */ - @Override - public void removeProfileInformation(final String irodsUserName) throws JargonException { - log.info("removeProfileInformation()"); - - if (irodsUserName == null || irodsUserName.isEmpty()) { - throw new IllegalArgumentException("null or empty irodsUserName"); - } - - log.info("irodsUserName:{}", irodsUserName); - - String userHomeDir = getUserProfileDir(irodsUserName); - - log.info("user home dir:{}", userHomeDir); - - IRODSFile userProfileFile = getIrodsAccessObjectFactory().getIRODSFileFactory(getIrodsAccount()) - .instanceIRODSFile(userHomeDir, userProfileServiceConfiguration.getPublicProfileFileName()); - - // delete the actual public profile file and associated AVU's - deletePublicProfile(irodsUserName, userProfileFile); - - IRODSFile protectedProfileFile = getIrodsAccessObjectFactory().getIRODSFileFactory(getIrodsAccount()) - .instanceIRODSFile(userHomeDir, userProfileServiceConfiguration.getProtectedProfileFileName()); - - log.info("deleting the protected profile file:{}", protectedProfileFile.getAbsolutePath()); - - protectedProfileFile.deleteWithForceOption(); - log.info("delete completed"); - - } - - /** - * @param irodsUserName - * @param userProfileFile - * @throws JargonException - * @throws DataNotFoundException - */ - private void deletePublicProfile(final String irodsUserName, final IRODSFile userProfileFile) - throws JargonException, DataNotFoundException { - if (!userProfileFile.exists()) { - log.info("user profile file does not exist, just ignore and proceed:{}", irodsUserName); - } else { - log.info("delete all avu's associated with profile", userProfileFile.getAbsolutePath()); - List queryList = new ArrayList(); - try { - queryList.add(AVUQueryElement.instanceForValueQuery(AVUQueryPart.UNITS, QueryConditionOperators.EQUAL, - - AVU_UNIT_NAMESPACE)); - List metadataList = dataObjectAO.findMetadataValuesByMetadataQuery(queryList); - AvuData avuData; - - for (MetaDataAndDomainData metadataAndDomainData : metadataList) { - avuData = AvuData.instance(metadataAndDomainData.getAvuAttribute(), - metadataAndDomainData.getAvuValue(), metadataAndDomainData.getAvuUnit()); - dataObjectAO.deleteAVUMetadata(userProfileFile.getAbsolutePath(), avuData); - } - - log.info("avus were deleted..now delete the public profile file"); - userProfileFile.deleteWithForceOption(); - - } catch (JargonQueryException e) { - log.info("Jargon query exeception querying for AVU metadata", e); - throw new JargonException(e); - } - } - } - - /* - * (non-Javadoc) - * - * @see org.irods.jargon.userprofile.UserProfileService#addProfileForUser(java - * .lang.String, org.irods.jargon.userprofile.UserProfile) - */ - @Override - public void addProfileForUser(final String irodsUserName, final UserProfile userProfile) - throws UserProfileValidationException, DuplicateDataException, JargonException { - - log.info("addProfileForUser()"); - boolean userGroupForProfilePresent = false; - if (userProfileServiceConfiguration.getProtectedProfileReadWriteGroup() == null - || userProfileServiceConfiguration.getProtectedProfileReadWriteGroup().isEmpty()) { - log.info("no permissions set for protected profile group in user profile service config"); - } else if (!isProtectedReadGroupConfigured()) { - log.info("no permissions set for protected profile group in user profile service config"); - } else { - userGroupForProfilePresent = true; - } - - if (irodsUserName == null || irodsUserName.isEmpty()) { - throw new IllegalArgumentException("null or empty irodsUserName"); - } - - if (userProfile == null) { - throw new IllegalArgumentException("null userProfile"); - } - - log.info("userName:{}", irodsUserName); - log.info("UserProfile:{}", userProfile); - - // see if a user profile already exists for this user - String userHomeDir = getUserProfileDir(irodsUserName); - log.info("looking for profile in userHomeDir:{}", userHomeDir); - - IRODSFile userProfileFile = getIrodsAccessObjectFactory().getIRODSFileFactory(getIrodsAccount()) - .instanceIRODSFile(userHomeDir, userProfileServiceConfiguration.getPublicProfileFileName()); - - if (userProfileFile.exists()) { - log.error("cannot add, user profile already exists for user:{}", irodsUserName); - throw new DuplicateDataException("user profile already exists"); - } - - userProfileFile.getParentFile().mkdirs(); - - log.info("creating the public profile"); - - try { - userProfileFile.createNewFile(); - // public can read the profile - // if so indicated in the config, give a special group write access - // to the public profile - if (userGroupForProfilePresent) { - log.info("permissions well be set for protected profile group in user profile service config"); - - if (userProfileServiceConfiguration.isProtectedProfileGroupHasWriteAccessToPublic()) { - log.info("adding WRITE acl to public profile"); - dataObjectAO.setAccessPermissionWrite(irodsAccount.getZone(), userProfileFile.getAbsolutePath(), - userProfileServiceConfiguration.getProtectedProfileReadWriteGroup()); - log.info("adding public read access"); - dataObjectAO.setAccessPermissionRead(irodsAccount.getZone(), userProfileFile.getAbsolutePath(), - "public"); - } - } - - } catch (IOException e) { - log.error("unable to create user profile file:{}", userProfileFile); - throw new JargonException("error creating user profile file", e); - } - - log.info("creating the protected profile file"); - - IRODSFile protectedProfileFile = getIrodsAccessObjectFactory().getIRODSFileFactory(getIrodsAccount()) - .instanceIRODSFile(userHomeDir, userProfileServiceConfiguration.getProtectedProfileFileName()); - - log.info("creating the protected profile file:{}", protectedProfileFile.getAbsolutePath()); - - if (protectedProfileFile.exists()) { - log.error("cannot add, protected user profile already exists for user:{}", irodsUserName); - throw new DuplicateDataException("protected user profile already exists"); - } - - log.info("creating the protected profile"); - - try { - protectedProfileFile.createNewFile(); - } catch (IOException e) { - log.error("unable to create protected user profile file:{}", userProfileFile); - throw new JargonException("error creating protected user profile file", e); - } - - // if a user or group is specified as having read/write access to the - // profile, do an acl to that user - - if (userGroupForProfilePresent) { - log.info("adding WRITE acl to protected profile"); - dataObjectAO.setAccessPermissionWrite(irodsAccount.getZone(), protectedProfileFile.getAbsolutePath(), - userProfileServiceConfiguration.getProtectedProfileReadWriteGroup()); - } - - // provision the public profile with the given profile information by - // hanging AVU off of the file - - UserProfilePublicFields userProfilePublicFields = userProfile.getUserProfilePublicFields(); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.ZONE, userProfile.getZone()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.USER_NAME, - userProfile.getUserName()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.DESCRIPTION, - userProfilePublicFields.getDescription()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.NICK_NAME, - userProfilePublicFields.getNickName()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.CN, - userProfilePublicFields.getCn()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.GIVEN_NAME, - userProfilePublicFields.getGivenName()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.SN, - userProfilePublicFields.getSn()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.POSTAL_CODE, - userProfilePublicFields.getPostalCode()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.POSTAL_ADDRESS, - userProfilePublicFields.getPostalAddress()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.POST_OFFICE_BOX, - userProfilePublicFields.getPostOfficeBox()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.LOCALITY_NAME, - userProfilePublicFields.getLocalityName()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.STREET, - userProfilePublicFields.getStreet()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.JPEG_PHOTO, - userProfilePublicFields.getJpegPhoto()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.LABELED_URL, - userProfilePublicFields.getLabeledURL()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.STATE, - userProfilePublicFields.getSt()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.TITLE, - userProfilePublicFields.getTitle()); - - addAVUIfDataPresent(userProfileFile.getAbsolutePath(), UserProfileConstants.TELEPHONE_NUMBER, - userProfilePublicFields.getTelephoneNumber()); - - // provision the protected profile information, first make into a - // Properties object - - Properties protectedProperties = new Properties(); - if (!userProfile.getUserProfileProtectedFields().getMail().isEmpty()) { - protectedProperties.put(UserProfileConstants.EMAIL, userProfile.getUserProfileProtectedFields().getMail()); - - } - - log.info("protected properties before serialization:{}", protectedProperties); - - OutputStream protectedPropertiesOutputStream = new BufferedOutputStream(getIrodsAccessObjectFactory() - .getIRODSFileFactory(getIrodsAccount()).instanceIRODSFileOutputStream(protectedProfileFile)); - - log.info("output stream created, store to properties file"); - - try { - protectedProperties.store(protectedPropertiesOutputStream, "saved protected properties"); - protectedPropertiesOutputStream.close(); - log.info("properties stored and stream closed"); - } catch (IOException e) { - log.error("io exeption storing properties file", e); - throw new JargonException("error serializing protected properties to output stream", e); - } - - } - - /** - * Add the AVU data based on the provided parameters. Note that if the value of - * the AVU is blank, it won't be added. Only set fields are preserved - * - * @param irodsDataObjectAbsolutePath - * @param proposedAttribute - * @param proposedValue - * @throws JargonException - */ - private void addAVUIfDataPresent(final String irodsDataObjectAbsolutePath, final String proposedAttribute, - final String proposedValue) throws JargonException { - - log.info("addAVUIfDataPresent()"); - - if (proposedAttribute == null || proposedAttribute.isEmpty()) { - throw new IllegalArgumentException("null or empty proposedAttribute"); - } - - if (proposedValue == null) { - throw new IllegalArgumentException("null proposedValue"); - } - - if (proposedValue.isEmpty()) { - log.info("ignore avu, value is blank"); - return; - } - - // valid data if I got here, add the AVU - - AvuData avuData; - avuData = AvuData.instance(proposedAttribute, proposedValue, AVU_UNIT_NAMESPACE); - dataObjectAO.addAVUMetadata(irodsDataObjectAbsolutePath, avuData); - } - - /* - * (non-Javadoc) - * - * @see org.irods.jargon.userprofile.UserProfileService# - * getUserProfileServiceConfiguration() - */ - @Override - public UserProfileServiceConfiguration getUserProfileServiceConfiguration() { - return userProfileServiceConfiguration; - } - - /* - * (non-Javadoc) - * - * @see org.irods.jargon.userprofile.UserProfileService# - * setUserProfileServiceConfiguration - * (org.irods.jargon.userprofile.UserProfileServiceConfiguration) - */ - @Override - public void setUserProfileServiceConfiguration( - final UserProfileServiceConfiguration userProfileServiceConfiguration) { - this.userProfileServiceConfiguration = userProfileServiceConfiguration; - } - - /* - * (non-Javadoc) - * - * @see org.irods.jargon.userprofile.UserProfileService#getUserProfileDir(java - * .lang.String) - */ - @Override - public String getUserProfileDir(final String userName) { - if (userName == null || userName.isEmpty()) { - throw new IllegalArgumentException("null or empty userName"); - } - String userHomeDir = MiscIRODSUtils.computeHomeDirectoryForGivenUserInSameZoneAsIRODSAccount(getIrodsAccount(), - userName); - - log.info("user home dir:{}", userHomeDir); - - if (!userProfileServiceConfiguration.getProfileSubdirName().isEmpty()) { - StringBuilder sb = new StringBuilder(); - sb.append(userHomeDir); - sb.append("/"); - sb.append(userProfileServiceConfiguration.getProfileSubdirName()); - userHomeDir = sb.toString(); - } - - return userHomeDir; - } - - /* - * (non-Javadoc) - * - * @see org.irods.jargon.userprofile.UserProfileService# - * isProtectedReadGroupConfigured() - */ - @Override - public boolean isProtectedReadGroupConfigured() throws JargonException { - log.info("isProtectedReadGroupConfigured()"); - - if (userProfileServiceConfiguration.getProtectedProfileReadWriteGroup() == null - || userProfileServiceConfiguration.getProtectedProfileReadWriteGroup().isEmpty()) { - log.info("no group specified"); - return false; - } - - UserGroupAO userGroupAO = getIrodsAccessObjectFactory().getUserGroupAO(getIrodsAccount()); - UserGroup group = userGroupAO.findByName(userProfileServiceConfiguration.getProtectedProfileReadWriteGroup()); - - if (group == null) { - log.info("user group not found"); - return false; - } else { - log.info("user group found:{}", group); - return true; - } - } - - /** - * Get the file that corresponds to the expected public profile. Note that this - * method does not evaluate whether the file actually exists - * - * @param userName - * @return - * @throws JargonException - */ - private IRODSFile retrieveUserPublicProfileFile(final String userName) throws JargonException { - - String userHomeDir = getUserProfileDir(userName); - - return getIrodsAccessObjectFactory().getIRODSFileFactory(getIrodsAccount()).instanceIRODSFile(userHomeDir, - userProfileServiceConfiguration.getPublicProfileFileName()); - } - -} diff --git a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileValidationException.java b/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileValidationException.java deleted file mode 100644 index 67d419501..000000000 --- a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileValidationException.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * - */ -package org.irods.jargon.userprofile; - -import java.util.ArrayList; -import java.util.List; - -import org.irods.jargon.core.exception.JargonException; - -/** - * Exception in the validation of the {@code UserProfile} - * - * @author Mike Conway - DICE (www.irods.org) - * - */ -public class UserProfileValidationException extends JargonException { - - private static final long serialVersionUID = -1188160240484261453L; - - /** - * Per-field validation messages - */ - private List validationMessages = new ArrayList(); - - /** - * @param message - * @param underlyingIRODSExceptionCode - */ - public UserProfileValidationException(final String message, final int underlyingIRODSExceptionCode) { - super(message, underlyingIRODSExceptionCode); - } - - /** - * @param message - * @param cause - * @param underlyingIRODSExceptionCode - */ - public UserProfileValidationException(final String message, final Throwable cause, - final int underlyingIRODSExceptionCode) { - super(message, cause, underlyingIRODSExceptionCode); - } - - /** - * @param message - * @param cause - */ - public UserProfileValidationException(final String message, final Throwable cause) { - super(message, cause); - } - - /** - * @param message - */ - public UserProfileValidationException(final String message) { - super(message); - } - - /** - * @param cause - * @param underlyingIRODSExceptionCode - */ - public UserProfileValidationException(final Throwable cause, final int underlyingIRODSExceptionCode) { - super(cause, underlyingIRODSExceptionCode); - } - - /** - * @param cause - */ - public UserProfileValidationException(final Throwable cause) { - super(cause); - } - - /** - * @return the validationMessages - */ - public List getValidationMessages() { - return validationMessages; - } - - /** - * @param validationMessages - * the validationMessages to set - */ - public void setValidationMessages(final List validationMessages) { - this.validationMessages = validationMessages; - } - -} diff --git a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileValidatorImpl.java b/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileValidatorImpl.java deleted file mode 100644 index c3c56da20..000000000 --- a/jargon-user-profile/src/main/java/org/irods/jargon/userprofile/UserProfileValidatorImpl.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.irods.jargon.userprofile; - -import org.irods.jargon.core.exception.JargonException; -import org.irods.jargon.core.service.AbstractJargonService; - -/** - * Utility class for validation of {@code UserProfile} - * - * @author Mike Conway - DICE (www.irods.org) - * - */ -public class UserProfileValidatorImpl extends AbstractJargonService { - - public void validateUserProfile(final UserProfile userProfile) - throws UserProfileValidationException, JargonException { - - } - -} diff --git a/jargon-user-profile/src/test/java/org/irods/jargon/userprofile/UserProfileServiceImplTest.java b/jargon-user-profile/src/test/java/org/irods/jargon/userprofile/UserProfileServiceImplTest.java deleted file mode 100644 index aae912c97..000000000 --- a/jargon-user-profile/src/test/java/org/irods/jargon/userprofile/UserProfileServiceImplTest.java +++ /dev/null @@ -1,724 +0,0 @@ -package org.irods.jargon.userprofile; - -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -import org.irods.jargon.core.connection.IRODSAccount; -import org.irods.jargon.core.exception.DataNotFoundException; -import org.irods.jargon.core.exception.DuplicateDataException; -import org.irods.jargon.core.exception.JargonRuntimeException; -import org.irods.jargon.core.protovalues.FilePermissionEnum; -import org.irods.jargon.core.protovalues.UserTypeEnum; -import org.irods.jargon.core.pub.DataObjectAO; -import org.irods.jargon.core.pub.IRODSAccessObjectFactory; -import org.irods.jargon.core.pub.IRODSFileSystem; -import org.irods.jargon.core.pub.UserAO; -import org.irods.jargon.core.pub.domain.User; -import org.irods.jargon.core.pub.io.IRODSFile; -import org.irods.jargon.core.query.AVUQueryElement; -import org.irods.jargon.core.query.AVUQueryElement.AVUQueryPart; -import org.irods.jargon.core.query.MetaDataAndDomainData; -import org.irods.jargon.core.query.QueryConditionOperators; -import org.irods.jargon.testutils.IRODSTestSetupUtilities; -import org.irods.jargon.testutils.TestingPropertiesHelper; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -public class UserProfileServiceImplTest { - - private static Properties testingProperties = new Properties(); - private static TestingPropertiesHelper testingPropertiesHelper = new TestingPropertiesHelper(); - private static IRODSFileSystem irodsFileSystem; - private static final String IRODS_TEST_SUBDIR_PATH = "UserProfileServiceTest"; - private static IRODSTestSetupUtilities irodsTestSetupUtilities = null; - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - TestingPropertiesHelper testingPropertiesLoader = new TestingPropertiesHelper(); - testingProperties = testingPropertiesLoader.getTestProperties(); - irodsTestSetupUtilities = new IRODSTestSetupUtilities(); - irodsTestSetupUtilities.initializeIrodsScratchDirectory(); - irodsTestSetupUtilities.initializeDirectoryForTest(IRODS_TEST_SUBDIR_PATH); - irodsFileSystem = IRODSFileSystem.instance(); - - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - - irodsFileSystem.closeAndEatExceptions(); - - } - - @Test - public final void testUserProfileServiceImpl() throws Exception { - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - new UserProfileServiceImpl(accessObjectFactory, irodsAccount); - } - - @Test(expected = IllegalArgumentException.class) - public final void testUserProfileServiceImplNullAccount() throws Exception { - IRODSAccount irodsAccount = null; - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - new UserProfileServiceImpl(accessObjectFactory, irodsAccount); - } - - @Test(expected = IllegalArgumentException.class) - public final void testUserProfileServiceImplNullAccessObjectFactory() throws Exception { - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = null; - new UserProfileServiceImpl(accessObjectFactory, irodsAccount); - } - - /** - * Test ability to add and remove profile repeatedly - * - * @throws Exception - */ - @Test - public final void testRepeatedlyAddAndRemoveProfileForUser() throws Exception { - - int count = 5; - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAdminAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - String testUser = "testRepeatedlyAddAndRemoveProfileForUser"; - - UserAO userAO = accessObjectFactory.getUserAO(irodsAccount); - - try { - userAO.findByName(testUser); - } catch (DataNotFoundException dnf) { - User newUser = new User(); - newUser.setName(testUser); - newUser.setUserType(UserTypeEnum.RODS_USER); - - userAO.addUser(newUser); - userAO.changeAUserPasswordByAnAdmin(testUser, testUser); - } - - IRODSAccount testUserAccount = testingPropertiesHelper - .buildIRODSAccountForIRODSUserFromTestPropertiesForGivenUser(testingProperties, testUser, testUser); - - UserProfileService userProfileService = new UserProfileServiceImpl(accessObjectFactory, testUserAccount); - - for (int i = 0; i < count; i++) { - - userProfileService.removeProfileInformation(testUser); - - UserProfile userProfile = new UserProfile(); - userProfile.setUserName(testUser); - userProfile.setZone(irodsAccount.getZone()); - - // adjust the config to use the admin uid as the protected profile - // access person - userProfileService.getUserProfileServiceConfiguration() - .setProtectedProfileReadWriteGroup(irodsAccount.getUserName()); - - userProfileService.addProfileForUser(testUser, userProfile); - - // make the files are there with the necessary permissions - - String userHomeDir = userProfileService.getUserProfileDir(testUser); - - IRODSFile userProfileFile = accessObjectFactory.getIRODSFileFactory(testUserAccount).instanceIRODSFile( - userHomeDir, userProfileService.getUserProfileServiceConfiguration().getPublicProfileFileName()); - - Assert.assertTrue("public user profile not created", userProfileFile.exists()); - - IRODSFile protectedProfileFile = accessObjectFactory.getIRODSFileFactory(testUserAccount).instanceIRODSFile( - userHomeDir, userProfileService.getUserProfileServiceConfiguration().getProtectedProfileFileName()); - - Assert.assertTrue("protected user profile not created", protectedProfileFile.exists()); - } - - } - - /** - * Add a profile twice - * - * @throws Exception - */ - @Test(expected = DuplicateDataException.class) - public final void testAddProfileWhenOneExists() throws Exception { - - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAdminAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - String testUser = "testAddProfileWhenOneExists"; - String password = "password"; - - UserAO userAO = accessObjectFactory.getUserAO(irodsAccount); - - try { - userAO.findByName(testUser); - } catch (DataNotFoundException dnf) { - User newUser = new User(); - newUser.setName(testUser); - newUser.setUserType(UserTypeEnum.RODS_USER); - - userAO.addUser(newUser); - userAO.changeAUserPasswordByAnAdmin(testUser, password); - } - - IRODSAccount testUserAccount = testingPropertiesHelper - .buildIRODSAccountForIRODSUserFromTestPropertiesForGivenUser(testingProperties, testUser, password); - - UserProfileService userProfileService = new UserProfileServiceImpl(accessObjectFactory, testUserAccount); - - userProfileService.removeProfileInformation(testUser); - - UserProfile userProfile = new UserProfile(); - userProfile.setUserName(testUser); - userProfile.setZone(irodsAccount.getZone()); - - // adjust the config to use the admin uid as the protected profile - // access person - userProfileService.getUserProfileServiceConfiguration() - .setProtectedProfileReadWriteGroup(irodsAccount.getUserName()); - - userProfileService.addProfileForUser(testUser, userProfile); - userProfileService.addProfileForUser(testUser, userProfile); - } - - @Test - public final void testAddProfileForUser() throws Exception { - - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAdminAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - String testUser = "testAddProfileForUser2"; - - UserAO userAO = accessObjectFactory.getUserAO(irodsAccount); - - try { - userAO.findByName(testUser); - } catch (DataNotFoundException dnf) { - User newUser = new User(); - newUser.setName(testUser); - newUser.setUserType(UserTypeEnum.RODS_USER); - - userAO.addUser(newUser); - userAO.changeAUserPasswordByAnAdmin(testUser, testUser); - } - - IRODSAccount testUserAccount = testingPropertiesHelper - .buildIRODSAccountForIRODSUserFromTestPropertiesForGivenUser(testingProperties, testUser, testUser); - - UserProfileService userProfileService = new UserProfileServiceImpl(accessObjectFactory, testUserAccount); - - userProfileService.removeProfileInformation(testUser); - - UserProfile userProfile = new UserProfile(); - userProfile.setUserName(testUser); - userProfile.setZone(irodsAccount.getZone()); - - String actualNickName = "nickName"; - String actualDescription = "description"; - - userProfile.getUserProfilePublicFields().setDescription(actualDescription); - userProfile.getUserProfilePublicFields().setNickName(actualNickName); - // access person - userProfileService.getUserProfileServiceConfiguration() - .setProtectedProfileReadWriteGroup(irodsAccount.getUserName()); - - userProfileService.addProfileForUser(testUser, userProfile); - - // make the files are there with the necessary permissions - - String userHomeDir = userProfileService.getUserProfileDir(testUser); - - IRODSFile userProfileFile = accessObjectFactory.getIRODSFileFactory(testUserAccount).instanceIRODSFile( - userHomeDir, userProfileService.getUserProfileServiceConfiguration().getPublicProfileFileName()); - - Assert.assertTrue("public user profile not created", userProfileFile.exists()); - - // make sure public can read profile - - DataObjectAO dataObjectAO = accessObjectFactory.getDataObjectAO(irodsAccount); - FilePermissionEnum permissionData = dataObjectAO.getPermissionForDataObject(userProfileFile.getAbsolutePath(), - "public", irodsAccount.getZone()); - - Assert.assertEquals("public should have read permission", FilePermissionEnum.READ, permissionData); - - // admin should have write - - permissionData = dataObjectAO.getPermissionForDataObject(userProfileFile.getAbsolutePath(), - irodsAccount.getUserName(), irodsAccount.getZone()); - - Assert.assertEquals("rods should have write permission", FilePermissionEnum.WRITE, permissionData); - - // inspect data in AVU - - List query = new ArrayList(); - - query.add(AVUQueryElement.instanceForValueQuery(AVUQueryPart.UNITS, QueryConditionOperators.EQUAL, - - UserProfileService.AVU_UNIT_NAMESPACE)); - - List metadata = dataObjectAO - .findMetadataValuesForDataObject(userProfileFile.getAbsolutePath()); - - // check for metadata, other unit tests will look at the details field - // by field - Assert.assertFalse("no metadata found", metadata.isEmpty()); - - IRODSFile protectedProfileFile = accessObjectFactory.getIRODSFileFactory(testUserAccount).instanceIRODSFile( - userHomeDir, userProfileService.getUserProfileServiceConfiguration().getProtectedProfileFileName()); - - Assert.assertTrue("protected user profile not created", protectedProfileFile.exists()); - - } - - @Test - public final void testRetrieveProfileForUser() throws Exception { - - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAdminAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - String testUser = "testRetrieveProfileForUser"; - - UserAO userAO = accessObjectFactory.getUserAO(irodsAccount); - - try { - userAO.findByName(testUser); - } catch (DataNotFoundException dnf) { - User newUser = new User(); - newUser.setName(testUser); - newUser.setUserType(UserTypeEnum.RODS_USER); - - userAO.addUser(newUser); - userAO.changeAUserPasswordByAnAdmin(testUser, testUser); - } - - IRODSAccount testUserAccount = testingPropertiesHelper - .buildIRODSAccountForIRODSUserFromTestPropertiesForGivenUser(testingProperties, testUser, testUser); - - UserProfileService userProfileService = new UserProfileServiceImpl(accessObjectFactory, testUserAccount); - - userProfileService.removeProfileInformation(testUser); - - UserProfile userProfile = new UserProfile(); - userProfile.setUserName(testUser); - userProfile.setZone(irodsAccount.getZone()); - - String actualNickName = "nickName"; - String actualDescription = "description"; - String actualEmail = "emal@something.com"; - - userProfile.getUserProfilePublicFields().setDescription(actualDescription); - userProfile.getUserProfilePublicFields().setNickName(actualNickName); - userProfile.getUserProfileProtectedFields().setMail(actualEmail); - - // access person - userProfileService.getUserProfileServiceConfiguration() - .setProtectedProfileReadWriteGroup(irodsAccount.getUserName()); - - userProfileService.addProfileForUser(testUser, userProfile); - - // now retrive - UserProfile actual = userProfileService.retrieveUserProfile(testUser); - Assert.assertEquals("user name not set", userProfile.getUserName(), actual.getUserName()); - Assert.assertEquals("zone not set", userProfile.getZone(), actual.getZone()); - Assert.assertEquals("nick name not set", userProfile.getUserProfilePublicFields().getNickName(), - actual.getUserProfilePublicFields().getNickName()); - Assert.assertEquals("description not set", userProfile.getUserProfilePublicFields().getDescription(), - actual.getUserProfilePublicFields().getDescription()); - Assert.assertEquals("mail not set", userProfile.getUserProfileProtectedFields().getMail(), - actual.getUserProfileProtectedFields().getMail()); - } - - /** - * Test general operation when a subdir is not defined for the profile info - * - * @throws Exception - */ - @Test - public final void testRetrieveProfileForUserNoSubdir() throws Exception { - - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAdminAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - String testUser = "testRetrieveProfileForUserNoSubdir"; - - UserAO userAO = accessObjectFactory.getUserAO(irodsAccount); - - try { - userAO.findByName(testUser); - } catch (DataNotFoundException dnf) { - User newUser = new User(); - newUser.setName(testUser); - newUser.setUserType(UserTypeEnum.RODS_USER); - - userAO.addUser(newUser); - userAO.changeAUserPasswordByAnAdmin(testUser, testUser); - } - - IRODSAccount testUserAccount = testingPropertiesHelper - .buildIRODSAccountForIRODSUserFromTestPropertiesForGivenUser(testingProperties, testUser, testUser); - - UserProfileService userProfileService = new UserProfileServiceImpl(accessObjectFactory, testUserAccount); - userProfileService.getUserProfileServiceConfiguration().setProfileSubdirName(""); - - userProfileService.removeProfileInformation(testUser); - - UserProfile userProfile = new UserProfile(); - userProfile.setUserName(testUser); - userProfile.setZone(irodsAccount.getZone()); - - String actualNickName = "nickName"; - String actualDescription = "description"; - String actualEmail = "emal@something.com"; - - userProfile.getUserProfilePublicFields().setDescription(actualDescription); - userProfile.getUserProfilePublicFields().setNickName(actualNickName); - userProfile.getUserProfileProtectedFields().setMail(actualEmail); - - // access person - userProfileService.getUserProfileServiceConfiguration() - .setProtectedProfileReadWriteGroup(irodsAccount.getUserName()); - - userProfileService.addProfileForUser(testUser, userProfile); - - // now retrive - UserProfile actual = userProfileService.retrieveUserProfile(testUser); - Assert.assertEquals("user name not set", userProfile.getUserName(), actual.getUserName()); - Assert.assertEquals("zone not set", userProfile.getZone(), actual.getZone()); - Assert.assertEquals("nick name not set", userProfile.getUserProfilePublicFields().getNickName(), - actual.getUserProfilePublicFields().getNickName()); - Assert.assertEquals("description not set", userProfile.getUserProfilePublicFields().getDescription(), - actual.getUserProfilePublicFields().getDescription()); - Assert.assertEquals("mail not set", userProfile.getUserProfileProtectedFields().getMail(), - actual.getUserProfileProtectedFields().getMail()); - } - - @Test(expected = IllegalArgumentException.class) - public final void testRetrieveProfileForUserNullUser() throws Exception { - - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAdminAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - String testUser = "testRetrieveProfileForUserNullUser"; - String password = "password"; - - UserAO userAO = accessObjectFactory.getUserAO(irodsAccount); - - try { - userAO.findByName(testUser); - } catch (DataNotFoundException dnf) { - User newUser = new User(); - newUser.setName(testUser); - newUser.setUserType(UserTypeEnum.RODS_USER); - - userAO.addUser(newUser); - userAO.changeAUserPasswordByAnAdmin(testUser, password); - } - - IRODSAccount testUserAccount = testingPropertiesHelper - .buildIRODSAccountForIRODSUserFromTestPropertiesForGivenUser(testingProperties, testUser, password); - - UserProfileService userProfileService = new UserProfileServiceImpl(accessObjectFactory, testUserAccount); - - // now retrive - userProfileService.retrieveUserProfile(null); - - } - - @Test(expected = IllegalArgumentException.class) - public final void testRetrieveProfileForUserBlankUser() throws Exception { - - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAdminAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - String testUser = "testRetrieveProfileForUserBlankUser"; - String password = "password"; - - UserAO userAO = accessObjectFactory.getUserAO(irodsAccount); - - try { - userAO.findByName(testUser); - } catch (DataNotFoundException dnf) { - User newUser = new User(); - newUser.setName(testUser); - newUser.setUserType(UserTypeEnum.RODS_USER); - - userAO.addUser(newUser); - userAO.changeAUserPasswordByAnAdmin(testUser, password); - } - - IRODSAccount testUserAccount = testingPropertiesHelper - .buildIRODSAccountForIRODSUserFromTestPropertiesForGivenUser(testingProperties, testUser, password); - - UserProfileService userProfileService = new UserProfileServiceImpl(accessObjectFactory, testUserAccount); - - // now retrive - userProfileService.retrieveUserProfile(""); - - } - - @Test - public final void testUpdateProfileForUser() throws Exception { - - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAdminAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - String testUser = "testUpdateProfileForUser"; - String updatedPostFix = "updated"; - - UserAO userAO = accessObjectFactory.getUserAO(irodsAccount); - - try { - userAO.findByName(testUser); - } catch (DataNotFoundException dnf) { - User newUser = new User(); - newUser.setName(testUser); - newUser.setUserType(UserTypeEnum.RODS_USER); - - userAO.addUser(newUser); - userAO.changeAUserPasswordByAnAdmin(testUser, testUser); - } - - IRODSAccount testUserAccount = testingPropertiesHelper - .buildIRODSAccountForIRODSUserFromTestPropertiesForGivenUser(testingProperties, testUser, testUser); - - UserProfileService userProfileService = new UserProfileServiceImpl(accessObjectFactory, testUserAccount); - - userProfileService.removeProfileInformation(testUser); - - UserProfile userProfile = new UserProfile(); - userProfile.setUserName(testUser); - userProfile.setZone(irodsAccount.getZone()); - - String actualNickName = "nickName"; - String actualDescription = "description"; - String actualEmail = "emal@something.com"; - - userProfile.getUserProfilePublicFields().setDescription(actualDescription); - userProfile.getUserProfilePublicFields().setNickName(actualNickName); - userProfile.getUserProfileProtectedFields().setMail(actualEmail); - - // access person - userProfileService.getUserProfileServiceConfiguration() - .setProtectedProfileReadWriteGroup(irodsAccount.getUserName()); - - userProfileService.addProfileForUser(testUser, userProfile); - - // now retrive and update the email and descr - UserProfile beforeUpdate = userProfileService.retrieveUserProfile(testUser); - beforeUpdate.getUserProfileProtectedFields().setMail(actualEmail + updatedPostFix); - beforeUpdate.getUserProfilePublicFields().setDescription(actualDescription + updatedPostFix); - - userProfileService.updateUserProfile(beforeUpdate); - - // retrieve again and check email and description - - UserProfile actual = userProfileService.retrieveUserProfile(testUser); - - Assert.assertEquals("did not update description", actualDescription + updatedPostFix, - actual.getUserProfilePublicFields().getDescription()); - Assert.assertEquals("did not update email", actualEmail + updatedPostFix, - actual.getUserProfileProtectedFields().getMail()); - - } - - /** - * Update a profile on a non-existent user - * - * @throws Exception - */ - @Test(expected = JargonRuntimeException.class) - public final void testUpdateProfileForUserUserNotExists() throws Exception { - - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAdminAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - String testUser = "testUpdateProfileForUserUserNotExists"; - - IRODSAccount testUserAccount = testingPropertiesHelper - .buildIRODSAccountForIRODSUserFromTestPropertiesForGivenUser(testingProperties, testUser, testUser); - - UserProfileService userProfileService = new UserProfileServiceImpl(accessObjectFactory, testUserAccount); - - UserProfile userProfile = new UserProfile(); - userProfile.setUserName(testUser); - userProfile.setZone(irodsAccount.getZone()); - userProfileService.updateUserProfile(userProfile); - - } - - /** - * Update a profile on an existing user who has no profile - * - * @throws Exception - */ - @Test - public final void testUpdateProfileForUserThatExistsButDoesNotHaveAProfile() throws Exception { - - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAdminAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - String testUser = "testUpdateProfileForUserThatExistsButDoesNotHaveAProfile"; - String password = "password"; - - UserAO userAO = accessObjectFactory.getUserAO(irodsAccount); - - try { - userAO.findByName(testUser); - } catch (DataNotFoundException dnf) { - User newUser = new User(); - newUser.setName(testUser); - newUser.setUserType(UserTypeEnum.RODS_USER); - - userAO.addUser(newUser); - userAO.changeAUserPasswordByAnAdmin(testUser, password); - } - - IRODSAccount testUserAccount = testingPropertiesHelper - .buildIRODSAccountForIRODSUserFromTestPropertiesForGivenUser(testingProperties, testUser, password); - - UserProfileService userProfileService = new UserProfileServiceImpl(accessObjectFactory, testUserAccount); - - userProfileService.removeProfileInformation(testUser); - - UserProfile userProfile = new UserProfile(); - userProfile.setUserName(testUser); - userProfile.setZone(irodsAccount.getZone()); - - String actualNickName = "nickName"; - String actualDescription = "description"; - String actualEmail = "emal@something.com"; - - userProfile.getUserProfilePublicFields().setDescription(actualDescription); - userProfile.getUserProfilePublicFields().setNickName(actualNickName); - userProfile.getUserProfileProtectedFields().setMail(actualEmail); - - // access person - userProfileService.getUserProfileServiceConfiguration() - .setProtectedProfileReadWriteGroup(irodsAccount.getUserName()); - - userProfileService.updateUserProfile(userProfile); - UserProfile actual = userProfileService.retrieveUserProfile(testUser); - // really should just not get a data not found error, should really add, - // the test below is a formality - Assert.assertNotNull("profile was null", actual); - } - - @Test(expected = IllegalArgumentException.class) - public final void testUpdateProfileForNullUserProfile() throws Exception { - - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAdminAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - String testUser = "testUpdateProfileForNullUserProfile"; - String password = "password"; - UserAO userAO = accessObjectFactory.getUserAO(irodsAccount); - - try { - userAO.findByName(testUser); - } catch (DataNotFoundException dnf) { - User newUser = new User(); - newUser.setName(testUser); - newUser.setUserType(UserTypeEnum.RODS_USER); - - userAO.addUser(newUser); - userAO.changeAUserPasswordByAnAdmin(testUser, password); - } - - IRODSAccount testUserAccount = testingPropertiesHelper - .buildIRODSAccountForIRODSUserFromTestPropertiesForGivenUser(testingProperties, testUser, password); - - UserProfileService userProfileService = new UserProfileServiceImpl(accessObjectFactory, testUserAccount); - - UserProfile userProfile = null; - userProfileService.updateUserProfile(userProfile); - - } - - @Test - public final void testRetrieveProfileForUserAllPublicFieldsTested() throws Exception { - - IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAdminAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - String testUser = "AllPublicFieldsTested"; - - UserAO userAO = accessObjectFactory.getUserAO(irodsAccount); - - try { - userAO.findByName(testUser); - } catch (DataNotFoundException dnf) { - User newUser = new User(); - newUser.setName(testUser); - newUser.setUserType(UserTypeEnum.RODS_USER); - - userAO.addUser(newUser); - userAO.changeAUserPasswordByAnAdmin(testUser, testUser); - } - - IRODSAccount testUserAccount = testingPropertiesHelper - .buildIRODSAccountForIRODSUserFromTestPropertiesForGivenUser(testingProperties, testUser, testUser); - - UserProfileService userProfileService = new UserProfileServiceImpl(accessObjectFactory, testUserAccount); - - userProfileService.removeProfileInformation(testUser); - - UserProfile userProfile = new UserProfile(); - userProfile.setUserName(testUser); - userProfile.setZone(irodsAccount.getZone()); - - String actualNickName = "nickName"; - String actualDescription = "description"; - String actualEmail = "emal@something.com"; - - userProfile.getUserProfilePublicFields().setDescription(actualDescription); - userProfile.getUserProfilePublicFields().setNickName(actualNickName); - userProfile.getUserProfileProtectedFields().setMail(actualEmail); - userProfile.getUserProfilePublicFields().setCn(UserProfileConstants.CN); - userProfile.getUserProfilePublicFields().setGivenName(UserProfileConstants.GIVEN_NAME); - userProfile.getUserProfilePublicFields().setJpegPhoto(UserProfileConstants.JPEG_PHOTO); - userProfile.getUserProfilePublicFields().setLabeledURL(UserProfileConstants.LABELED_URL); - userProfile.getUserProfilePublicFields().setLocalityName(UserProfileConstants.LOCALITY_NAME); - userProfile.getUserProfilePublicFields().setPostalAddress(UserProfileConstants.POSTAL_ADDRESS); - userProfile.getUserProfilePublicFields().setPostalCode(UserProfileConstants.POSTAL_CODE); - userProfile.getUserProfilePublicFields().setPostOfficeBox(UserProfileConstants.POST_OFFICE_BOX); - userProfile.getUserProfilePublicFields().setSn(UserProfileConstants.SN); - userProfile.getUserProfilePublicFields().setSt(UserProfileConstants.STATE); - userProfile.getUserProfilePublicFields().setStreet(UserProfileConstants.STREET); - userProfile.getUserProfilePublicFields().setTelephoneNumber(UserProfileConstants.TELEPHONE_NUMBER); - userProfile.getUserProfilePublicFields().setTitle(UserProfileConstants.TITLE); - - // access person - userProfileService.getUserProfileServiceConfiguration() - .setProtectedProfileReadWriteGroup(irodsAccount.getUserName()); - - userProfileService.addProfileForUser(testUser, userProfile); - - // now retrive - UserProfile actual = userProfileService.retrieveUserProfile(testUser); - Assert.assertEquals("user name not set", userProfile.getUserName(), actual.getUserName()); - Assert.assertEquals("zone not set", userProfile.getZone(), actual.getZone()); - Assert.assertEquals("nick name not set", userProfile.getUserProfilePublicFields().getNickName(), - actual.getUserProfilePublicFields().getNickName()); - Assert.assertEquals("description not set", userProfile.getUserProfilePublicFields().getDescription(), - actual.getUserProfilePublicFields().getDescription()); - Assert.assertEquals("mail not set", userProfile.getUserProfileProtectedFields().getMail(), - actual.getUserProfileProtectedFields().getMail()); - - Assert.assertEquals("cn not set", UserProfileConstants.CN, actual.getUserProfilePublicFields().getCn()); - Assert.assertEquals("GIVEN_NAME not set", UserProfileConstants.GIVEN_NAME, - actual.getUserProfilePublicFields().getGivenName()); - Assert.assertEquals("JPEG_PHOTO not set", UserProfileConstants.JPEG_PHOTO, - actual.getUserProfilePublicFields().getJpegPhoto()); - Assert.assertEquals("LABELED_URL not set", UserProfileConstants.LABELED_URL, - actual.getUserProfilePublicFields().getLabeledURL()); - Assert.assertEquals("LOCALITY_NAME not set", UserProfileConstants.LOCALITY_NAME, - actual.getUserProfilePublicFields().getLocalityName()); - Assert.assertEquals("POSTAL_ADDRESS not set", UserProfileConstants.POSTAL_ADDRESS, - actual.getUserProfilePublicFields().getPostalAddress()); - Assert.assertEquals("POSTAL_CODE not set", UserProfileConstants.POSTAL_CODE, - actual.getUserProfilePublicFields().getPostalCode()); - Assert.assertEquals("POST_OFFICE_BOX not set", UserProfileConstants.POST_OFFICE_BOX, - actual.getUserProfilePublicFields().getPostOfficeBox()); - Assert.assertEquals("SN not set", UserProfileConstants.SN, actual.getUserProfilePublicFields().getSn()); - Assert.assertEquals("STREET not set", UserProfileConstants.STREET, - actual.getUserProfilePublicFields().getStreet()); - Assert.assertEquals("STATE not set", UserProfileConstants.STATE, actual.getUserProfilePublicFields().getSt()); - Assert.assertEquals("TELEPHONE_NUMBER not set", UserProfileConstants.TELEPHONE_NUMBER, - actual.getUserProfilePublicFields().getTelephoneNumber()); - Assert.assertEquals("TITLE not set", UserProfileConstants.TITLE, - actual.getUserProfilePublicFields().getTitle()); - } - -} diff --git a/jargon-user-profile/src/test/java/org/irods/jargon/userprofile/unittest/AllTests.java b/jargon-user-profile/src/test/java/org/irods/jargon/userprofile/unittest/AllTests.java deleted file mode 100644 index 5282d4205..000000000 --- a/jargon-user-profile/src/test/java/org/irods/jargon/userprofile/unittest/AllTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.irods.jargon.userprofile.unittest; - -import org.irods.jargon.userprofile.UserProfileServiceImplTest; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ UserProfileServiceImplTest.class }) -/** - * Suite to run all tests (except long running and functional), further refined - * by settings in testing.properites. Some subtests may be shut off by these - * properties. - */ -public class AllTests { - -} diff --git a/jargon-user-profile/src/test/java/org/irods/jargon/userprofile/unittest/package-info.java b/jargon-user-profile/src/test/java/org/irods/jargon/userprofile/unittest/package-info.java deleted file mode 100644 index 15eac9498..000000000 --- a/jargon-user-profile/src/test/java/org/irods/jargon/userprofile/unittest/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Unit test helpers and suites - * - * @author Mike Conway - DICE (www.irods.org) see http://code.renci.org for - * trackers, access info, and documentation - * - */ -package org.irods.jargon.userprofile.unittest; \ No newline at end of file diff --git a/jargon-user-profile/src/test/resources/log4j.properties b/jargon-user-profile/src/test/resources/log4j.properties deleted file mode 100644 index 569118f29..000000000 --- a/jargon-user-profile/src/test/resources/log4j.properties +++ /dev/null @@ -1,10 +0,0 @@ -# Set root logger level to DEBUG and its only appender to A1. -log4j.rootLogger=DEBUG, A1 -log4j.category.org.irods.jargon.core=INFO - -# A1 is set to be a ConsoleAppender. -log4j.appender.A1=org.apache.log4j.ConsoleAppender - -# A1 uses PatternLayout. -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n diff --git a/pom.xml b/pom.xml index 885f80277..7d245bb90 100644 --- a/pom.xml +++ b/pom.xml @@ -226,7 +226,6 @@ jargon-data-utils jargon-ticket jargon-pool - jargon-user-profile jargon-ruleservice data-profile jargon-zipservice