List of usage examples for com.liferay.portal.kernel.util Http HTTPS
String HTTPS
To view the source code for com.liferay.portal.kernel.util Http HTTPS.
Click Source Link
From source file:com.liferay.dynamic.data.mapping.data.provider.internal.rest.DDMRESTDataProvider.java
License:Open Source License
protected DDMDataProviderResponse doGetData(DDMDataProviderRequest ddmDataProviderRequest) { DDMDataProviderContext ddmDataProviderContext = ddmDataProviderRequest.getDDMDataProviderContext(); DDMRESTDataProviderSettings ddmRESTDataProviderSettings = ddmDataProviderContext .getSettingsInstance(DDMRESTDataProviderSettings.class); HttpRequest httpRequest = HttpRequest.get(ddmRESTDataProviderSettings.url()); if (StringUtil.startsWith(ddmRESTDataProviderSettings.url(), Http.HTTPS)) { httpRequest.trustAllCerts(true); }//from ww w . j a v a 2 s . c o m if (Validator.isNotNull(ddmRESTDataProviderSettings.username())) { httpRequest.basicAuthentication(ddmRESTDataProviderSettings.username(), ddmRESTDataProviderSettings.password()); } setRequestParameters(ddmDataProviderRequest, ddmRESTDataProviderSettings, httpRequest); String cacheKey = getCacheKey(httpRequest); DDMRESTDataProviderResult ddmRESTDataProviderResult = _portalCache.get(cacheKey); if ((ddmRESTDataProviderResult != null) && ddmRESTDataProviderSettings.cacheable()) { return ddmRESTDataProviderResult.getDDMDataProviderResponse(); } HttpResponse httpResponse = httpRequest.send(); DocumentContext documentContext = JsonPath.parse(httpResponse.body()); DDMDataProviderResponse ddmDataProviderResponse = createDDMDataProviderResponse(documentContext, ddmDataProviderRequest, ddmRESTDataProviderSettings); if (ddmRESTDataProviderSettings.cacheable()) { _portalCache.put(cacheKey, new DDMRESTDataProviderResult(ddmDataProviderResponse)); } return ddmDataProviderResponse; }
From source file:com.liferay.message.boards.internal.pop.MessageListenerImpl.java
License:Open Source License
@Override public void deliver(String from, String recipient, Message message) throws MessageListenerException { List<ObjectValuePair<String, InputStream>> inputStreamOVPs = null; try {//from w ww. ja v a 2 s .c o m StopWatch stopWatch = new StopWatch(); stopWatch.start(); if (_log.isDebugEnabled()) { _log.debug("Deliver message from " + from + " to " + recipient); } String messageIdString = getMessageIdString(recipient, message); Company company = getCompany(messageIdString); if (_log.isDebugEnabled()) { _log.debug("Message id " + messageIdString); } long parentMessageId = MBUtil.getMessageId(messageIdString); if (_log.isDebugEnabled()) { _log.debug("Parent message id " + parentMessageId); } MBMessage parentMessage = null; if (parentMessageId > 0) { parentMessage = _mbMessageLocalService.fetchMBMessage(parentMessageId); } if (_log.isDebugEnabled()) { _log.debug("Parent message " + parentMessage); } long groupId = 0; long categoryId = MBUtil.getCategoryId(messageIdString); MBCategory category = _mbCategoryLocalService.fetchMBCategory(categoryId); if (category == null) { categoryId = MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID; if (parentMessage != null) { groupId = parentMessage.getGroupId(); } } else { groupId = category.getGroupId(); } if (_log.isDebugEnabled()) { _log.debug("Group id " + groupId); _log.debug("Category id " + categoryId); } User user = _userLocalService.getUserByEmailAddress(company.getCompanyId(), from); String subject = null; if (parentMessage != null) { subject = MBUtil.getSubjectForEmail(parentMessage); } MBMailMessage mbMailMessage = new MBMailMessage(); MBUtil.collectPartContent(message, mbMailMessage); inputStreamOVPs = mbMailMessage.getInputStreamOVPs(); PermissionCheckerUtil.setThreadValues(user); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAttribute("propagatePermissions", Boolean.TRUE); String portletId = PortletProviderUtil.getPortletId(MBMessage.class.getName(), PortletProvider.Action.VIEW); serviceContext.setLayoutFullURL(PortalUtil.getLayoutFullURL(groupId, portletId, StringUtil.equalsIgnoreCase(Http.HTTPS, PropsValues.WEB_SERVER_PROTOCOL))); serviceContext.setScopeGroupId(groupId); if (parentMessage == null) { _mbMessageService.addMessage(groupId, categoryId, subject, mbMailMessage.getBody(), MBMessageConstants.DEFAULT_FORMAT, inputStreamOVPs, false, 0.0, true, serviceContext); } else { _mbMessageService.addMessage(parentMessage.getMessageId(), subject, mbMailMessage.getBody(), MBMessageConstants.DEFAULT_FORMAT, inputStreamOVPs, false, 0.0, true, serviceContext); } if (_log.isDebugEnabled()) { _log.debug("Delivering message takes " + stopWatch.getTime() + " ms"); } } catch (PrincipalException pe) { if (_log.isDebugEnabled()) { _log.debug("Prevented unauthorized post from " + from); } throw new MessageListenerException(pe); } catch (Exception e) { _log.error(e, e); throw new MessageListenerException(e); } finally { if (inputStreamOVPs != null) { for (ObjectValuePair<String, InputStream> inputStreamOVP : inputStreamOVPs) { InputStream inputStream = inputStreamOVP.getValue(); StreamUtil.cleanUp(inputStream); } } PermissionCheckerUtil.setThreadValues(null); } }
From source file:com.liferay.portlet.login.util.LoginUtil.java
License:Open Source License
public static void login(HttpServletRequest request, HttpServletResponse response, String login, String password, boolean rememberMe, String authType) throws Exception { CookieKeys.validateSupportCookie(request); HttpSession session = request.getSession(); Company company = PortalUtil.getCompany(request); long userId = getAuthenticatedUserId(request, login, password, authType); if (!PropsValues.AUTH_SIMULTANEOUS_LOGINS) { Map<String, UserTracker> sessionUsers = LiveUsers.getSessionUsers(company.getCompanyId()); List<UserTracker> userTrackers = new ArrayList<UserTracker>(sessionUsers.values()); for (UserTracker userTracker : userTrackers) { if (userId != userTracker.getUserId()) { continue; }//from w ww . j a v a 2s .c o m JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); ClusterNode clusterNode = ClusterExecutorUtil.getLocalClusterNode(); if (clusterNode != null) { jsonObject.put("clusterNodeId", clusterNode.getClusterNodeId()); } jsonObject.put("command", "signOut"); long companyId = CompanyLocalServiceUtil.getCompanyIdByUserId(userId); jsonObject.put("companyId", companyId); jsonObject.put("sessionId", userTracker.getSessionId()); jsonObject.put("userId", userId); MessageBusUtil.sendMessage(DestinationNames.LIVE_USERS, jsonObject.toString()); } } if (PropsValues.SESSION_ENABLE_PHISHING_PROTECTION) { session = renewSession(request, session); } // Set cookies String domain = CookieKeys.getDomain(request); User user = UserLocalServiceUtil.getUserById(userId); String userIdString = String.valueOf(userId); session.setAttribute("j_username", userIdString); if (PropsValues.PORTAL_JAAS_PLAIN_PASSWORD) { session.setAttribute("j_password", password); } else { session.setAttribute("j_password", user.getPassword()); } session.setAttribute("j_remoteuser", userIdString); if (PropsValues.SESSION_STORE_PASSWORD) { session.setAttribute(WebKeys.USER_PASSWORD, password); } Cookie companyIdCookie = new Cookie(CookieKeys.COMPANY_ID, String.valueOf(company.getCompanyId())); if (Validator.isNotNull(domain)) { companyIdCookie.setDomain(domain); } companyIdCookie.setPath(StringPool.SLASH); Cookie idCookie = new Cookie(CookieKeys.ID, Encryptor.encrypt(company.getKeyObj(), userIdString)); if (Validator.isNotNull(domain)) { idCookie.setDomain(domain); } idCookie.setPath(StringPool.SLASH); Cookie passwordCookie = new Cookie(CookieKeys.PASSWORD, Encryptor.encrypt(company.getKeyObj(), password)); if (Validator.isNotNull(domain)) { passwordCookie.setDomain(domain); } passwordCookie.setPath(StringPool.SLASH); Cookie rememberMeCookie = new Cookie(CookieKeys.REMEMBER_ME, Boolean.TRUE.toString()); if (Validator.isNotNull(domain)) { rememberMeCookie.setDomain(domain); } rememberMeCookie.setPath(StringPool.SLASH); int loginMaxAge = PropsValues.COMPANY_SECURITY_AUTO_LOGIN_MAX_AGE; String userUUID = userIdString.concat(StringPool.PERIOD).concat(String.valueOf(System.nanoTime())); Cookie userUUIDCookie = new Cookie(CookieKeys.USER_UUID, Encryptor.encrypt(company.getKeyObj(), userUUID)); userUUIDCookie.setPath(StringPool.SLASH); session.setAttribute(WebKeys.USER_UUID, userUUID); if (PropsValues.SESSION_DISABLED) { rememberMe = true; } if (rememberMe) { companyIdCookie.setMaxAge(loginMaxAge); idCookie.setMaxAge(loginMaxAge); passwordCookie.setMaxAge(loginMaxAge); rememberMeCookie.setMaxAge(loginMaxAge); userUUIDCookie.setMaxAge(loginMaxAge); } else { // This was explicitly changed from 0 to -1 so that the cookie lasts // as long as the browser. This allows an external servlet wrapped // in AutoLoginFilter to work throughout the client connection. The // cookies ARE removed on an actual logout, so there is no security // issue. See LEP-4678 and LEP-5177. companyIdCookie.setMaxAge(-1); idCookie.setMaxAge(-1); passwordCookie.setMaxAge(-1); rememberMeCookie.setMaxAge(0); userUUIDCookie.setMaxAge(-1); } Cookie loginCookie = new Cookie(CookieKeys.LOGIN, login); if (Validator.isNotNull(domain)) { loginCookie.setDomain(domain); } loginCookie.setMaxAge(loginMaxAge); loginCookie.setPath(StringPool.SLASH); Cookie screenNameCookie = new Cookie(CookieKeys.SCREEN_NAME, Encryptor.encrypt(company.getKeyObj(), user.getScreenName())); if (Validator.isNotNull(domain)) { screenNameCookie.setDomain(domain); } screenNameCookie.setMaxAge(loginMaxAge); screenNameCookie.setPath(StringPool.SLASH); boolean secure = request.isSecure(); if (secure && !PropsValues.COMPANY_SECURITY_AUTH_REQUIRES_HTTPS && !StringUtil.equalsIgnoreCase(Http.HTTPS, PropsValues.WEB_SERVER_PROTOCOL)) { Boolean httpsInitial = (Boolean) session.getAttribute(WebKeys.HTTPS_INITIAL); if ((httpsInitial == null) || !httpsInitial.booleanValue()) { secure = false; } } CookieKeys.addCookie(request, response, companyIdCookie, secure); CookieKeys.addCookie(request, response, idCookie, secure); CookieKeys.addCookie(request, response, userUUIDCookie, secure); if (rememberMe) { CookieKeys.addCookie(request, response, loginCookie, secure); CookieKeys.addCookie(request, response, passwordCookie, secure); CookieKeys.addCookie(request, response, rememberMeCookie, secure); CookieKeys.addCookie(request, response, screenNameCookie, secure); } AuthenticatedUserUUIDStoreUtil.register(userUUID); }
From source file:com.twelve.capital.external.feed.util.HttpImpl.java
License:Open Source License
@Override public String getProtocol(boolean secure) { if (!secure) { return Http.HTTP; } return Http.HTTPS; }
From source file:com.twelve.capital.external.feed.util.HttpImpl.java
License:Open Source License
@Override public boolean isSecure(String url) { String protocol = getProtocol(url); return StringUtil.equalsIgnoreCase(protocol, Http.HTTPS); }
From source file:com.twelve.capital.external.feed.util.HttpImpl.java
License:Open Source License
@Override public String protocolize(String url, int port, boolean secure) { if (Validator.isNull(url)) { return url; }//from ww w . j av a 2s . co m try { URL urlObj = new URL(url); String protocol = Http.HTTP; if (secure) { protocol = Http.HTTPS; } urlObj = new URL(protocol, urlObj.getHost(), port, urlObj.getFile()); return urlObj.toString(); } catch (Exception e) { return url; } }
From source file:com.twelve.capital.external.feed.util.HttpImpl.java
License:Open Source License
/** * This method only uses the default Commons HttpClient implementation when * the URL object represents a HTTP resource. The URL object could also * represent a file or some JNDI resource. In that case, the default Java * implementation is used.//from w w w. j ava2s . co m * * @param url the URL * @return A string representation of the resource referenced by the URL * object * @throws IOException if an IO exception occurred */ @Override public String URLtoString(URL url) throws IOException { String xml = null; if (url == null) { return null; } String protocol = StringUtil.toLowerCase(url.getProtocol()); if (protocol.startsWith(Http.HTTP) || protocol.startsWith(Http.HTTPS)) { return URLtoString(url.toString()); } URLConnection urlConnection = url.openConnection(); InputStream inputStream = urlConnection.getInputStream(); UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream(); byte[] bytes = new byte[512]; for (int i = inputStream.read(bytes, 0, 512); i != -1; i = inputStream.read(bytes, 0, 512)) { unsyncByteArrayOutputStream.write(bytes, 0, i); } xml = new String(unsyncByteArrayOutputStream.unsafeGetByteArray(), 0, unsyncByteArrayOutputStream.size()); inputStream.close(); unsyncByteArrayOutputStream.close(); return xml; }