1
22
23 package com.liferay.portlet.openid.action;
24
25 import com.liferay.portal.action.OpenIdRequestAction;
26 import com.liferay.portal.kernel.util.Constants;
27 import com.liferay.portal.kernel.util.ParamUtil;
28 import com.liferay.portal.kernel.util.Validator;
29 import com.liferay.portal.struts.ActionConstants;
30 import com.liferay.portal.struts.PortletAction;
31 import com.liferay.portal.theme.ThemeDisplay;
32 import com.liferay.portal.util.PortalUtil;
33 import com.liferay.portal.util.WebKeys;
34 import com.liferay.util.servlet.SessionErrors;
35
36 import javax.portlet.ActionRequest;
37 import javax.portlet.ActionResponse;
38 import javax.portlet.PortletConfig;
39 import javax.portlet.RenderRequest;
40 import javax.portlet.RenderResponse;
41
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpServletResponse;
44 import javax.servlet.jsp.PageContext;
45
46 import org.apache.commons.logging.Log;
47 import org.apache.commons.logging.LogFactory;
48 import org.apache.struts.action.ActionForm;
49 import org.apache.struts.action.ActionForward;
50 import org.apache.struts.action.ActionMapping;
51
52 import org.openid4java.OpenIDException;
53
54
60 public class ViewAction extends PortletAction {
61
62 public void processAction(
63 ActionMapping mapping, ActionForm form, PortletConfig config,
64 ActionRequest req, ActionResponse res)
65 throws Exception {
66
67 String cmd = req.getParameter(Constants.CMD);
68
69 ThemeDisplay themeDisplay =
70 (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);
71
72 if (req.getRemoteUser() != null) {
73 res.sendRedirect(themeDisplay.getPathMain());
74 }
75 else if (Validator.isNotNull(cmd)) {
76 try {
77 login(themeDisplay, req, res);
78 }
79 catch (Exception e) {
80 if (e instanceof OpenIDException) {
81 if (_log.isInfoEnabled()) {
82 _log.info(
83 "Error communicating with OpenID provider: " +
84 e.getMessage());
85 }
86
87 SessionErrors.add(req, e.getClass().getName());
88 }
89 else {
90 req.setAttribute(PageContext.EXCEPTION, e);
91
92 setForward(req, ActionConstants.COMMON_ERROR);
93 }
94 }
95 }
96 }
97
98 public ActionForward render(
99 ActionMapping mapping, ActionForm form, PortletConfig config,
100 RenderRequest req, RenderResponse res)
101 throws Exception {
102
103 return mapping.findForward("portlet.open_id.view");
104 }
105
106 protected void login(
107 ThemeDisplay themeDisplay, ActionRequest req, ActionResponse res)
108 throws Exception {
109
110 HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
111 HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(res);
112
113 String openId = ParamUtil.getString(req, "openId");
114
115 OpenIdRequestAction.sendOpenIdRequest(
116 themeDisplay, httpReq, httpRes, openId);
117 }
118
119 private static Log _log = LogFactory.getLog(ViewAction.class);
120
121 }