|
|
|
@ -8,13 +8,14 @@ import java.sql.Timestamp;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
|
import org.gcube.portal.mailing.message.Recipient;
|
|
|
|
|
import org.gcube.portal.mailing.service.EmailTemplateService;
|
|
|
|
|
import org.gcube.portal.mailing.templates.TemplateWelcomeCreatedAccount;
|
|
|
|
|
import org.gcube.portlets.admin.createusers.client.HandleUsersService;
|
|
|
|
|
import org.gcube.portlets.admin.createusers.orchestrator.CreateUserAddToVre;
|
|
|
|
|
import org.gcube.portlets.admin.createusers.orchestrator.CreateUserAddToVrePublisher;
|
|
|
|
|
import org.gcube.portlets.admin.createusers.shared.VreUserBean;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException;
|
|
|
|
@ -33,11 +34,10 @@ import com.liferay.portal.kernel.exception.SystemException;
|
|
|
|
|
import com.liferay.portal.kernel.util.GetterUtil;
|
|
|
|
|
import com.liferay.portal.kernel.util.PropsUtil;
|
|
|
|
|
import com.liferay.portal.model.Company;
|
|
|
|
|
import com.liferay.portal.model.User;
|
|
|
|
|
import com.liferay.portal.model.Group;
|
|
|
|
|
import com.liferay.portal.service.CompanyLocalServiceUtil;
|
|
|
|
|
import com.liferay.portal.service.ServiceContext;
|
|
|
|
|
import com.liferay.portal.service.GroupLocalServiceUtil;
|
|
|
|
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
|
|
|
|
import com.liferay.portal.util.PortalUtil;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The server side implementation of the RPC service.
|
|
|
|
@ -48,6 +48,8 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
|
|
|
|
|
private final static Logger logger = LoggerFactory.getLogger(CreateUsersImpl.class);
|
|
|
|
|
private static final long serialVersionUID = -3124676000683430170L;
|
|
|
|
|
private static final String REGISTERED_USERS_TABLE = "registered_users";
|
|
|
|
|
private static final String INITIAL_PWD = "training1";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SQL TABLE FIELDS
|
|
|
|
|
private static final String FIELD_EMAIL = "email";
|
|
|
|
@ -233,15 +235,16 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
|
|
|
|
|
int res = statement.executeUpdate();
|
|
|
|
|
if(res != 0){
|
|
|
|
|
logger.debug("User added in " + REGISTERED_USERS_TABLE);
|
|
|
|
|
// add in liferay too
|
|
|
|
|
// add in Keycloak too
|
|
|
|
|
try{
|
|
|
|
|
User user = register(name, surname, email, institution, sendEmail);
|
|
|
|
|
// adding to the current VRE
|
|
|
|
|
long userId = userManager.getUserId(user.getScreenName());
|
|
|
|
|
userManager.assignUserToGroup(getCurrentGroupID(), userId);
|
|
|
|
|
logger.debug("trying to send the event to create the account for this user to the orchestrator");
|
|
|
|
|
long currGroupId = pContext.getCurrentGroupId(getThreadLocalRequest());
|
|
|
|
|
Group theVRE = GroupLocalServiceUtil.getGroup(currGroupId);
|
|
|
|
|
|
|
|
|
|
new CreateUserAddToVrePublisher().publish(
|
|
|
|
|
CreateUserAddToVre.newEvent(name, surname, email, INITIAL_PWD, theVRE));
|
|
|
|
|
if (sendEmail)
|
|
|
|
|
sendEmailToUser(email);
|
|
|
|
|
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
|
|
|
|
|
// unable to create.. we need to delete it from the list of users
|
|
|
|
@ -273,74 +276,7 @@ public class CreateUsersImpl extends RemoteServiceServlet implements HandleUsers
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private User register(String firstName, String lastName, String email, String institution, boolean sendEmail) {
|
|
|
|
|
User toReturn = null;
|
|
|
|
|
try{
|
|
|
|
|
logger.debug("Trying createuser and instatiate serviceContext" + email);
|
|
|
|
|
Long defaultCompanyId = PortalUtil.getDefaultCompanyId();
|
|
|
|
|
Long defaultUserId = UserLocalServiceUtil.getDefaultUserId(defaultCompanyId);
|
|
|
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
|
|
|
//ServiceContext instanciated as follows is needed when the Email verification is sent
|
|
|
|
|
ServiceContext serviceContext = new ServiceContext();
|
|
|
|
|
serviceContext.setScopeGroupId(pContext.getCurrentGroupId(getThreadLocalRequest()));
|
|
|
|
|
serviceContext.setPortalURL(pContext.getGatewayURL(getThreadLocalRequest()));
|
|
|
|
|
serviceContext.setPathMain("/c");
|
|
|
|
|
|
|
|
|
|
boolean autoPassword = false;
|
|
|
|
|
Locale locale = new Locale("en_US");
|
|
|
|
|
int prefixId = 0;
|
|
|
|
|
int suffixId = 0;
|
|
|
|
|
int birthdayMonth = 1;
|
|
|
|
|
int birthdayDay = 1;
|
|
|
|
|
int birthdayYear = 1970;
|
|
|
|
|
String password1 = "training1";
|
|
|
|
|
String password2 = password1;
|
|
|
|
|
toReturn = UserLocalServiceUtil.addUser(
|
|
|
|
|
defaultUserId,
|
|
|
|
|
defaultCompanyId,
|
|
|
|
|
autoPassword,
|
|
|
|
|
password1,
|
|
|
|
|
password2,
|
|
|
|
|
true,
|
|
|
|
|
"",
|
|
|
|
|
email,
|
|
|
|
|
0L,
|
|
|
|
|
"",
|
|
|
|
|
locale,
|
|
|
|
|
firstName,
|
|
|
|
|
"",
|
|
|
|
|
lastName,
|
|
|
|
|
prefixId,
|
|
|
|
|
suffixId,
|
|
|
|
|
true,
|
|
|
|
|
birthdayMonth,
|
|
|
|
|
birthdayDay,
|
|
|
|
|
birthdayYear,
|
|
|
|
|
institution,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
null,
|
|
|
|
|
false,
|
|
|
|
|
serviceContext);
|
|
|
|
|
logger.debug("CreateUser " + lastName + " SUCCESS");
|
|
|
|
|
UserLocalServiceUtil.updateEmailAddressVerified(toReturn.getUserId(), true);
|
|
|
|
|
UserLocalServiceUtil.updateAgreedToTermsOfUse(toReturn.getUserId(), false);
|
|
|
|
|
UserLocalServiceUtil.updatePasswordReset(toReturn.getUserId(), true);
|
|
|
|
|
UserLocalServiceUtil.updateReminderQuery(toReturn.getUserId(), "What was your initial password?", "training1");
|
|
|
|
|
logger.debug("User " + lastName + " has agreed to ToU");
|
|
|
|
|
logger.debug("User " + lastName + " has verified the Email");
|
|
|
|
|
logger.debug("User " + lastName + " updatePasswordReset & updateReminderQuery");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e){
|
|
|
|
|
// unable to create.. we need to delete it from the list of users
|
|
|
|
|
logger.error("Unable to create the user " + email + " in liferay.", e);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return toReturn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<VreUserBean> getAlreadyRegisterdUsers() {
|
|
|
|
|