001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.openid.action;
022:
023: import com.liferay.portal.action.OpenIdRequestAction;
024: import com.liferay.portal.kernel.util.Constants;
025: import com.liferay.portal.kernel.util.ParamUtil;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.portal.struts.ActionConstants;
028: import com.liferay.portal.struts.PortletAction;
029: import com.liferay.portal.theme.ThemeDisplay;
030: import com.liferay.portal.util.PortalUtil;
031: import com.liferay.portal.util.WebKeys;
032: import com.liferay.util.servlet.SessionErrors;
033:
034: import javax.portlet.ActionRequest;
035: import javax.portlet.ActionResponse;
036: import javax.portlet.PortletConfig;
037: import javax.portlet.RenderRequest;
038: import javax.portlet.RenderResponse;
039:
040: import javax.servlet.http.HttpServletRequest;
041: import javax.servlet.http.HttpServletResponse;
042: import javax.servlet.jsp.PageContext;
043:
044: import org.apache.commons.logging.Log;
045: import org.apache.commons.logging.LogFactory;
046: import org.apache.struts.action.ActionForm;
047: import org.apache.struts.action.ActionForward;
048: import org.apache.struts.action.ActionMapping;
049:
050: import org.openid4java.OpenIDException;
051:
052: /**
053: * <a href="ViewAction.java.html"><b><i>View Source</i></b></a>
054: *
055: * @author Jorge Ferrer
056: *
057: */
058: public class ViewAction extends PortletAction {
059:
060: public void processAction(ActionMapping mapping, ActionForm form,
061: PortletConfig config, ActionRequest req, ActionResponse res)
062: throws Exception {
063:
064: String cmd = req.getParameter(Constants.CMD);
065:
066: ThemeDisplay themeDisplay = (ThemeDisplay) req
067: .getAttribute(WebKeys.THEME_DISPLAY);
068:
069: if (req.getRemoteUser() != null) {
070: res.sendRedirect(themeDisplay.getPathMain());
071: } else if (Validator.isNotNull(cmd)) {
072: try {
073: login(themeDisplay, req, res);
074: } catch (Exception e) {
075: if (e instanceof OpenIDException) {
076: if (_log.isInfoEnabled()) {
077: _log
078: .info("Error communicating with OpenID provider: "
079: + e.getMessage());
080: }
081:
082: SessionErrors.add(req, e.getClass().getName());
083: } else {
084: req.setAttribute(PageContext.EXCEPTION, e);
085:
086: setForward(req, ActionConstants.COMMON_ERROR);
087: }
088: }
089: }
090: }
091:
092: public ActionForward render(ActionMapping mapping, ActionForm form,
093: PortletConfig config, RenderRequest req, RenderResponse res)
094: throws Exception {
095:
096: return mapping.findForward("portlet.open_id.view");
097: }
098:
099: protected void login(ThemeDisplay themeDisplay, ActionRequest req,
100: ActionResponse res) throws Exception {
101:
102: HttpServletRequest httpReq = PortalUtil
103: .getHttpServletRequest(req);
104: HttpServletResponse httpRes = PortalUtil
105: .getHttpServletResponse(res);
106:
107: String openId = ParamUtil.getString(req, "openId");
108:
109: OpenIdRequestAction.sendOpenIdRequest(themeDisplay, httpReq,
110: httpRes, openId);
111: }
112:
113: private static Log _log = LogFactory.getLog(ViewAction.class);
114:
115: }
|