protected void doExportStagedModel( PortletDataContext portletDataContext, CalendarResource calendarResource) throws Exception { Element calendarResourceElement = portletDataContext.getExportDataElement(calendarResource); for (Calendar calendar : calendarResource.getCalendars()) { StagedModelDataHandlerUtil.exportReferenceStagedModel( portletDataContext, calendarResource, calendar, PortletDataContext.REFERENCE_TYPE_STRONG); } if (calendarResource.getClassNameId() == PortalUtil.getClassNameId(User.class)) { User user = UserLocalServiceUtil.getUser(calendarResource.getClassPK()); portletDataContext.addReferenceElement( calendarResource, calendarResourceElement, user, User.class, PortletDataContext.REFERENCE_TYPE_DEPENDENCY_DISPOSABLE, true); } portletDataContext.addClassedModel( calendarResourceElement, ExportImportPathUtil.getModelPath(calendarResource), calendarResource); }
@Override protected void doUpgrade() throws Exception { List<User> users = UserLocalServiceUtil.getUsers(QueryUtil.ALL_POS, QueryUtil.ALL_POS); for (User user : users) { try { if (user.isDefaultUser()) { continue; } Group group = user.getGroup(); LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(group.getGroupId(), false); String themeId = layoutSet.getThemeId(); if (!themeId.equals("so_WAR_sotheme")) { return; } Role role = RoleLocalServiceUtil.getRole(user.getCompanyId(), RoleConstants.SOCIAL_OFFICE_USER); UserLocalServiceUtil.addRoleUsers(role.getRoleId(), new long[] {user.getUserId()}); updateUserGroup(group); updateSocialRelations(user); } catch (Exception e) { } } }
@Override public void run(String[] arg0) throws ActionException { Properties props = new Properties(); try { props.load( this.getClass().getClassLoader().getResourceAsStream("password.changer.properties")); String type = props.getProperty("type"); String virtualHost = props.getProperty("virtualhost"); Company c = CompanyUtil.fetchByVirtualHost(virtualHost); User u = null; String name = null; if ("screenname".equals(type)) { String screenName = props.getProperty("screenname"); u = UserLocalServiceUtil.getUserByScreenName(c.getCompanyId(), screenName); name = screenName; } else if ("e-mail".equals(type)) { String emailAddress = props.getProperty("emailaddress"); u = UserLocalServiceUtil.getUserByEmailAddress(c.getCompanyId(), emailAddress); name = emailAddress; } else { _log.error( "You should set type to screenname or e-mail if you want to use the password updater."); } String password = props.getProperty("password"); UserLocalServiceUtil.updatePasswordManually(u.getUserId(), password, false, true, new Date()); _log.info("Password for " + name + " was updated."); } catch (Exception e) { _log.error(e); } }
protected int authenticateOmniadmin( long companyId, String emailAddress, String screenName, long userId) throws Exception { // Only allow omniadmin if Liferay password checking is enabled if (PropsValues.AUTH_PIPELINE_ENABLE_LIFERAY_CHECK) { if (userId > 0) { if (OmniadminUtil.isOmniadmin(userId)) { return SUCCESS; } } else if (Validator.isNotNull(emailAddress)) { try { User user = UserLocalServiceUtil.getUserByEmailAddress(companyId, emailAddress); if (OmniadminUtil.isOmniadmin(user.getUserId())) { return SUCCESS; } } catch (NoSuchUserException nsue) { } } else if (Validator.isNotNull(screenName)) { try { User user = UserLocalServiceUtil.getUserByScreenName(companyId, screenName); if (OmniadminUtil.isOmniadmin(user.getUserId())) { return SUCCESS; } } catch (NoSuchUserException nsue) { } } } return FAILURE; }
@After public void tearDown() throws Exception { SocialActivityHierarchyEntryThreadLocal.clear(); if (_actorUser != null) { UserLocalServiceUtil.deleteUser(_actorUser); _actorUser = null; } if (_assetEntry != null) { AssetEntryLocalServiceUtil.deleteEntry(_assetEntry); _assetEntry = null; } if (_creatorUser != null) { UserLocalServiceUtil.deleteUser(_creatorUser); _creatorUser = null; } if (_group != null) { GroupLocalServiceUtil.deleteGroup(_group); _group = null; } }
private void update() { if (!IConstants.CFG_NOTIFY_OLD_USERS) return; DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(User.class, PortalClassLoaderUtil.getClassLoader()); dynamicQuery.add(RestrictionsFactoryUtil.eq("jobTitle", "mail-not-sent")); try { @SuppressWarnings("unchecked") List<User> users = UserLocalServiceUtil.dynamicQuery(dynamicQuery); int cnt = 0; for (User user : users) { // notifyUser thru email and SMS user.setJobTitle(StringPool.BLANK); user.setLastName(StringPool.BLANK); user = UserLocalServiceUtil.updateUser(user); cnt++; if (cnt == 200) break; } } catch (SystemException e) { e.printStackTrace(); } }
/* * NOTE FOR DEVELOPERS: * * Never modify or reference this class directly. All methods that expect a user model instance should use the {@link User} interface instead. */ public void persist() throws SystemException { if (this.isNew()) { UserLocalServiceUtil.addUser(this); } else { UserLocalServiceUtil.updateUser(this); } }
protected List<User> parseRecipients(long userId, String to) throws PortalException { User user = UserLocalServiceUtil.getUser(userId); String[] recipients = StringUtil.split(to); List<User> users = new ArrayList<>(); for (String recipient : recipients) { int x = recipient.indexOf(CharPool.LESS_THAN); int y = recipient.indexOf(CharPool.GREATER_THAN); try { String screenName = recipient; if ((x != -1) && (y != -1)) { screenName = recipient.substring(x + 1, y); } User recipientUser = UserLocalServiceUtil.getUserByScreenName(user.getCompanyId(), screenName); if (!users.contains(recipientUser)) { users.add(recipientUser); } } catch (NoSuchUserException nsue) { } } return users; }
protected List<User> getUsers( ActionRequest actionRequest, ActionResponse actionResponse, ThemeDisplay themeDisplay) throws Exception { PortletURL portletURL = ((ActionResponseImpl) actionResponse).createRenderURL(PortletKeys.USERS_ADMIN); UserSearch userSearch = new UserSearch(actionRequest, portletURL); UserSearchTerms searchTerms = (UserSearchTerms) userSearch.getSearchTerms(); searchTerms.setStatus(WorkflowConstants.STATUS_APPROVED); LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>(); long organizationId = searchTerms.getOrganizationId(); if (organizationId > 0) { params.put("usersOrgs", new Long(organizationId)); } long roleId = searchTerms.getRoleId(); if (roleId > 0) { params.put("usersRoles", new Long(roleId)); } long userGroupId = searchTerms.getUserGroupId(); if (userGroupId > 0) { params.put("usersUserGroups", new Long(userGroupId)); } if (searchTerms.isAdvancedSearch()) { return UserLocalServiceUtil.search( themeDisplay.getCompanyId(), searchTerms.getFirstName(), searchTerms.getMiddleName(), searchTerms.getLastName(), searchTerms.getScreenName(), searchTerms.getEmailAddress(), searchTerms.getStatus(), params, searchTerms.isAndOperator(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, (OrderByComparator) null); } else { return UserLocalServiceUtil.search( themeDisplay.getCompanyId(), searchTerms.getKeywords(), searchTerms.getStatus(), params, QueryUtil.ALL_POS, QueryUtil.ALL_POS, (OrderByComparator) null); } }
public static List<User> getThreadUsers(long userId, long mbThreadId) throws PortalException, SystemException { List<User> users = new ArrayList<User>(); // Users who have contributed to the thread List<MBMessage> mbMessages = UserThreadServiceUtil.getThreadMessages( mbThreadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, false); for (MBMessage mbMessage : mbMessages) { if (userId == mbMessage.getUserId()) { continue; } User user = UserLocalServiceUtil.fetchUser(mbMessage.getUserId()); if (user == null) { user = UserLocalServiceUtil.createUser(mbMessage.getUserId()); user.setFirstName(mbMessage.getUserName()); user.setStatus(WorkflowConstants.STATUS_INACTIVE); } if (!users.contains(user)) { users.add(user); } } // Users who can view the thread List<UserThread> userThreads = UserThreadLocalServiceUtil.getMBThreadUserThreads(mbThreadId); for (UserThread userThread : userThreads) { if (userId == userThread.getUserId()) { continue; } User user = UserLocalServiceUtil.fetchUser(userThread.getUserId()); if (user == null) { user = UserLocalServiceUtil.createUser(userThread.getUserId()); user.setFirstName(userThread.getUserName()); user.setStatus(WorkflowConstants.STATUS_INACTIVE); } if (!users.contains(user)) { users.add(user); } } return users; }
@Test public void testAddUserToRequiredGroups() throws Exception { long[] requiredGroupIds = addRequiredGroups(); int initialGroupUsersCount = UserLocalServiceUtil.getGroupUsersCount(requiredGroupIds[0]); MembershipPolicyTestUtil.addUser(null, null, new long[] {requiredGroupIds[0]}, null); Assert.assertEquals( initialGroupUsersCount + 1, UserLocalServiceUtil.getGroupUsersCount(requiredGroupIds[0])); }
@Test public void testAssignUsersToRequiredGroup() throws Exception { long[] requiredGroupIds = addRequiredGroups(); int initialGroupUsersCount = UserLocalServiceUtil.getGroupUsersCount(requiredGroupIds[0]); UserServiceUtil.addGroupUsers( requiredGroupIds[0], addUsers(), ServiceContextTestUtil.getServiceContext()); Assert.assertEquals( initialGroupUsersCount + 2, UserLocalServiceUtil.getGroupUsersCount(requiredGroupIds[0])); Assert.assertTrue(isPropagateMembership()); }
private static void _updateCompany(HttpServletRequest request) throws Exception { Company company = CompanyLocalServiceUtil.getCompanyById(PortalInstances.getDefaultCompanyId()); Account account = company.getAccount(); String currentName = account.getName(); String newName = ParamUtil.getString(request, "companyName", PropsValues.COMPANY_DEFAULT_NAME); if (!currentName.equals(newName)) { account.setName(newName); AccountLocalServiceUtil.updateAccount(account); } String languageId = ParamUtil.getString(request, "companyLocale", PropsValues.COMPANY_DEFAULT_LOCALE); User defaultUser = company.getDefaultUser(); defaultUser.setLanguageId(languageId); UserLocalServiceUtil.updateUser(defaultUser); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); themeDisplay.setCompany(company); }
protected String[] authenticate() throws IOException, UnsupportedCallbackException { NameCallback nameCallback = new NameCallback("name: "); PasswordCallback passwordCallback = new PasswordCallback("password: ", false); _callbackHandler.handle(new Callback[] {nameCallback, passwordCallback}); String name = nameCallback.getName(); String password = null; char[] passwordChar = passwordCallback.getPassword(); if (passwordChar != null) { password = new String(passwordChar); } if (name == null) { return new String[] {StringPool.BLANK, StringPool.BLANK}; } try { long userId = GetterUtil.getLong(name); if (UserLocalServiceUtil.authenticateForJAAS(userId, password)) { return new String[] {name, password}; } } catch (Exception e) { _log.error(e, e); } return null; }
@Override public AnonymousUser addAnonymousUser( long userId, String lastIp, String typeSettings, ServiceContext serviceContext) throws PortalException, SystemException { User user = UserLocalServiceUtil.fetchUser(userId); Date now = new Date(); long anonymousUserId = CounterLocalServiceUtil.increment(); AnonymousUser anonymousUser = anonymousUserPersistence.create(anonymousUserId); anonymousUser.setCompanyId(serviceContext.getCompanyId()); if (user != null) { anonymousUser.setUserId(user.getUserId()); anonymousUser.setUserName(user.getFullName()); } anonymousUser.setCreateDate(serviceContext.getCreateDate(now)); anonymousUser.setModifiedDate(serviceContext.getModifiedDate(now)); anonymousUser.setLastIp(lastIp); anonymousUser.setTypeSettings(typeSettings); anonymousUserPersistence.update(anonymousUser); return anonymousUser; }
@Override public AnonymousUser updateAnonymousUser( long anonymousUserId, long userId, String lastIp, String typeSettings, ServiceContext serviceContext) throws PortalException, SystemException { Date now = new Date(); AnonymousUser anonymousUser = anonymousUserPersistence.findByPrimaryKey(anonymousUserId); User user = UserLocalServiceUtil.fetchUser(userId); if (user != null) { anonymousUser.setUserId(user.getUserId()); anonymousUser.setUserName(user.getFullName()); } anonymousUser.setModifiedDate(serviceContext.getModifiedDate(now)); anonymousUser.setLastIp(lastIp); anonymousUser.setTypeSettings(typeSettings); anonymousUserPersistence.update(anonymousUser); return anonymousUser; }
public AssetRenderer getAssetRenderer(long classPK, int type) throws PortalException, SystemException { User user = UserLocalServiceUtil.getUserById(classPK); return new UserAssetRenderer(user); }
@Override public Map<String, String> getReferenceAttributes( PortletDataContext portletDataContext, DDMStructure structure) { Map<String, String> referenceAttributes = new HashMap<String, String>(); referenceAttributes.put("referenced-class-name", structure.getClassName()); referenceAttributes.put("structure-key", structure.getStructureKey()); long defaultUserId = 0; try { defaultUserId = UserLocalServiceUtil.getDefaultUserId(structure.getCompanyId()); } catch (Exception e) { return referenceAttributes; } boolean preloaded = false; if (defaultUserId == structure.getUserId()) { preloaded = true; } referenceAttributes.put("preloaded", String.valueOf(preloaded)); return referenceAttributes; }
protected long getImageId(HttpServletRequest request) { // The image id may be passed in as image_id, img_id, or i_id long imageId = ParamUtil.getLong(request, "image_id"); if (imageId <= 0) { imageId = ParamUtil.getLong(request, "img_id"); } if (imageId <= 0) { imageId = ParamUtil.getLong(request, "i_id"); } if (imageId <= 0) { long companyId = ParamUtil.getLong(request, "companyId"); String screenName = ParamUtil.getString(request, "screenName"); try { if ((companyId > 0) && Validator.isNotNull(screenName)) { User user = UserLocalServiceUtil.getUserByScreenName(companyId, screenName); imageId = user.getPortraitId(); } } catch (Exception e) { } } return imageId; }
public static long getGroupId(long companyId, String[] pathArray) throws WebDAVException { try { if (pathArray.length == 0) { return 0; } String name = pathArray[0]; Group group = GroupLocalServiceUtil.fetchFriendlyURLGroup(companyId, StringPool.SLASH + name); if (group != null) { return group.getGroupId(); } User user = UserLocalServiceUtil.fetchUserByScreenName(companyId, name); if (user != null) { group = user.getGroup(); return group.getGroupId(); } } catch (Exception e) { throw new WebDAVException(e); } return 0; }
public void importFromLDAP(long companyId) throws Exception { if (!LDAPSettingsUtil.isImportEnabled(companyId)) { return; } long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId); if (LockLocalServiceUtil.hasLock( defaultUserId, PortalLDAPImporterUtil.class.getName(), companyId)) { if (_log.isDebugEnabled()) { _log.debug( "Skipping LDAP import for company " + companyId + "because another LDAP import is in process"); } return; } LockLocalServiceUtil.lock( defaultUserId, PortalLDAPImporterUtil.class.getName(), companyId, PortalLDAPImporterImpl.class.getName(), false, PropsValues.LDAP_IMPORT_LOCK_EXPIRATION_TIME); long threadLocalCompanyId = CompanyThreadLocal.getCompanyId(); try { if (threadLocalCompanyId == CompanyConstants.SYSTEM) { CompanyThreadLocal.setCompanyId(companyId); } long[] ldapServerIds = StringUtil.split(PrefsPropsUtil.getString(companyId, "ldap.server.ids"), 0L); for (long ldapServerId : ldapServerIds) { importFromLDAP(ldapServerId, companyId); } for (int ldapServerId = 0; ; ldapServerId++) { String postfix = LDAPSettingsUtil.getPropertyPostfix(ldapServerId); String providerUrl = PrefsPropsUtil.getString(companyId, PropsKeys.LDAP_BASE_PROVIDER_URL + postfix); if (Validator.isNull(providerUrl)) { break; } importFromLDAP(ldapServerId, companyId); } } finally { LockLocalServiceUtil.unlock(PortalLDAPImporterUtil.class.getName(), companyId); CompanyThreadLocal.setCompanyId(threadLocalCompanyId); } }
/** @deprecated As of 6.2.0, replaced by {@link #getUserName(long, ServiceContext)} */ protected String getUserName(long userId, ThemeDisplay themeDisplay) { try { if (userId <= 0) { return StringPool.BLANK; } User user = UserLocalServiceUtil.getUserById(userId); if (user.getUserId() == themeDisplay.getUserId()) { return HtmlUtil.escape(user.getFirstName()); } String userName = user.getFullName(); Group group = user.getGroup(); if (group.getGroupId() == themeDisplay.getScopeGroupId()) { return HtmlUtil.escape(userName); } String userDisplayURL = user.getDisplayURL(themeDisplay); userName = "******"user\" href=\"" + userDisplayURL + "\">" + HtmlUtil.escape(userName) + "</a>"; return userName; } catch (Exception e) { return StringPool.BLANK; } }
public MBMessage addPrivateMessageBranch( long userId, long parentMBMessageId, String body, List<ObjectValuePair<String, InputStream>> inputStreamOVPs, ThemeDisplay themeDisplay) throws PortalException { long mbThreadId = 0; MBMessage parentMessage = MBMessageLocalServiceUtil.getMBMessage(parentMBMessageId); List<User> recipients = new ArrayList<>(); recipients.add(UserLocalServiceUtil.getUser(parentMessage.getUserId())); return addPrivateMessage( userId, mbThreadId, parentMBMessageId, recipients, parentMessage.getSubject(), body, inputStreamOVPs, themeDisplay); }
@Test public void testUnassignUserFromRequiredGroups() throws Exception { long[] userIds = addUsers(); long[] standardGroupIds = addStandardGroups(); long[] requiredGroupIds = addRequiredGroups(); User user = UserLocalServiceUtil.getUser(userIds[0]); List<Group> groups = user.getGroups(); Assert.assertEquals(1, groups.size()); long[] userGroupIds = ArrayUtil.append(standardGroupIds, requiredGroupIds, new long[] {user.getGroupId()}); MembershipPolicyTestUtil.updateUser( user, null, null, userGroupIds, null, Collections.<UserGroupRole>emptyList()); groups = user.getGroups(); Assert.assertEquals(userGroupIds.length, groups.size()); MembershipPolicyTestUtil.updateUser( user, null, null, requiredGroupIds, null, Collections.<UserGroupRole>emptyList()); groups = user.getGroups(); Assert.assertEquals(requiredGroupIds.length, groups.size()); }
@Override protected void doExportStagedModel( PortletDataContext portletDataContext, DLFileEntryType fileEntryType) throws Exception { Element fileEntryTypeElement = portletDataContext.getExportDataElement(fileEntryType); List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures(); for (DDMStructure ddmStructure : ddmStructures) { com.liferay.dynamic.data.mapping.model.DDMStructure structure = _ddmStructureLocalService.getStructure(ddmStructure.getStructureId()); Element referenceElement = StagedModelDataHandlerUtil.exportReferenceStagedModel( portletDataContext, fileEntryType, structure, PortletDataContext.REFERENCE_TYPE_STRONG); referenceElement.addAttribute( "structure-id", StringUtil.valueOf(ddmStructure.getStructureId())); } long defaultUserId = UserLocalServiceUtil.getDefaultUserId(fileEntryType.getCompanyId()); if (defaultUserId == fileEntryType.getUserId()) { fileEntryTypeElement.addAttribute("preloaded", "true"); } portletDataContext.addClassedModel( fileEntryTypeElement, ExportImportPathUtil.getModelPath(fileEntryType), fileEntryType); }
// TODO: allow for dynamic user url building classes to be injected private void addUsers(Element element, Group suppliedGroup, ThemeDisplay themeDisplay) throws PortalException, SystemException { // get all users List<User> users = UserLocalServiceUtil.getGroupUsers(suppliedGroup.getGroupId()); // we're only displaying users with blogs for now for (User u : users) { Group usersOwnGroup = GroupLocalServiceUtil.getUserGroup(suppliedGroup.getCompanyId(), u.getUserId()); int count = BlogsEntryLocalServiceUtil.getGroupEntriesCount(usersOwnGroup.getGroupId()); List<BlogsEntry> entries = BlogsEntryLocalServiceUtil.getGroupEntries(usersOwnGroup.getGroupId(), 0, count); // only add if the user has blogs if (entries != null && entries.size() > 0) { // index the user, as well StringBuffer baseUrl = new StringBuffer(themeDisplay.getPortalURL()); // TODO figure out where web comes from baseUrl.append("/web"); baseUrl.append(usersOwnGroup.getFriendlyURL()); Element userUrlElement = element.addElement("url"); userUrlElement.addElement("loc").addText(encodeXML(baseUrl.toString())); userUrlElement.addElement("changefreq").addText("daily"); } } }
public static void sendPassword( ActionRequest actionRequest, String fromName, String fromAddress, String toAddress, String subject, String body) throws Exception { HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); if (!company.isSendPassword() && !company.isSendPasswordResetLink()) { return; } ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest); UserLocalServiceUtil.sendPassword( company.getCompanyId(), toAddress, fromName, fromAddress, subject, body, serviceContext); SessionMessages.add(actionRequest, "request_processed", toAddress); }
@Override public Map<String, String> getReferenceAttributes( PortletDataContext portletDataContext, DLFileEntryType fileEntryType) { Map<String, String> referenceAttributes = new HashMap<>(); referenceAttributes.put("file-entry-type-key", fileEntryType.getFileEntryTypeKey()); long defaultUserId = UserConstants.USER_ID_DEFAULT; try { defaultUserId = UserLocalServiceUtil.getDefaultUserId(fileEntryType.getCompanyId()); } catch (Exception e) { } boolean preloaded = false; if ((fileEntryType.getFileEntryTypeId() == DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) || (defaultUserId == fileEntryType.getUserId())) { preloaded = true; } referenceAttributes.put("preloaded", String.valueOf(preloaded)); return referenceAttributes; }
private static void _populateThreadLocalsFromContext(Map<String, Serializable> context) { long companyId = GetterUtil.getLong(context.get("companyId")); if (companyId > 0) { CompanyThreadLocal.setCompanyId(companyId); } Locale defaultLocale = (Locale) context.get("defaultLocale"); if (defaultLocale != null) { LocaleThreadLocal.setDefaultLocale(defaultLocale); } long groupId = GetterUtil.getLong(context.get("groupId")); if (groupId > 0) { GroupThreadLocal.setGroupId(groupId); } String principalName = GetterUtil.getString(context.get("principalName")); if (Validator.isNotNull(principalName)) { PrincipalThreadLocal.setName(principalName); } PermissionChecker permissionChecker = null; if (Validator.isNotNull(principalName)) { try { User user = UserLocalServiceUtil.fetchUser(PrincipalThreadLocal.getUserId()); permissionChecker = PermissionCheckerFactoryUtil.create(user); } catch (Exception e) { throw new RuntimeException(e); } } if (permissionChecker != null) { PermissionThreadLocal.setPermissionChecker(permissionChecker); } String principalPassword = GetterUtil.getString(context.get("principalPassword")); if (Validator.isNotNull(principalPassword)) { PrincipalThreadLocal.setPassword(principalPassword); } Locale siteDefaultLocale = (Locale) context.get("siteDefaultLocale"); if (siteDefaultLocale != null) { LocaleThreadLocal.setSiteDefaultLocale(siteDefaultLocale); } Locale themeDisplayLocale = (Locale) context.get("themeDisplayLocale"); if (themeDisplayLocale != null) { LocaleThreadLocal.setThemeDisplayLocale(themeDisplayLocale); } }
private static User _getUser(HttpServletRequest request) throws Exception { HttpSession session = request.getSession(); if (PortalSessionThreadLocal.getHttpSession() == null) { PortalSessionThreadLocal.setHttpSession(session); } User user = PortalUtil.getUser(request); if (user != null) { return user; } String userIdString = (String) session.getAttribute("j_username"); String password = (String) session.getAttribute("j_password"); if ((userIdString != null) && (password != null)) { long userId = GetterUtil.getLong(userIdString); user = UserLocalServiceUtil.getUser(userId); } else { long companyId = PortalUtil.getCompanyId(request); Company company = CompanyLocalServiceUtil.getCompany(companyId); user = company.getDefaultUser(); } return user; }