Java tutorial
/** * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.portlet.monitoring.action; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.servlet.PortalSessionContext; import com.liferay.portal.kernel.servlet.SessionErrors; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.security.auth.PrincipalException; import com.liferay.portal.security.permission.PermissionChecker; import com.liferay.portal.struts.PortletAction; import com.liferay.portal.theme.ThemeDisplay; import com.liferay.portal.util.WebKeys; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletConfig; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import javax.servlet.http.HttpSession; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; /** * @author Brian Wing Shun Chan */ public class EditSessionAction extends PortletAction { @Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); if (!permissionChecker.isOmniadmin()) { SessionErrors.add(actionRequest, PrincipalException.class.getName()); setForward(actionRequest, "portlet.monitoring.error"); return; } invalidateSession(actionRequest); sendRedirect(actionRequest, actionResponse); } @Override public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse) throws Exception { return mapping.findForward(getForward(renderRequest, "portlet.monitoring.edit_session")); } protected void invalidateSession(ActionRequest actionRequest) throws Exception { String sessionId = ParamUtil.getString(actionRequest, "sessionId"); HttpSession userSession = PortalSessionContext.get(sessionId); if (userSession != null) { try { if (!actionRequest.getPortletSession().getId().equals(sessionId)) { userSession.invalidate(); } } catch (Exception e) { _log.error(e); } } } private static Log _log = LogFactoryUtil.getLog(EditSessionAction.class); }