List of usage examples for com.liferay.portal.kernel.servlet PortalSessionThreadLocal getHttpSession
public static HttpSession getHttpSession()
From source file:com.liferay.document.library.repository.cmis.internal.CMISSessionCache.java
License:Open Source License
public Session get(String key) { HttpSession httpSession = PortalSessionThreadLocal.getHttpSession(); if (httpSession == null) { return null; }//w w w . jav a2 s . c o m TransientValue<Session> transientValue = (TransientValue<Session>) httpSession.getAttribute(key); if (transientValue == null) { return null; } Object value = transientValue.getValue(); if (value instanceof Session) { return (Session) value; } httpSession.removeAttribute(key); return null; }
From source file:com.liferay.document.library.repository.cmis.internal.CMISSessionCache.java
License:Open Source License
public void put(String key, Session session) { HttpSession httpSession = PortalSessionThreadLocal.getHttpSession(); if (httpSession == null) { if (_log.isWarnEnabled()) { _log.warn("Unable to get HTTP session"); }// www . j ava 2s. c o m return; } httpSession.setAttribute(key, new TransientValue<>(session)); _sessions.putIfAbsent(httpSession.getId(), httpSession); }
From source file:com.liferay.document.library.repository.external.cache.ConnectionCache.java
License:Open Source License
public T getConnection() throws RepositoryException { T connection = null;/*from ww w . j a v a2s . co m*/ HttpSession httpSession = PortalSessionThreadLocal.getHttpSession(); if (httpSession != null) { TransientValue<T> transientValue = (TransientValue<T>) httpSession.getAttribute(_sessionKey); if (transientValue != null) { connection = transientValue.getValue(); } } else { connection = _connectionThreadLocal.get(); } if (connection != null) { return connection; } connection = _connectionBuilder.buildConnection(); if (httpSession != null) { TransientValue<T> transientValue = new TransientValue<>(connection); httpSession.setAttribute(_sessionKey, transientValue); } _connectionThreadLocal.set(connection); return connection; }
From source file:com.liferay.documentlibrary.hook.filter.DLRecordFilter.java
License:Open Source License
/** * Get logged in user . // w w w . j av a2 s.co m * If user is not logged in then it will return default user. * @param request * @return * @throws Exception */ 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; }
From source file:com.liferay.google.drive.repository.GoogleDriveRepository.java
License:Open Source License
protected GoogleDriveSession getGoogleDriveSession() throws PortalException { GoogleDriveSession googleDriveSession = null; HttpSession httpSession = PortalSessionThreadLocal.getHttpSession(); if (httpSession != null) { TransientValue<GoogleDriveSession> transientValue = (TransientValue<GoogleDriveSession>) httpSession .getAttribute(GoogleDriveSession.class.getName()); if (transientValue != null) { googleDriveSession = transientValue.getValue(); }/*w w w .ja v a2 s . com*/ } else { googleDriveSession = _googleDriveSessionThreadLocal.get(); } if (googleDriveSession != null) { return googleDriveSession; } try { googleDriveSession = buildGoogleDriveSession(); } catch (Exception e) { throw new PrincipalException(e); } if (httpSession != null) { httpSession.setAttribute(GoogleDriveSession.class.getName(), new TransientValue<GoogleDriveSession>(googleDriveSession)); } else { _googleDriveSessionThreadLocal.set(googleDriveSession); } return googleDriveSession; }
From source file:com.liferay.repository.external.cache.ConnectionCache.java
License:Open Source License
public T getConnection() throws RepositoryException { T connection = null;/*w w w. ja va 2 s. c om*/ HttpSession httpSession = PortalSessionThreadLocal.getHttpSession(); if (httpSession != null) { TransientValue<T> transientValue = (TransientValue<T>) httpSession.getAttribute(_sessionKey); if (transientValue != null) { connection = transientValue.getValue(); } } else { connection = _connectionThreadLocal.get(); } if (connection != null) { return connection; } connection = _connectionBuilder.buildConnection(); if (httpSession != null) { TransientValue<T> transientValue = new TransientValue<T>(connection); httpSession.setAttribute(_sessionKey, transientValue); } _connectionThreadLocal.set(connection); return connection; }
From source file:com.liferay.sync.internal.servlet.SyncDownloadServlet.java
License:Open Source License
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try {/*from w w w. j a v a 2s .c o m*/ HttpSession session = request.getSession(); if (PortalSessionThreadLocal.getHttpSession() == null) { PortalSessionThreadLocal.setHttpSession(session); } User user = _portal.getUser(request); String syncUuid = request.getHeader("Sync-UUID"); if (syncUuid != null) { SyncDevice syncDevice = SyncDeviceLocalServiceUtil.fetchSyncDeviceByUuidAndCompanyId(syncUuid, user.getCompanyId()); if (syncDevice != null) { syncDevice.checkStatus(); } } PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user); PermissionThreadLocal.setPermissionChecker(permissionChecker); String path = _http.fixPath(request.getPathInfo()); String[] pathArray = StringUtil.split(path, CharPool.SLASH); if (pathArray[0].equals("image")) { long imageId = GetterUtil.getLong(pathArray[1]); sendImage(request, response, imageId); } else if (pathArray[0].equals("zip")) { String zipFileIds = ParamUtil.get(request, "zipFileIds", StringPool.BLANK); if (Validator.isNull(zipFileIds)) { throw new IllegalArgumentException("Missing parameter zipFileIds"); } JSONArray zipFileIdsJSONArray = JSONFactoryUtil.createJSONArray(zipFileIds); sendZipFile(response, user.getUserId(), zipFileIdsJSONArray); } else if (pathArray[0].equals("zipfolder")) { long repositoryId = ParamUtil.getLong(request, "repositoryId"); long folderId = ParamUtil.getLong(request, "folderId"); if (repositoryId == 0) { throw new IllegalArgumentException("Missing parameter repositoryId"); } else if (folderId == 0) { throw new IllegalArgumentException("Missing parameter folderId"); } sendZipFolder(response, user.getUserId(), repositoryId, folderId); } else { long groupId = GetterUtil.getLong(pathArray[0]); String fileUuid = pathArray[1]; Group group = _groupLocalService.fetchGroup(groupId); if ((group == null) || !_syncUtil.isSyncEnabled(group)) { response.setHeader(_ERROR_HEADER, SyncSiteUnavailableException.class.getName()); ServletResponseUtil.write(response, new byte[0]); return; } boolean patch = ParamUtil.getBoolean(request, "patch"); if (patch) { sendPatch(request, response, user.getUserId(), groupId, fileUuid); } else { sendFile(request, response, user.getUserId(), groupId, fileUuid); } } } catch (NoSuchFileEntryException nsfee) { _portal.sendError(HttpServletResponse.SC_NOT_FOUND, nsfee, request, response); } catch (NoSuchFileVersionException nsfve) { _portal.sendError(HttpServletResponse.SC_NOT_FOUND, nsfve, request, response); } catch (Exception e) { _portal.sendError(e, request, response); } }
From source file:com.liferay.sync.servlet.DownloadServlet.java
License:Open Source License
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try {/* w w w.j a v a 2s . c o m*/ HttpSession session = request.getSession(); if (PortalSessionThreadLocal.getHttpSession() == null) { PortalSessionThreadLocal.setHttpSession(session); } User user = PortalUtil.getUser(request); PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user); PermissionThreadLocal.setPermissionChecker(permissionChecker); String path = HttpUtil.fixPath(request.getPathInfo()); String[] pathArray = StringUtil.split(path, CharPool.SLASH); if (pathArray[0].equals("image")) { long imageId = GetterUtil.getLong(pathArray[1]); sendImage(response, imageId); } else { long groupId = GetterUtil.getLong(pathArray[0]); String uuid = pathArray[1]; boolean patch = ParamUtil.getBoolean(request, "patch"); if (patch) { sendPatch(request, response, user, groupId, uuid); } else { sendFile(request, response, groupId, uuid); } } } catch (NoSuchFileEntryException nsfee) { PortalUtil.sendError(HttpServletResponse.SC_NOT_FOUND, nsfee, request, response); } catch (Exception e) { PortalUtil.sendError(e, request, response); } }