Added methods:

- isPasswordChanged;
- userExistsByMail;
- createUser (new version with more parameters)

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/vo-management/usermanagement-core@125584 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-03-17 11:20:52 +00:00
parent f76d63bc89
commit 5a6d648905
2 changed files with 289 additions and 189 deletions

View File

@ -20,188 +20,218 @@ import org.gcube.vomanagement.usermanagement.model.MembershipRequestStatus;
* @author Massimiliano Assante, CNR-ISTI
*
*/
public interface UserManager {
/**
* @param autoScreenName set true if you want liferay to auto generate a screename for this user, false otherwise
* @param username the username of the user you want
* @param email a valid email address
* @param firstName
* @param middleName
* @param lastName
* @param jobTitle
* @param backgroundSummary
* @param male
* @return an instance of the yet created user
* @throws UserManagementSystemException
*/
GCubeUser createUser(boolean autoScreenName, String username, String email, String firstName, String middleName, String lastName, String jobTitle, String backgroundSummary, boolean male, String reminderQuestion, String reminderAnswer) throws UserManagementSystemException;
/**
*
* @param username the username of the user you want to get
* @return the instance of the user
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
GCubeUser getUserByUsername(String username) throws UserManagementSystemException, UserRetrievalFault;
/**
* @deprecated use getUserByUsername
* @param username
* @return
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
@Deprecated
GCubeUser getUserByScreenName(String username) throws UserManagementSystemException, UserRetrievalFault;
/**
*
* @param username the email of the user you want to get
* @return the instance of the user
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
GCubeUser getUserByEmail(String email) throws UserManagementSystemException, UserRetrievalFault;
/**
*
* @param userId the LR UserId
* @return the instance of the user
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
GCubeUser getUserById(long userId) throws UserManagementSystemException, UserRetrievalFault;
/**
*
* @param username the LR screenname
* @return the LR userId associated to this screenname
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
long getUserId(String username) throws UserManagementSystemException, UserRetrievalFault;
/**
*
* @return a list of all portal active users no matter if the belong or not to a VRE, if a user is deactived is not returned
* @throws UserManagementSystemException
*/
List<GCubeUser> listUsers() throws UserManagementSystemException;
/**
*
* @param groupId the LR groupId
* @return
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
*/
List<GCubeUser> listUsersByGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
*
* @param the name of the VO or VRE (e.g. devVRE, or gcube etc.)
* @return
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
*/
List<GCubeUser> listUsersByGroupName(String name) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
*
* @param groupId the LR groupId
* @return the list of {@link GCubeMembershipRequest} with their status and users given the LR GroupId (status can be requested, approved or rejected, @see {@link MembershipRequestStatus}
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
*/
List<GCubeMembershipRequest> listMembershipRequestsByGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
*
* @param requestId
* @return an istance of {@link GCubeMembershipRequest}
*/
GCubeMembershipRequest getMembershipRequestsById(long membershipRequestId);
/**
*
* @param userId the LR userid
* @param groupId the LR groupId the
* @param status an istance of {@link MembershipRequestStatus}
* @return the list of {@link GCubeMembershipRequest} with their status and users given the LR GroupId and userId (status can be requested, approved or rejected, @see {@link MembershipRequestStatus}
*/
List<GCubeMembershipRequest> getMembershipRequests(long userId, long groupId, MembershipRequestStatus status) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
* request the membership to a restricted Site, no further actions are performed (no emails are sent, nor notifications)
* @param userId the LR userid
* @param groupId the LR groupId the
* @param comment a comment to the request must not be null
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
*/
GCubeMembershipRequest requestMembership(long userId, long groupId, String comment) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
* accept a membership request and optionally add the user to the group
* @param requestUserId the LR userid of the request
* @param groupId the LR groupId
* @param addUserToGroup if you want it to also add the user to the group
* @param String the username (screenname) of the user accepting the request
* @param replyComment a comment attachd to the reply (must not be null)
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserManagementPortalException
*/
GCubeMembershipRequest acceptMembershipRequest(long requestUserId,long groupId, boolean addUserToGroup, String replyUsername, String replyComment) throws UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException;
/**
* rejects a membership request
* @param requestUserId the LR userid of the request
* @param groupId the LR groupId
* @param String the username (screenname) of the user accepting the request
* @param replyComment a comment attachd to the reply (must not be null)
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserManagementPortalException
*/
GCubeMembershipRequest rejectMembershipRequest(long userId, long groupId, String replyUsername, String replyComment) throws UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException;
/**
*
* @param groupId the LR groupId
* @return the list of {@link GCubeUser} with their GCubeRole given the LR GroupId
* @throws GroupRetrievalFault
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
Map<GCubeUser, List<GCubeRole>> listUsersAndRolesByGroup(long groupId) throws GroupRetrievalFault, UserManagementSystemException, UserRetrievalFault ;
/**
*
* @param groupId the LR groupId
* @parmam roleId the LR roleId
* @return the list of {@link GCubeUser} having group and role that matches
* @throws GroupRetrievalFault
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
List<GCubeUser> listUsersByGroupAndRole(long groupId, long roleId) throws UserManagementSystemException, RoleRetrievalFault, GroupRetrievalFault, UserRetrievalFault;
/**
* this method assigns the user to the Group and perform other necessary actions (such as adding him to the HL Folder)
* @param groupId LR groupId
* @param userId LR userId
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
* @throws UserManagementPortalException
*/
void assignUserToGroup(long groupId, long userId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault, UserManagementPortalException;
/**
* this method removes the user to the Group and perform other necessary actions (such as removing him from the HL Folder)
* @param groupId LR groupId
* @param userId LR userId
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
* @throws UserManagementPortalException
*/
void dismissUserFromGroup(long groupId, long userId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
*
* @param groupId LR groupId
* @return all the users of the portal not belonging to the groupId
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
*/
List<GCubeUser> listUnregisteredUsersByGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
public interface UserManager {
/**
* Create the user without sending notification mail.
* @param autoScreenName set true if you want liferay to auto generate a screename for this user, false otherwise
* @param username the username of the user you want
* @param email a valid email address
* @param firstName
* @param middleName
* @param lastName
* @param jobTitle
* @param backgroundSummary
* @param male
* @return an instance of the yet created user
* @throws UserManagementSystemException
*/
GCubeUser createUser(boolean autoScreenName, String username, String email, String firstName, String middleName, String lastName, String jobTitle, String backgroundSummary, boolean male, String reminderQuestion, String reminderAnswer) throws UserManagementSystemException;
/**
* Create the user and let you choose if you want to send him/her a mail notification.
* @param autoScreenName set true if you want liferay to auto generate a screename for this user, false otherwise
* @param username the username of the user you want
* @param email a valid email address
* @param firstName
* @param middleName
* @param lastName
* @param jobTitle
* @param backgroundSummary
* @param male
* @return an instance of the yet created user
* @throws UserManagementSystemException
*/
GCubeUser createUser(boolean autoScreenName, String username, String email, String firstName, String middleName, String lastName, String jobTitle, String backgroundSummary, boolean male, String reminderQuestion, String reminderAnswer, boolean sendEmail) throws UserManagementSystemException;
/**
*
* @param username the username of the user you want to get
* @return the instance of the user
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
GCubeUser getUserByUsername(String username) throws UserManagementSystemException, UserRetrievalFault;
/**
* @deprecated use getUserByUsername
* @param username
* @return
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
@Deprecated
GCubeUser getUserByScreenName(String username) throws UserManagementSystemException, UserRetrievalFault;
/**
*
* @param username the email of the user you want to get
* @return the instance of the user
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
GCubeUser getUserByEmail(String email) throws UserManagementSystemException, UserRetrievalFault;
/**
*
* @param userId the LR UserId
* @return the instance of the user
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
GCubeUser getUserById(long userId) throws UserManagementSystemException, UserRetrievalFault;
/**
*
* @param username the LR screenname
* @return the LR userId associated to this screenname
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
long getUserId(String username) throws UserManagementSystemException, UserRetrievalFault;
/**
*
* @return a list of all portal active users no matter if the belong or not to a VRE, if a user is deactived is not returned
* @throws UserManagementSystemException
*/
List<GCubeUser> listUsers() throws UserManagementSystemException;
/**
*
* @param groupId the LR groupId
* @return
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
*/
List<GCubeUser> listUsersByGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
*
* @param the name of the VO or VRE (e.g. devVRE, or gcube etc.)
* @return
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
*/
List<GCubeUser> listUsersByGroupName(String name) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
*
* @param groupId the LR groupId
* @return the list of {@link GCubeMembershipRequest} with their status and users given the LR GroupId (status can be requested, approved or rejected, @see {@link MembershipRequestStatus}
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
*/
List<GCubeMembershipRequest> listMembershipRequestsByGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
*
* @param requestId
* @return an istance of {@link GCubeMembershipRequest}
*/
GCubeMembershipRequest getMembershipRequestsById(long membershipRequestId);
/**
*
* @param userId the LR userid
* @param groupId the LR groupId the
* @param status an istance of {@link MembershipRequestStatus}
* @return the list of {@link GCubeMembershipRequest} with their status and users given the LR GroupId and userId (status can be requested, approved or rejected, @see {@link MembershipRequestStatus}
*/
List<GCubeMembershipRequest> getMembershipRequests(long userId, long groupId, MembershipRequestStatus status) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
* request the membership to a restricted Site, no further actions are performed (no emails are sent, nor notifications)
* @param userId the LR userid
* @param groupId the LR groupId the
* @param comment a comment to the request must not be null
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
*/
GCubeMembershipRequest requestMembership(long userId, long groupId, String comment) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
* accept a membership request and optionally add the user to the group
* @param requestUserId the LR userid of the request
* @param groupId the LR groupId
* @param addUserToGroup if you want it to also add the user to the group
* @param String the username (screenname) of the user accepting the request
* @param replyComment a comment attachd to the reply (must not be null)
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserManagementPortalException
*/
GCubeMembershipRequest acceptMembershipRequest(long requestUserId,long groupId, boolean addUserToGroup, String replyUsername, String replyComment) throws UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException;
/**
* rejects a membership request
* @param requestUserId the LR userid of the request
* @param groupId the LR groupId
* @param String the username (screenname) of the user accepting the request
* @param replyComment a comment attachd to the reply (must not be null)
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserManagementPortalException
*/
GCubeMembershipRequest rejectMembershipRequest(long userId, long groupId, String replyUsername, String replyComment) throws UserManagementSystemException, GroupRetrievalFault, UserManagementPortalException;
/**
*
* @param groupId the LR groupId
* @return the list of {@link GCubeUser} with their GCubeRole given the LR GroupId
* @throws GroupRetrievalFault
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
Map<GCubeUser, List<GCubeRole>> listUsersAndRolesByGroup(long groupId) throws GroupRetrievalFault, UserManagementSystemException, UserRetrievalFault ;
/**
*
* @param groupId the LR groupId
* @parmam roleId the LR roleId
* @return the list of {@link GCubeUser} having group and role that matches
* @throws GroupRetrievalFault
* @throws UserManagementSystemException
* @throws UserRetrievalFault
*/
List<GCubeUser> listUsersByGroupAndRole(long groupId, long roleId) throws UserManagementSystemException, RoleRetrievalFault, GroupRetrievalFault, UserRetrievalFault;
/**
* this method assigns the user to the Group and perform other necessary actions (such as adding him to the HL Folder)
* @param groupId LR groupId
* @param userId LR userId
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
* @throws UserManagementPortalException
*/
void assignUserToGroup(long groupId, long userId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault, UserManagementPortalException;
/**
* this method removes the user to the Group and perform other necessary actions (such as removing him from the HL Folder)
* @param groupId LR groupId
* @param userId LR userId
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
* @throws UserManagementPortalException
*/
void dismissUserFromGroup(long groupId, long userId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
*
* @param groupId LR groupId
* @return all the users of the portal not belonging to the groupId
* @throws UserManagementSystemException
* @throws GroupRetrievalFault
* @throws UserRetrievalFault
*/
List<GCubeUser> listUnregisteredUsersByGroup(long groupId) throws UserManagementSystemException, GroupRetrievalFault, UserRetrievalFault;
/**
* Check if the user changed his/her password from the initial one.
* @param email the email of the user to consider
* @return true if the password has been changed, false if it has been not or the user doesn't exist.
*/
boolean isPasswordChanged(String email);
/**
* Check if a user with such email exists.
* @param email
* @return true on success, false otherwise
*/
public boolean userExistsByEmail(String email);
}

View File

@ -140,11 +140,50 @@ public class LiferayUserManager implements UserManager {
requestStatus);
return toReturn;
}
/**
* {@inheritDoc}
*/
@Override
public GCubeUser createUser(boolean autoScreenName, String username, String email, String firstName, String middleName, String lastName, String jobTitle, String backgroundSummary, boolean male, String reminderQuestion, String reminderAnswer) throws UserManagementSystemException {
return createUserBody(
autoScreenName,
username,
email,
firstName,
middleName,
lastName,
jobTitle,
backgroundSummary,
male,
reminderQuestion,
reminderAnswer,
false);
}
@Override
public GCubeUser createUser(boolean autoScreenName, String username,
String email, String firstName, String middleName, String lastName,
String jobTitle, String backgroundSummary, boolean male,
String reminderQuestion, String reminderAnswer, boolean sendEmail)
throws UserManagementSystemException {
return createUserBody(
autoScreenName,
username,
email,
firstName,
middleName,
lastName,
jobTitle,
backgroundSummary,
male,
reminderQuestion,
reminderAnswer,
sendEmail);
}
private GCubeUser createUserBody(boolean autoScreenName, String username,
String email, String firstName, String middleName, String lastName,
String jobTitle, String backgroundSummary, boolean male,
String reminderQuestion, String reminderAnswer, boolean sendEmail){
GCubeUser toReturn = null;
try {
_log.debug("Trying createuser " + email);
@ -158,7 +197,6 @@ public class LiferayUserManager implements UserManager {
int birthdayMonth = 1;
int birthdayDay = 1;
int birthdayYear = 1970;
boolean sendEmail = false;
String password1 = "training1";
String password2 = password1;
User added = UserLocalServiceUtil.addUser(
@ -187,7 +225,7 @@ public class LiferayUserManager implements UserManager {
null,
null,
null,
sendEmail,
sendEmail,
new ServiceContext());
added.setComments(backgroundSummary);
UserLocalServiceUtil.updateUser(added);
@ -208,7 +246,9 @@ public class LiferayUserManager implements UserManager {
e.printStackTrace();
}
return toReturn;
}
/**
* {@inheritDoc}
*/
@ -593,5 +633,35 @@ public class LiferayUserManager implements UserManager {
List<GCubeUser> toProcess = listUsers();
toProcess.removeAll(listUsersByGroup(groupId));
return toProcess;
}
@Override
public boolean isPasswordChanged(String emailAddress) {
_log.debug("Trying to fetch user by email = " + emailAddress);
User user;
try {
user = UserLocalServiceUtil.getUserByEmailAddress(ManagementUtils.getCompany().getCompanyId(), emailAddress);
// date are saved according GMT
long creationTime = user.getCreateDate().getTime();
long changedTime = user.getPasswordModifiedDate().getTime();
return changedTime > creationTime;
} catch (Exception e) {
_log.error("Error while retrieving user with mail=" + emailAddress, e);
}
return false;
}
@Override
public boolean userExistsByEmail(String emailAddress) {
try {
if(UserLocalServiceUtil.getUserByEmailAddress(ManagementUtils.getCompany().getCompanyId(), emailAddress) != null)
return true;
} catch (Exception e){
_log.error("Error while retrieving user with mail=" + emailAddress, e);
}
return false;
}
}