List of usage examples for com.liferay.portal.kernel.servlet SessionErrors add
public static void add(PortletRequest portletRequest, String key)
From source file:com.liferay.login.authentication.openid.connect.web.internal.portlet.action.OpenIdConnectLoginRequestMVCActionCommand.java
License:Open Source License
@Override public void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { try {//from www . j a va 2 s. co m String openIdConnectProviderName = ParamUtil.getString(actionRequest, OpenIdConnectWebKeys.OPEN_ID_CONNECT_PROVIDER_NAME); HttpServletRequest httpServletRequest = _portal.getHttpServletRequest(actionRequest); httpServletRequest = _portal.getOriginalServletRequest(httpServletRequest); HttpServletResponse httpServletResponse = _portal.getHttpServletResponse(actionResponse); _openIdConnectServiceHandler.requestAuthentication(openIdConnectProviderName, httpServletRequest, httpServletResponse); } catch (Exception e) { if (e instanceof OpenIdConnectServiceException) { if (_log.isInfoEnabled()) { _log.info("Unable to communicate with OpenID Connect provider: " + e.getMessage()); } SessionErrors.add(actionRequest, e.getClass()); } else if (e instanceof UserEmailAddressException.MustNotBeDuplicate) { SessionErrors.add(actionRequest, e.getClass()); } else { _log.error("Unable to process the OpenID login", e); _portal.sendError(e, actionRequest, actionResponse); } } }
From source file:com.liferay.login.authentication.openid.web.internal.portlet.action.OpenIdLoginMVCActionCommand.java
License:Open Source License
@Override public void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); if (!_openId.isEnabled(themeDisplay.getCompanyId())) { throw new PrincipalException.MustBeEnabled(themeDisplay.getCompanyId(), OpenId.class.getName()); }/*from www . j a va 2 s. c o m*/ if (actionRequest.getRemoteUser() != null) { actionResponse.sendRedirect(themeDisplay.getPathMain()); return; } String cmd = ParamUtil.getString(actionRequest, Constants.CMD); try { if (cmd.equals(Constants.READ)) { String redirect = _openIdServiceHandler.readResponse(themeDisplay, actionRequest); if (Validator.isNull(redirect)) { redirect = themeDisplay.getURLSignIn(); } redirect = _portal.escapeRedirect(redirect); actionResponse.sendRedirect(redirect); } else { _openIdServiceHandler.sendRequest(themeDisplay, actionRequest, actionResponse); } } catch (Exception e) { if (e instanceof OpenIdServiceException) { if (_log.isInfoEnabled()) { _log.info("Error communicating with OpenID provider: " + e.getMessage()); } SessionErrors.add(actionRequest, e.getClass()); } else if (e instanceof UserEmailAddressException.MustNotBeDuplicate) { SessionErrors.add(actionRequest, e.getClass()); } else { _log.error("Error processing the OpenID login", e); _portal.sendError(e, actionRequest, actionResponse); } } }
From source file:com.liferay.login.web.internal.portlet.action.CreateAnonymousAccountMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletConfig portletConfig = (PortletConfig) actionRequest .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG); String portletName = portletConfig.getPortletName(); if (!portletName.equals(LoginPortletKeys.FAST_LOGIN)) { throw new PrincipalException("Unable to create anonymous account"); }// w ww . j a v a2s . co m if (actionRequest.getRemoteUser() != null) { actionResponse.sendRedirect(themeDisplay.getPathMain()); return; } String cmd = ParamUtil.getString(actionRequest, Constants.CMD); String emailAddress = ParamUtil.getString(actionRequest, "emailAddress"); PortletURL portletURL = PortletURLFactoryUtil.create(actionRequest, LoginPortletKeys.FAST_LOGIN, PortletRequest.RENDER_PHASE); portletURL.setParameter("mvcRenderCommandName", "/login/login_redirect"); portletURL.setParameter("emailAddress", emailAddress); portletURL.setParameter("anonymousUser", Boolean.TRUE.toString()); portletURL.setWindowState(LiferayWindowState.POP_UP); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); try { if (cmd.equals(Constants.ADD)) { addAnonymousUser(actionRequest, actionResponse); sendRedirect(actionRequest, actionResponse, portletURL.toString()); } else if (cmd.equals(Constants.UPDATE)) { Company company = themeDisplay.getCompany(); if (!company.isStrangers()) { throw new PrincipalException.MustBeEnabled(company.getCompanyId(), PropsKeys.COMPANY_SECURITY_STRANGERS); } jsonObject = updateIncompleteUser(actionRequest, actionResponse); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } } catch (Exception e) { if (cmd.equals(Constants.UPDATE)) { jsonObject.putException(e); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); } else if (e instanceof UserEmailAddressException.MustNotBeDuplicate) { User user = _userLocalService.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress); if (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE) { SessionErrors.add(actionRequest, e.getClass()); } else { sendRedirect(actionRequest, actionResponse, portletURL.toString()); } } else if (e instanceof CaptchaConfigurationException || e instanceof CaptchaTextException || e instanceof CompanyMaxUsersException || e instanceof ContactNameException || e instanceof EmailAddressException || e instanceof GroupFriendlyURLException || e instanceof UserEmailAddressException) { SessionErrors.add(actionRequest, e.getClass(), e); } else { _log.error("Unable to create anonymous account", e); _portal.sendError(e, actionRequest, actionResponse); } } }
From source file:com.liferay.login.web.internal.portlet.action.ForgotPasswordMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Company company = themeDisplay.getCompany(); if (!company.isSendPassword() && !company.isSendPasswordResetLink()) { throw new PrincipalException.MustBeEnabled(company.getCompanyId(), PropsKeys.COMPANY_SECURITY_SEND_PASSWORD, PropsKeys.COMPANY_SECURITY_SEND_PASSWORD_RESET_LINK); }//from www . j a va 2 s. com try { if (PropsValues.USERS_REMINDER_QUERIES_ENABLED) { checkReminderQueries(actionRequest, actionResponse); } else { checkCaptcha(actionRequest); sendPassword(actionRequest, actionResponse); } } catch (Exception e) { if (e instanceof CaptchaConfigurationException || e instanceof CaptchaTextException || e instanceof UserEmailAddressException) { SessionErrors.add(actionRequest, e.getClass()); } else if (e instanceof NoSuchUserException || e instanceof RequiredReminderQueryException || e instanceof SendPasswordException || e instanceof UserActiveException || e instanceof UserLockoutException || e instanceof UserReminderQueryException) { if (PropsValues.LOGIN_SECURE_FORGOT_PASSWORD) { sendRedirect(actionRequest, actionResponse, null); } else { SessionErrors.add(actionRequest, e.getClass(), e); } } else { _portal.sendError(e, actionRequest, actionResponse); } } }
From source file:com.liferay.marketplace.app.manager.web.internal.portlet.MarketplaceAppManagerPortlet.java
License:Open Source License
public void installLocalApp(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest); String fileName = GetterUtil.getString(uploadPortletRequest.getFileName("file")); File file = uploadPortletRequest.getFile("file"); byte[] bytes = FileUtil.getBytes(file); if (ArrayUtil.isEmpty(bytes)) { SessionErrors.add(actionRequest, UploadException.class.getName()); } else if (!fileName.endsWith(".jar") && !fileName.endsWith(".lpkg") && !fileName.endsWith(".war")) { throw new FileExtensionException(); } else {/*from w w w . j a va 2s . c o m*/ String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR); FileUtil.copyFile(file.toString(), deployDir + StringPool.SLASH + fileName); SessionMessages.add(actionRequest, "pluginUploaded"); } sendRedirect(actionRequest, actionResponse); }
From source file:com.liferay.marketplace.app.manager.web.internal.portlet.MarketplaceAppManagerPortlet.java
License:Open Source License
protected int doInstallRemoteApp(String url, ActionRequest actionRequest, boolean failOnError) throws Exception { int responseCode = HttpServletResponse.SC_OK; try {//from w w w . j a va2 s.c o m String fileName = null; Http.Options options = new Http.Options(); options.setFollowRedirects(false); options.setLocation(url); options.setPost(false); byte[] bytes = HttpUtil.URLtoByteArray(options); Http.Response response = options.getResponse(); responseCode = response.getResponseCode(); if ((responseCode == HttpServletResponse.SC_OK) && (bytes.length > 0)) { String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR); String destination = deployDir + StringPool.SLASH + fileName; File destinationFile = new File(destination); FileUtil.write(destinationFile, bytes); SessionMessages.add(actionRequest, "pluginDownloaded"); } else { if (failOnError) { SessionErrors.add(actionRequest, UploadException.class.getName()); } responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } } catch (MalformedURLException murle) { SessionErrors.add(actionRequest, "invalidUrl", murle); } catch (IOException ioe) { SessionErrors.add(actionRequest, "errorConnectingToUrl", ioe); } return responseCode; }
From source file:com.liferay.marketplace.appmanager.portlet.AppManagerPortlet.java
License:Open Source License
public void installApp(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); String installMethod = ParamUtil.getString(uploadPortletRequest, "installMethod"); if (installMethod.equals("local")) { String fileName = GetterUtil.getString(uploadPortletRequest.getFileName("file")); File file = uploadPortletRequest.getFile("file"); byte[] bytes = FileUtil.getBytes(file); if (ArrayUtil.isEmpty(bytes)) { SessionErrors.add(actionRequest, UploadException.class.getName()); } else {/* ww w . j av a2 s . c o m*/ String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR); FileUtil.copyFile(file.toString(), deployDir + StringPool.SLASH + fileName); SessionMessages.add(actionRequest, "pluginUploaded"); } } else { try { String url = ParamUtil.getString(uploadPortletRequest, "url"); URL urlObj = new URL(url); String host = urlObj.getHost(); if (host.endsWith("sf.net") || host.endsWith("sourceforge.net")) { doInstallSourceForgeApp(urlObj.getPath(), uploadPortletRequest, actionRequest); } else { doInstallRemoteApp(url, uploadPortletRequest, actionRequest, true); } } catch (MalformedURLException murle) { SessionErrors.add(actionRequest, "invalidUrl", murle); } } String redirect = ParamUtil.getString(uploadPortletRequest, "redirect"); actionResponse.sendRedirect(redirect); }
From source file:com.liferay.marketplace.appmanager.portlet.AppManagerPortlet.java
License:Open Source License
protected int doInstallRemoteApp(String url, UploadPortletRequest uploadPortletRequest, ActionRequest actionRequest, boolean failOnError) throws Exception { int responseCode = HttpServletResponse.SC_OK; String deploymentContext = ParamUtil.getString(uploadPortletRequest, "deploymentContext"); try {/*from w ww . j a va2 s . c om*/ String fileName = null; if (Validator.isNotNull(deploymentContext)) { fileName = DEPLOY_TO_PREFIX + deploymentContext + ".war"; } else { fileName = url.substring(url.lastIndexOf(CharPool.SLASH) + 1); int pos = fileName.lastIndexOf(CharPool.PERIOD); if (pos != -1) { deploymentContext = fileName.substring(0, pos); } } Http.Options options = new Http.Options(); options.setFollowRedirects(false); options.setLocation(url); options.setPortletRequest(actionRequest); options.setPost(false); String progressId = ParamUtil.getString(uploadPortletRequest, Constants.PROGRESS_ID); options.setProgressId(progressId); byte[] bytes = HttpUtil.URLtoByteArray(options); Http.Response response = options.getResponse(); responseCode = response.getResponseCode(); if ((responseCode == HttpServletResponse.SC_OK) && (bytes.length > 0)) { String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR); String destination = deployDir + StringPool.SLASH + fileName; File destinationFile = new File(destination); FileUtil.write(destinationFile, bytes); SessionMessages.add(actionRequest, "pluginDownloaded"); } else { if (failOnError) { SessionErrors.add(actionRequest, UploadException.class.getName()); } responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } } catch (MalformedURLException murle) { SessionErrors.add(actionRequest, "invalidUrl", murle); } catch (IOException ioe) { SessionErrors.add(actionRequest, "errorConnectingToUrl", ioe); } return responseCode; }
From source file:com.liferay.message.boards.web.internal.portlet.action.BanUserMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String cmd = ParamUtil.getString(actionRequest, Constants.CMD); try {//w w w.java2 s . c o m if (cmd.equals("ban")) { banUser(actionRequest); } else if (cmd.equals("unban")) { unbanUser(actionRequest); } } catch (PrincipalException pe) { SessionErrors.add(actionRequest, pe.getClass()); actionResponse.setRenderParameter("mvcPath", "/message_boards/error.jsp"); } }
From source file:com.liferay.message.boards.web.internal.portlet.action.BaseViewMVCRenderCommand.java
License:Open Source License
@Override public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException { try {//www . j av a 2 s . co m MBCategory category = ActionUtil.getCategory(renderRequest); renderRequest.setAttribute(WebKeys.MESSAGE_BOARDS_CATEGORY, category); } catch (BannedUserException | NoSuchCategoryException | PrincipalException e) { SessionErrors.add(renderRequest, e.getClass()); return "/message_boards/error.jsp"; } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new PortletException(e); } return _jspPath; }