protected static ExportImportConfiguration buildDefaultRemotePublishingExportImportConfiguration( User user, long sourceGroupId, boolean privateLayout, String remoteAddress, int remotePort, String remotePathContext, boolean secureConnection, long remoteGroupId, Map<String, String[]> parameterMap) throws PortalException { Map<String, Serializable> publishLayoutRemoteSettingsMap = ExportImportConfigurationSettingsMapFactory.buildPublishLayoutRemoteSettingsMap( user.getUserId(), sourceGroupId, privateLayout, ExportImportHelperUtil.getAllLayoutIdsMap(sourceGroupId, privateLayout), parameterMap, remoteAddress, remotePort, remotePathContext, secureConnection, remoteGroupId, privateLayout, user.getLocale(), user.getTimeZone()); return ExportImportConfigurationLocalServiceUtil.addDraftExportImportConfiguration( user.getUserId(), ExportImportConfigurationConstants.TYPE_PUBLISH_LAYOUT_REMOTE, publishLayoutRemoteSettingsMap); }
protected File[] exportLayouts(long userGroupId, Map<String, String[]> parameterMap) throws PortalException { File[] files = new File[2]; UserGroup userGroup = userGroupPersistence.findByPrimaryKey(userGroupId); User user = userLocalService.getUser(GetterUtil.getLong(PrincipalThreadLocal.getName())); Group group = userGroup.getGroup(); if (userGroup.hasPrivateLayouts()) { Map<String, Serializable> exportLayoutSettingsMap = ExportImportConfigurationSettingsMapFactory.buildExportLayoutSettingsMap( user, group.getGroupId(), true, ExportImportHelperUtil.getAllLayoutIds(group.getGroupId(), true), parameterMap); ExportImportConfiguration exportImportConfiguration = exportImportConfigurationLocalService.addDraftExportImportConfiguration( user.getUserId(), ExportImportConfigurationConstants.TYPE_EXPORT_LAYOUT, exportLayoutSettingsMap); files[0] = exportImportLocalService.exportLayoutsAsFile(exportImportConfiguration); } if (userGroup.hasPublicLayouts()) { Map<String, Serializable> exportLayoutSettingsMap = ExportImportConfigurationSettingsMapFactory.buildExportLayoutSettingsMap( user, group.getGroupId(), false, ExportImportHelperUtil.getAllLayoutIds(group.getGroupId(), false), parameterMap); ExportImportConfiguration exportImportConfiguration = exportImportConfigurationLocalService.addDraftExportImportConfiguration( user.getUserId(), ExportImportConfigurationConstants.TYPE_EXPORT_LAYOUT, exportLayoutSettingsMap); files[1] = exportImportLocalService.exportLayoutsAsFile(exportImportConfiguration); } return files; }
@Override public KaleoDefinition addKaleoDefinition( String name, String title, String description, String content, int version, ServiceContext serviceContext) throws PortalException { User user = userPersistence.findByPrimaryKey(serviceContext.getGuestOrUserId()); Date now = new Date(); long kaleoDefinitionId = counterLocalService.increment(); KaleoDefinition kaleoDefinition = kaleoDefinitionPersistence.create(kaleoDefinitionId); kaleoDefinition.setCompanyId(user.getCompanyId()); kaleoDefinition.setUserId(user.getUserId()); kaleoDefinition.setUserName(user.getFullName()); kaleoDefinition.setCreateDate(now); kaleoDefinition.setModifiedDate(now); kaleoDefinition.setName(name); kaleoDefinition.setTitle(title); kaleoDefinition.setDescription(description); kaleoDefinition.setContent(content); kaleoDefinition.setVersion(version); kaleoDefinition.setActive(false); kaleoDefinitionPersistence.update(kaleoDefinition); return kaleoDefinition; }
private static LayoutSet _getParentLayoutSet(LayoutSet layoutSet) throws Exception { Group group = layoutSet.getGroup(); if (group.isSite()) { Group parentGroup = group.getParentGroup(); if (parentGroup != null) { return LayoutSetLocalServiceUtil.getLayoutSet( parentGroup.getGroupId(), layoutSet.isPrivateLayout()); } } else if (group.isUser()) { User user = UserLocalServiceUtil.getUser(group.getClassPK()); List<Organization> organizations = OrganizationLocalServiceUtil.getUserOrganizations(user.getUserId()); if (!organizations.isEmpty()) { Organization organization = organizations.get(0); Group parentGroup = organization.getGroup(); return LayoutSetLocalServiceUtil.getLayoutSet( parentGroup.getGroupId(), layoutSet.isPrivateLayout()); } } return null; }
protected void updateUserAndSendRedirect( ActionRequest actionRequest, ActionResponse actionResponse, ThemeDisplay themeDisplay, User user, String password1) throws Exception { _userLocalService.updateLastLogin(user.getUserId(), user.getLoginIP()); _userLocalService.updatePasswordReset(user.getUserId(), false); _userLocalService.updateEmailAddressVerified(user.getUserId(), true); sendRedirect(actionRequest, actionResponse, themeDisplay, user, password1); }
@Override public Address addAddress( long userId, String className, long classPK, String street1, String street2, String street3, String city, String zip, long regionId, long countryId, long typeId, boolean mailing, boolean primary, ServiceContext serviceContext) throws PortalException { User user = userPersistence.findByPrimaryKey(userId); long classNameId = classNameLocalService.getClassNameId(className); validate( 0, user.getCompanyId(), classNameId, classPK, street1, city, zip, regionId, countryId, typeId, mailing, primary); long addressId = counterLocalService.increment(); Address address = addressPersistence.create(addressId); address.setUuid(serviceContext.getUuid()); address.setCompanyId(user.getCompanyId()); address.setUserId(user.getUserId()); address.setUserName(user.getFullName()); address.setClassNameId(classNameId); address.setClassPK(classPK); address.setStreet1(street1); address.setStreet2(street2); address.setStreet3(street3); address.setCity(city); address.setZip(zip); address.setRegionId(regionId); address.setCountryId(countryId); address.setTypeId(typeId); address.setMailing(mailing); address.setPrimary(primary); addressPersistence.update(address); return address; }
public PortletURL getPortletURL() throws PortalException { PortletURL portletURL = _liferayPortletResponse.createRenderURL(); User selUser = PortalUtil.getSelectedUser(_request); if (selUser != null) { portletURL.setParameter("p_u_i_d", String.valueOf(selUser.getUserId())); } long[] selectedGroupIds = StringUtil.split(ParamUtil.getString(_request, "selectedGroupIds"), 0L); boolean includeCompany = ParamUtil.getBoolean(_request, "includeCompany"); boolean includeCurrentGroup = ParamUtil.getBoolean(_request, "includeCurrentGroup", true); boolean includeUserPersonalSite = ParamUtil.getBoolean(_request, "includeUserPersonalSite"); String eventName = ParamUtil.getString( _request, "eventName", _liferayPortletResponse.getNamespace() + "selectSite"); String target = ParamUtil.getString(_request, "target"); portletURL.setParameter("groupId", String.valueOf(getGroupId())); portletURL.setParameter("selectedGroupIds", StringUtil.merge(selectedGroupIds)); portletURL.setParameter("type", getType()); portletURL.setParameter("types", getTypes()); portletURL.setParameter("displayStyle", getDisplayStyle()); portletURL.setParameter("filter", getFilter()); portletURL.setParameter("includeCompany", String.valueOf(includeCompany)); portletURL.setParameter("includeCurrentGroup", String.valueOf(includeCurrentGroup)); portletURL.setParameter("includeUserPersonalSite", String.valueOf(includeUserPersonalSite)); portletURL.setParameter("manualMembership", String.valueOf(isManualMembership())); portletURL.setParameter("eventName", eventName); portletURL.setParameter("target", target); return portletURL; }
@Override protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { try { User user = PortalUtil.getUser(renderRequest); RenderRequestImpl renderRequestImpl = (RenderRequestImpl) renderRequest; DynamicServletRequest dynamicRequest = (DynamicServletRequest) renderRequestImpl.getHttpServletRequest(); dynamicRequest.setParameter("p_u_i_d", String.valueOf(user.getUserId())); Group group = user.getGroup(); dynamicRequest.setParameter("groupId", String.valueOf(group.getGroupId())); ActionUtil.getGroup(renderRequest); } catch (Exception e) { throw new PortletException(e); } super.doDispatch(renderRequest, renderResponse); }
@Override public AssetEntry getAssetEntry(String className, long classPK) throws PortalException { LayoutRevision layoutRevision = _layoutRevisionLocalService.getLayoutRevision(classPK); LayoutSetBranch layoutSetBranch = _layoutSetBranchLocalService.getLayoutSetBranch(layoutRevision.getLayoutSetBranchId()); User user = _userLocalService.getUserById(layoutRevision.getUserId()); AssetEntry assetEntry = _assetEntryLocalService.createAssetEntry(classPK); assetEntry.setGroupId(layoutRevision.getGroupId()); assetEntry.setCompanyId(user.getCompanyId()); assetEntry.setUserId(user.getUserId()); assetEntry.setUserName(user.getFullName()); assetEntry.setCreateDate(layoutRevision.getCreateDate()); assetEntry.setClassNameId(PortalUtil.getClassNameId(LayoutRevision.class.getName())); assetEntry.setClassPK(layoutRevision.getLayoutRevisionId()); StringBundler sb = new StringBundler(4); sb.append(layoutRevision.getHTMLTitle(LocaleUtil.getSiteDefault())); sb.append(" ["); sb.append(layoutSetBranch.getName()); sb.append("]"); assetEntry.setTitle(sb.toString()); return assetEntry; }
public LinkedHashMap<String, Object> getGroupParams() throws PortalException { if (_groupParams != null) { return _groupParams; } long groupId = ParamUtil.getLong(_request, "groupId"); boolean includeCurrentGroup = ParamUtil.getBoolean(_request, "includeCurrentGroup", true); String type = getType(); ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); User user = themeDisplay.getUser(); boolean filterManageableGroups = true; if (permissionChecker.isCompanyAdmin()) { filterManageableGroups = false; } _groupParams = new LinkedHashMap<>(); _groupParams.put("active", Boolean.TRUE); if (isManualMembership()) { _groupParams.put("manualMembership", Boolean.TRUE); } if (type.equals("child-sites")) { Group parentGroup = GroupLocalServiceUtil.getGroup(groupId); List<Group> parentGroups = new ArrayList<>(); parentGroups.add(parentGroup); _groupParams.put("groupsTree", parentGroups); } else if (filterManageableGroups) { _groupParams.put("usersGroups", user.getUserId()); } _groupParams.put("site", Boolean.TRUE); if (!includeCurrentGroup && (groupId > 0)) { List<Long> excludedGroupIds = new ArrayList<>(); Group group = GroupLocalServiceUtil.getGroup(groupId); if (group.isStagingGroup()) { excludedGroupIds.add(group.getLiveGroupId()); } else { excludedGroupIds.add(groupId); } _groupParams.put("excludedGroupIds", excludedGroupIds); } return _groupParams; }
public static Map<String, Serializable> buildPublishLayoutRemoteSettingsMap( User user, long sourceGroupId, boolean privateLayout, Map<Long, Boolean> layoutIdMap, Map<String, String[]> parameterMap, String remoteAddress, int remotePort, String remotePathContext, boolean secureConnection, long remoteGroupId, boolean remotePrivateLayout) { return buildPublishLayoutRemoteSettingsMap( user.getUserId(), sourceGroupId, privateLayout, layoutIdMap, parameterMap, remoteAddress, remotePort, remotePathContext, secureConnection, remoteGroupId, remotePrivateLayout, user.getLocale(), user.getTimeZone()); }
public Folder addFolder( long userId, long accountId, String fullName, String displayName, int remoteMessageCount) throws PortalException { User user = userPersistence.findByPrimaryKey(userId); Date now = new Date(); long folderId = counterLocalService.increment(); Folder folder = folderPersistence.create(folderId); folder.setCompanyId(user.getCompanyId()); folder.setUserId(user.getUserId()); folder.setUserName(user.getFullName()); folder.setCreateDate(now); folder.setModifiedDate(now); folder.setAccountId(accountId); folder.setFullName(fullName); folder.setDisplayName(displayName); folder.setRemoteMessageCount(remoteMessageCount); folderPersistence.update(folder); return folder; }
@Override public void postProcessDocument(Document document, Object obj) throws Exception { User user = (User) obj; List<ProjectsEntry> projectsEntries = ProjectsEntryLocalServiceUtil.getUserProjectsEntries(user.getUserId()); String[] projectTitles = new String[projectsEntries.size()]; for (int i = 0; i < projectTitles.length; i++) { ProjectsEntry projectEntry = projectsEntries.get(i); projectTitles[i] = StringUtil.toLowerCase(projectEntry.getTitle()); } document.addKeyword("projectTitles", projectTitles); int count = UserLocalServiceUtil.getSocialUsersCount( user.getUserId(), SocialRelationConstants.TYPE_BI_CONNECTION, StringPool.EQUAL); List<Long> socialRelationshipUserIds = new ArrayList<>(); int pages = count / Indexer.DEFAULT_INTERVAL; for (int i = 0; i <= pages; i++) { int start = (i * Indexer.DEFAULT_INTERVAL); int end = start + Indexer.DEFAULT_INTERVAL; List<User> socialRelationshipUsers = UserLocalServiceUtil.getSocialUsers( user.getUserId(), SocialRelationConstants.TYPE_BI_CONNECTION, StringPool.EQUAL, start, end, new UserFirstNameComparator(true)); for (User socialRelationshipUser : socialRelationshipUsers) { socialRelationshipUserIds.add(socialRelationshipUser.getUserId()); } } document.addKeyword("socialRelationships", ArrayUtil.toLongArray(socialRelationshipUserIds)); }
@Override public void onBeforeRemove(User user) { try { _subscriptionLocalService.deleteSubscriptions(user.getUserId()); } catch (PortalException pe) { throw new ModelListenerException(pe); } }
protected void importLayouts( long userId, Map<String, String[]> parameterMap, File privateLayoutsFile, File publicLayoutsFile) throws PortalException { User user = userPersistence.findByPrimaryKey(userId); long groupId = user.getGroupId(); if (privateLayoutsFile != null) { Map<String, Serializable> importLayoutSettingsMap = ExportImportConfigurationSettingsMapFactory.buildImportLayoutSettingsMap( user, groupId, true, null, parameterMap); ExportImportConfiguration exportImportConfiguration = exportImportConfigurationLocalService.addDraftExportImportConfiguration( user.getUserId(), ExportImportConfigurationConstants.TYPE_IMPORT_LAYOUT, importLayoutSettingsMap); exportImportLocalService.importLayouts(exportImportConfiguration, privateLayoutsFile); } if (publicLayoutsFile != null) { Map<String, Serializable> importLayoutSettingsMap = ExportImportConfigurationSettingsMapFactory.buildImportLayoutSettingsMap( user, groupId, false, null, parameterMap); ExportImportConfiguration exportImportConfiguration = exportImportConfigurationLocalService.addDraftExportImportConfiguration( user.getUserId(), ExportImportConfigurationConstants.TYPE_IMPORT_LAYOUT, importLayoutSettingsMap); exportImportLocalService.importLayouts(exportImportConfiguration, publicLayoutsFile); } }
@Override public KaleoInstance addKaleoInstance( long kaleoDefinitionId, String kaleoDefinitionName, int kaleoDefinitionVersion, Map<String, Serializable> workflowContext, ServiceContext serviceContext) throws PortalException { User user = userLocalService.fetchUser(serviceContext.getUserId()); if (user == null) { user = userLocalService.getDefaultUser(serviceContext.getCompanyId()); } Date now = new Date(); long kaleoInstanceId = counterLocalService.increment(); KaleoInstance kaleoInstance = kaleoInstancePersistence.create(kaleoInstanceId); long groupId = StagingUtil.getLiveGroupId(serviceContext.getScopeGroupId()); kaleoInstance.setGroupId(groupId); kaleoInstance.setCompanyId(user.getCompanyId()); kaleoInstance.setUserId(user.getUserId()); kaleoInstance.setUserName(user.getFullName()); kaleoInstance.setCreateDate(now); kaleoInstance.setModifiedDate(now); kaleoInstance.setKaleoDefinitionId(kaleoDefinitionId); kaleoInstance.setKaleoDefinitionName(kaleoDefinitionName); kaleoInstance.setKaleoDefinitionVersion(kaleoDefinitionVersion); kaleoInstance.setClassName( (String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME)); if (workflowContext.containsKey(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK)) { kaleoInstance.setClassPK( GetterUtil.getLong( (String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK))); } kaleoInstance.setCompleted(false); kaleoInstance.setWorkflowContext(WorkflowContextUtil.convert(workflowContext)); kaleoInstancePersistence.update(kaleoInstance); return kaleoInstance; }
public static Map<String, Serializable> buildExportLayoutSettingsMap( User user, long groupId, boolean privateLayout, long[] layoutIds, Map<String, String[]> parameterMap) { return buildExportLayoutSettingsMap( user.getUserId(), groupId, privateLayout, layoutIds, parameterMap, user.getLocale(), user.getTimeZone()); }
public static Map<String, Serializable> buildImportPortletSettingsMap( User user, long targetPlid, long targetGroupId, String portletId, Map<String, String[]> parameterMap) { return buildImportPortletSettingsMap( user.getUserId(), targetPlid, targetGroupId, portletId, parameterMap, user.getLocale(), user.getTimeZone()); }
public static Map<String, Serializable> buildPublishLayoutLocalSettingsMap( User user, long sourceGroupId, long targetGroupId, boolean privateLayout, long[] layoutIds, Map<String, String[]> parameterMap) { return buildPublishLayoutLocalSettingsMap( user.getUserId(), sourceGroupId, targetGroupId, privateLayout, layoutIds, parameterMap, user.getLocale(), user.getTimeZone()); }
public static Map<String, Serializable> buildExportPortletSettingsMap( User user, long sourcePlid, long sourceGroupId, String portletId, Map<String, String[]> parameterMap, String fileName) { return buildExportPortletSettingsMap( user.getUserId(), sourcePlid, sourceGroupId, portletId, parameterMap, user.getLocale(), user.getTimeZone(), fileName); }
protected void resetUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); String emailAddress = ParamUtil.getString(actionRequest, "emailAddress"); User anonymousUser = _userLocalService.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress); if (anonymousUser.getStatus() != WorkflowConstants.STATUS_INCOMPLETE) { throw new PrincipalException.MustBeAuthenticated(anonymousUser.getUuid()); } _userLocalService.deleteUser(anonymousUser.getUserId()); addUser(actionRequest, actionResponse); }
protected void sendRedirect( ActionRequest actionRequest, ActionResponse actionResponse, ThemeDisplay themeDisplay, User user, String password) throws Exception { String login = null; Company company = themeDisplay.getCompany(); String authType = company.getAuthType(); if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) { login = String.valueOf(user.getUserId()); } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) { login = user.getScreenName(); } else { login = user.getEmailAddress(); } HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect")); if (Validator.isNotNull(redirect)) { HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); AuthenticatedSessionManagerUtil.login(request, response, login, password, false, null); } else { PortletURL loginURL = LoginUtil.getLoginURL(request, themeDisplay.getPlid()); loginURL.setParameter("login", login); redirect = loginURL.toString(); } actionResponse.sendRedirect(redirect); }
public static ExportImportConfiguration buildDefaultLocalPublishingExportImportConfiguration( User user, long sourceGroupId, long targetGroupId, boolean privateLayout, Map<String, String[]> parameterMap) throws PortalException { Map<String, Serializable> publishLayoutLocalSettingsMap = ExportImportConfigurationSettingsMapFactory.buildPublishLayoutLocalSettingsMap( user, sourceGroupId, targetGroupId, privateLayout, ExportImportHelperUtil.getAllLayoutIds(sourceGroupId, privateLayout), parameterMap); return ExportImportConfigurationLocalServiceUtil.addDraftExportImportConfiguration( user.getUserId(), ExportImportConfigurationConstants.TYPE_PUBLISH_LAYOUT_LOCAL, publishLayoutLocalSettingsMap); }
protected MBMessage addMBMessageAttachment() throws Exception { List<ObjectValuePair<String, InputStream>> objectValuePairs = MBTestUtil.getInputStreamOVPs("OSX_Test.docx", getClass(), StringPool.BLANK); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); User user = TestPropsValues.getUser(); return MBMessageLocalServiceUtil.addMessage( user.getUserId(), user.getFullName(), _group.getGroupId(), MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID, "Subject", "Body", MBMessageConstants.DEFAULT_FORMAT, objectValuePairs, false, 0, false, serviceContext); }
protected LinkedHashMap<String, Object> getGroupParams( PortletRequest portletRequest, GroupSearchTerms searchTerms, long parentGroupId) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); LinkedHashMap<String, Object> groupParams = new LinkedHashMap<>(); groupParams.put("site", Boolean.TRUE); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); User user = themeDisplay.getUser(); if (searchTerms.hasSearchTerms()) { if (isFilterManageableGroups(portletRequest)) { groupParams.put("groupsTree", getAllGroups(portletRequest)); } else if (parentGroupId > 0) { List<Group> groupsTree = new ArrayList<>(); Group parentGroup = _groupLocalService.getGroup(parentGroupId); groupsTree.add(parentGroup); groupParams.put("groupsTree", groupsTree); } if (!permissionChecker.isCompanyAdmin() && !GroupPermissionUtil.contains(permissionChecker, ActionKeys.VIEW)) { groupParams.put("usersGroups", Long.valueOf(user.getUserId())); } } return groupParams; }
protected void updateIncompleteUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { HttpServletRequest request = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(actionRequest)); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); boolean autoPassword = true; String password1 = null; String password2 = null; boolean autoScreenName = false; String screenName = ParamUtil.getString(actionRequest, "screenName"); String emailAddress = ParamUtil.getString(actionRequest, "emailAddress"); HttpSession session = request.getSession(); long facebookId = GetterUtil.getLong(session.getAttribute(WebKeys.FACEBOOK_INCOMPLETE_USER_ID)); String googleUserId = GetterUtil.getString(session.getAttribute(WebKeys.GOOGLE_INCOMPLETE_USER_ID)); if (Validator.isNotNull(googleUserId)) { autoPassword = false; } if ((facebookId > 0) || Validator.isNotNull(googleUserId)) { password1 = PwdGenerator.getPassword(); password2 = password1; } String openId = ParamUtil.getString(actionRequest, "openId"); String firstName = ParamUtil.getString(actionRequest, "firstName"); String middleName = ParamUtil.getString(actionRequest, "middleName"); String lastName = ParamUtil.getString(actionRequest, "lastName"); long prefixId = ParamUtil.getInteger(actionRequest, "prefixId"); long suffixId = ParamUtil.getInteger(actionRequest, "suffixId"); boolean male = ParamUtil.getBoolean(actionRequest, "male", true); int birthdayMonth = ParamUtil.getInteger(actionRequest, "birthdayMonth"); int birthdayDay = ParamUtil.getInteger(actionRequest, "birthdayDay"); int birthdayYear = ParamUtil.getInteger(actionRequest, "birthdayYear"); String jobTitle = ParamUtil.getString(actionRequest, "jobTitle"); boolean updateUserInformation = true; boolean sendEmail = true; if (Validator.isNotNull(googleUserId)) { sendEmail = false; } ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest); User user = _userService.updateIncompleteUser( themeDisplay.getCompanyId(), autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, themeDisplay.getLocale(), firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, updateUserInformation, sendEmail, serviceContext); if (facebookId > 0) { session.removeAttribute(WebKeys.FACEBOOK_INCOMPLETE_USER_ID); updateUserAndSendRedirect(actionRequest, actionResponse, themeDisplay, user, password1); return; } if (Validator.isNotNull(googleUserId)) { _userLocalService.updateGoogleUserId(user.getUserId(), googleUserId); session.removeAttribute(WebKeys.GOOGLE_INCOMPLETE_USER_ID); updateUserAndSendRedirect(actionRequest, actionResponse, themeDisplay, user, password1); return; } // Session messages if (user.getStatus() == WorkflowConstants.STATUS_APPROVED) { SessionMessages.add(request, "userAdded", user.getEmailAddress()); SessionMessages.add(request, "userAddedPassword", user.getPasswordUnencrypted()); } else { SessionMessages.add(request, "userPending", user.getEmailAddress()); } // Send redirect sendRedirect(actionRequest, actionResponse, themeDisplay, user, user.getPasswordUnencrypted()); }
@Override public String readResponse(ThemeDisplay themeDisplay, ActionRequest actionRequest) throws PortalException { HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); request = PortalUtil.getOriginalServletRequest(request); String receivingURL = ParamUtil.getString(request, "openid.return_to"); ParameterList parameterList = new ParameterList(request.getParameterMap()); HttpSession session = request.getSession(); DiscoveryInformation discoveryInformation = (DiscoveryInformation) session.getAttribute(OpenIdWebKeys.OPEN_ID_DISCO); if (discoveryInformation == null) { return null; } AuthSuccess authSuccess = null; String firstName = null; String lastName = null; String emailAddress = null; try { VerificationResult verificationResult = _consumerManager.verify(receivingURL, parameterList, discoveryInformation); Identifier identifier = verificationResult.getVerifiedId(); if (identifier == null) { return null; } authSuccess = (AuthSuccess) verificationResult.getAuthResponse(); firstName = null; lastName = null; emailAddress = null; if (authSuccess.hasExtension(SRegMessage.OPENID_NS_SREG)) { MessageExtension messageExtension = authSuccess.getExtension(SRegMessage.OPENID_NS_SREG); if (messageExtension instanceof SRegResponse) { SRegResponse sregResp = (SRegResponse) messageExtension; String fullName = GetterUtil.getString(sregResp.getAttributeValue(_OPEN_ID_SREG_ATTR_FULLNAME)); String[] names = splitFullName(fullName); if (names != null) { firstName = names[0]; lastName = names[1]; } emailAddress = sregResp.getAttributeValue(_OPEN_ID_SREG_ATTR_EMAIL); } } if (authSuccess.hasExtension(AxMessage.OPENID_NS_AX)) { MessageExtension messageExtension = authSuccess.getExtension(AxMessage.OPENID_NS_AX); if (messageExtension instanceof FetchResponse) { FetchResponse fetchResponse = (FetchResponse) messageExtension; OpenIdProvider openIdProvider = _openIdProviderRegistry.getOpenIdProvider(discoveryInformation.getOPEndpoint()); String[] openIdAXTypes = openIdProvider.getAxSchema(); for (String openIdAXType : openIdAXTypes) { if (openIdAXType.equals(_OPEN_ID_AX_ATTR_EMAIL)) { if (Validator.isNull(emailAddress)) { emailAddress = getFirstValue(fetchResponse.getAttributeValues(_OPEN_ID_AX_ATTR_EMAIL)); } } else if (openIdAXType.equals(_OPEN_ID_AX_ATTR_FIRST_NAME)) { if (Validator.isNull(firstName)) { firstName = getFirstValue(fetchResponse.getAttributeValues(_OPEN_ID_AX_ATTR_FIRST_NAME)); } } else if (openIdAXType.equals(_OPEN_ID_AX_ATTR_FULL_NAME)) { String fullName = fetchResponse.getAttributeValue(_OPEN_ID_AX_ATTR_FULL_NAME); String[] names = splitFullName(fullName); if (names != null) { if (Validator.isNull(firstName)) { firstName = names[0]; } if (Validator.isNull(lastName)) { lastName = names[1]; } } } else if (openIdAXType.equals(_OPEN_ID_AX_ATTR_LAST_NAME)) { if (Validator.isNull(lastName)) { lastName = getFirstValue(fetchResponse.getAttributeValues(_OPEN_ID_AX_ATTR_LAST_NAME)); } } } } } } catch (AssociationException ae) { throw new OpenIdServiceException.AssociationException(ae.getMessage(), ae); } catch (DiscoveryException de) { throw new OpenIdServiceException.DiscoveryException(de.getMessage(), de); } catch (MessageException me) { throw new OpenIdServiceException.MessageException(me.getMessage(), me); } String openId = normalize(authSuccess.getIdentity()); User user = _userLocalService.fetchUserByOpenId(themeDisplay.getCompanyId(), openId); if (user != null) { session.setAttribute(WebKeys.OPEN_ID_LOGIN, user.getUserId()); return null; } try { if (Validator.isNull(firstName) || Validator.isNull(lastName) || Validator.isNull(emailAddress)) { SessionMessages.add(request, "openIdUserInformationMissing"); if (_log.isInfoEnabled()) { _log.info( "The OpenID provider did not send the required " + "attributes to create an account"); } String createAccountURL = PortalUtil.getCreateAccountURL(request, themeDisplay); String portletId = HttpUtil.getParameter(createAccountURL, "p_p_id", false); String portletNamespace = PortalUtil.getPortletNamespace(portletId); createAccountURL = HttpUtil.setParameter(createAccountURL, portletNamespace + "openId", openId); session.setAttribute(WebKeys.OPEN_ID_LOGIN_PENDING, Boolean.TRUE); return createAccountURL; } } catch (Exception e) { throw new PortalException(e); } long creatorUserId = 0; long companyId = themeDisplay.getCompanyId(); boolean autoPassword = false; String password1 = PwdGenerator.getPassword(); String password2 = password1; boolean autoScreenName = true; String screenName = StringPool.BLANK; long facebookId = 0; Locale locale = themeDisplay.getLocale(); String middleName = StringPool.BLANK; long prefixId = 0; long suffixId = 0; boolean male = true; int birthdayMonth = Calendar.JANUARY; int birthdayDay = 1; int birthdayYear = 1970; String jobTitle = StringPool.BLANK; long[] groupIds = null; long[] organizationIds = null; long[] roleIds = null; long[] userGroupIds = null; boolean sendEmail = false; ServiceContext serviceContext = new ServiceContext(); user = _userLocalService.addUser( creatorUserId, companyId, autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, locale, firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext); session.setAttribute(WebKeys.OPEN_ID_LOGIN, user.getUserId()); return null; }
@Override public void sendRequest( ThemeDisplay themeDisplay, ActionRequest actionRequest, ActionResponse actionResponse) throws PortalException { HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); request = PortalUtil.getOriginalServletRequest(request); HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); HttpSession session = request.getSession(); LiferayPortletResponse liferayPortletResponse = PortalUtil.getLiferayPortletResponse(actionResponse); String openId = ParamUtil.getString(actionRequest, "openId"); PortletURL portletURL = liferayPortletResponse.createActionURL(); portletURL.setParameter(ActionRequest.ACTION_NAME, "/login/openid"); portletURL.setParameter("saveLastPath", Boolean.FALSE.toString()); portletURL.setParameter("mvcRenderCommandName", "/login/openid"); portletURL.setParameter(Constants.CMD, Constants.READ); try { List<DiscoveryInformation> discoveryInformationList = _consumerManager.discover(openId); DiscoveryInformation discoveryInformation = _consumerManager.associate(discoveryInformationList); session.setAttribute(OpenIdWebKeys.OPEN_ID_DISCO, discoveryInformation); AuthRequest authRequest = _consumerManager.authenticate( discoveryInformation, portletURL.toString(), themeDisplay.getPortalURL()); if (_userLocalService.fetchUserByOpenId(themeDisplay.getCompanyId(), openId) != null) { response.sendRedirect(authRequest.getDestinationUrl(true)); return; } String screenName = getScreenName(openId); User user = _userLocalService.fetchUserByScreenName(themeDisplay.getCompanyId(), screenName); if (user != null) { _userLocalService.updateOpenId(user.getUserId(), openId); response.sendRedirect(authRequest.getDestinationUrl(true)); return; } FetchRequest fetchRequest = FetchRequest.createFetchRequest(); OpenIdProvider openIdProvider = _openIdProviderRegistry.getOpenIdProvider(discoveryInformation.getOPEndpoint()); Map<String, String> openIdAXTypes = openIdProvider.getAxTypes(); for (String openIdAXType : openIdAXTypes.keySet()) { fetchRequest.addAttribute(openIdAXType, openIdAXTypes.get(openIdAXType), true); } authRequest.addExtension(fetchRequest); SRegRequest sRegRequest = SRegRequest.createFetchRequest(); sRegRequest.addAttribute(_OPEN_ID_SREG_ATTR_EMAIL, true); sRegRequest.addAttribute(_OPEN_ID_SREG_ATTR_FULLNAME, true); authRequest.addExtension(sRegRequest); response.sendRedirect(authRequest.getDestinationUrl(true)); } catch (ConsumerException ce) { throw new OpenIdServiceException.ConsumerException(ce.getMessage(), ce); } catch (DiscoveryException de) { throw new OpenIdServiceException.DiscoveryException(de.getMessage(), de); } catch (MessageException me) { throw new OpenIdServiceException.MessageException(me.getMessage(), me); } catch (IOException ioe) { throw new SystemException("Unable to communicate with OpenId provider", ioe); } }
protected void addUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); HttpSession session = request.getSession(); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); boolean autoPassword = true; String password1 = null; String password2 = null; boolean autoScreenName = isAutoScreenName(); String screenName = ParamUtil.getString(actionRequest, "screenName"); String emailAddress = ParamUtil.getString(actionRequest, "emailAddress"); long facebookId = ParamUtil.getLong(actionRequest, "facebookId"); String openId = ParamUtil.getString(actionRequest, "openId"); String languageId = ParamUtil.getString(actionRequest, "languageId"); String firstName = ParamUtil.getString(actionRequest, "firstName"); String middleName = ParamUtil.getString(actionRequest, "middleName"); String lastName = ParamUtil.getString(actionRequest, "lastName"); long prefixId = ParamUtil.getInteger(actionRequest, "prefixId"); long suffixId = ParamUtil.getInteger(actionRequest, "suffixId"); boolean male = ParamUtil.getBoolean(actionRequest, "male", true); int birthdayMonth = ParamUtil.getInteger(actionRequest, "birthdayMonth"); int birthdayDay = ParamUtil.getInteger(actionRequest, "birthdayDay"); int birthdayYear = ParamUtil.getInteger(actionRequest, "birthdayYear"); String jobTitle = ParamUtil.getString(actionRequest, "jobTitle"); long[] groupIds = null; long[] organizationIds = null; long[] roleIds = null; long[] userGroupIds = null; boolean sendEmail = true; ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest); if (PropsValues.LOGIN_CREATE_ACCOUNT_ALLOW_CUSTOM_PASSWORD) { autoPassword = false; password1 = ParamUtil.getString(actionRequest, "password1"); password2 = ParamUtil.getString(actionRequest, "password2"); } boolean openIdPending = false; Boolean openIdLoginPending = (Boolean) session.getAttribute(WebKeys.OPEN_ID_LOGIN_PENDING); if ((openIdLoginPending != null) && openIdLoginPending.booleanValue() && Validator.isNotNull(openId)) { sendEmail = false; openIdPending = true; } User user = _userService.addUserWithWorkflow( company.getCompanyId(), autoPassword, password1, password2, autoScreenName, screenName, emailAddress, facebookId, openId, LocaleUtil.fromLanguageId(languageId), firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle, groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext); if (openIdPending) { session.setAttribute(WebKeys.OPEN_ID_LOGIN, Long.valueOf(user.getUserId())); session.removeAttribute(WebKeys.OPEN_ID_LOGIN_PENDING); } else { // Session messages if (user.getStatus() == WorkflowConstants.STATUS_APPROVED) { SessionMessages.add(request, "userAdded", user.getEmailAddress()); SessionMessages.add(request, "userAddedPassword", user.getPasswordUnencrypted()); } else { SessionMessages.add(request, "userPending", user.getEmailAddress()); } } // Send redirect sendRedirect(actionRequest, actionResponse, themeDisplay, user, user.getPasswordUnencrypted()); }
@Override public ActionForward execute( ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); String languageId = ParamUtil.getString(request, "languageId"); Locale locale = LocaleUtil.fromLanguageId(languageId); if (LanguageUtil.isAvailableLocale(themeDisplay.getSiteGroupId(), locale)) { boolean persistState = ParamUtil.getBoolean(request, "persistState", true); if (themeDisplay.isSignedIn() && persistState) { User user = themeDisplay.getUser(); Contact contact = user.getContact(); AdminUtil.updateUser( request, user.getUserId(), user.getScreenName(), user.getEmailAddress(), user.getFacebookId(), user.getOpenId(), languageId, user.getTimeZoneId(), user.getGreeting(), user.getComments(), contact.getSmsSn(), contact.getFacebookSn(), contact.getJabberSn(), contact.getSkypeSn(), contact.getTwitterSn()); } session.setAttribute(Globals.LOCALE_KEY, locale); LanguageUtil.updateCookie(request, response, locale); } // Send redirect String redirect = ParamUtil.getString(request, "redirect"); String layoutURL = StringPool.BLANK; String queryString = StringPool.BLANK; int pos = redirect.indexOf(Portal.FRIENDLY_URL_SEPARATOR); if (pos == -1) { pos = redirect.indexOf(StringPool.QUESTION); } if (pos != -1) { layoutURL = redirect.substring(0, pos); queryString = redirect.substring(pos); } else { layoutURL = redirect; } Layout layout = themeDisplay.getLayout(); if (isGroupFriendlyURL(layout.getGroup(), layout, layoutURL, locale)) { if (PropsValues.LOCALE_PREPEND_FRIENDLY_URL_STYLE == 0) { redirect = layoutURL; } else { redirect = PortalUtil.getGroupFriendlyURL(layout.getLayoutSet(), themeDisplay, locale); } } else { if (PropsValues.LOCALE_PREPEND_FRIENDLY_URL_STYLE == 0) { if (themeDisplay.isI18n()) { redirect = layout.getFriendlyURL(locale); } else { redirect = PortalUtil.getLayoutURL(layout, themeDisplay, locale); } } else { redirect = PortalUtil.getLayoutFriendlyURL(layout, themeDisplay, locale); } } if (layout.isTypeControlPanel()) { redirect = redirect + queryString; } response.sendRedirect(redirect); return null; }