public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { String siteName = request.getPreferences().getValue("SRC", null); SSOSite site = null; if (siteName != null) { site = sso.getSiteByUrl(siteName); } if (site == null) { response.getWriter().print(NO_CREDENTIALS); return; } else { PasswordCredential pwc = SSOPortletUtil.getCredentialsForSite(sso, siteName, request); if (pwc != null) { request.setAttribute(SSO_REQUEST_ATTRIBUTE_USERNAME, pwc.getUserName()); request.setAttribute(SSO_REQUEST_ATTRIBUTE_PASSWORD, pwc.getPassword()); } else { response.getWriter().print(NO_CREDENTIALS); return; } } StatusMessage msg = (StatusMessage) PortletMessaging.consume(request, "SSOWebContent", "status"); if (msg != null) { this.getContext(request).put("statusMsg", msg); } super.doView(request, response); }
public void init(PortletConfig config) throws PortletException { super.init(config); context = getPortletContext(); sso = (SSOManager) context.getAttribute("cps:SSO"); if (null == sso) { throw new PortletException("Failed to find SSO Manager on portlet initialization"); } userManager = (UserManager) context.getAttribute(CommonPortletServices.CPS_USER_MANAGER_COMPONENT); if (null == userManager) { throw new PortletException("Failed to find the User Manager on portlet initialization"); } ssoTypesList = new LinkedList<String>(); for (String s : SSO_TYPES) ssoTypesList.add(s); }
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { // grab parameters - they will be cleared in processing of edit response String webContentParameter = actionRequest.getParameter(WebContentRewriter.ACTION_PARAMETER_URL); String ssoPrincipalName = actionRequest.getParameter(SSO_EDIT_FIELD_PRINCIPAL); String ssoPrincipalPassword = actionRequest.getParameter(SSO_EDIT_FIELD_CREDENTIAL); // save the prefs super.processAction(actionRequest, actionResponse); // process credentials if (webContentParameter == null || actionRequest.getPortletMode() == PortletMode.EDIT) { // processPreferencesAction(request, actionResponse); // get the POST params -- requires HTML post params named above String siteUrl = actionRequest.getPreferences().getValue("SRC", ""); String localUser = actionRequest.getUserPrincipal().getName(); SSOSite site = sso.getSiteByUrl(siteUrl); try { if (!SecurityHelper.isEmpty(siteUrl) && !SecurityHelper.isEmpty(ssoPrincipalName) && !SecurityHelper.isEmpty(ssoPrincipalPassword)) { if (site == null) { site = sso.newSite(siteUrl, siteUrl); sso.addSite(site); SSOPortletUtil.updateUser( sso, actionRequest, site, ssoPrincipalName, ssoPrincipalPassword); } else { SSOPortletUtil.updateUser( sso, actionRequest, site, ssoPrincipalName, ssoPrincipalPassword); } } } catch (SSOException e) { String errorMessage = "Failed to add remote user for the portal principal, " + actionRequest.getUserPrincipal().getName() + "."; if (e.getCause() != null) { errorMessage += " (" + e.getCause() + ")"; } StatusMessage statusMessage = new StatusMessage(errorMessage, StatusMessage.ERROR); PortletMessaging.publish(actionRequest, "SSOWebContent", "status", statusMessage); actionResponse.setPortletMode(PortletMode.EDIT); // stay on edit } } }
public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException { String site = request.getPreferences().getValue("SRC", ""); PasswordCredential pwc = SSOPortletUtil.getCredentialsForSite(sso, site, request); if (pwc != null) { getContext(request).put(SSO_EDIT_FIELD_PRINCIPAL, pwc.getUserName()); getContext(request).put(SSO_EDIT_FIELD_CREDENTIAL, pwc.getPassword()); } else { // no credentials configured in SSO store // switch to SSO Configure View getContext(request).put(SSO_EDIT_FIELD_PRINCIPAL, ""); getContext(request).put(SSO_EDIT_FIELD_CREDENTIAL, ""); } StatusMessage msg = (StatusMessage) PortletMessaging.consume(request, "SSOWebContent", "status"); if (msg != null) { this.getContext(request).put("statusMsg", msg); } this.getContext(request).put("ssoTypes", SSO_TYPES); this.getContext(request) .put("ssoTypeSelected", request.getPreferences().getValue("sso.type", SSO_TYPE_BASIC)); super.doEdit(request, response); }