ConfigureSalesForceAppsCompleteViewBean.java revision 4c2ed873ce0d69780e28220e175a838a6829d4ea
0N/A/*
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0N/A *
0N/A * Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
0N/A *
0N/A * The contents of this file are subject to the terms
0N/A * of the Common Development and Distribution License
0N/A * (the License). You may not use this file except in
0N/A * compliance with the License.
0N/A *
0N/A * You can obtain a copy of the License at
0N/A * https://opensso.dev.java.net/public/CDDLv1.0.html or
0N/A * opensso/legal/CDDLv1.0.txt
0N/A * See the License for the specific language governing
0N/A * permission and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL
0N/A * Header Notice in each file and include the License file
0N/A * at opensso/legal/CDDLv1.0.txt.
0N/A * If applicable, add the following below the CDDL Header,
0N/A * with the fields enclosed by brackets [] replaced by
0N/A * your own identifying information:
0N/A * "Portions Copyrighted [year] [name of copyright owner]"
0N/A *
0N/A * $Id: ConfigureSalesForceAppsCompleteViewBean.java,v 1.3 2009/07/28 17:45:40 babysunil Exp $
0N/A *
0N/A * Portions Copyrighted 2013-2015 ForgeRock AS.
0N/A */
0N/Apackage com.sun.identity.console.task;
0N/A
0N/Aimport com.iplanet.jato.RequestContext;
0N/Aimport com.iplanet.jato.model.ModelControlException;
0N/Aimport com.iplanet.jato.view.View;
0N/Aimport com.iplanet.jato.view.event.DisplayEvent;
0N/Aimport com.iplanet.jato.view.event.RequestInvocationEvent;
0N/Aimport com.sun.identity.console.base.AMPrimaryMastHeadViewBean;
0N/Aimport com.sun.identity.console.base.AMPropertySheet;
0N/Aimport com.sun.identity.console.base.model.AMConsoleException;
0N/Aimport com.sun.identity.console.base.model.AMModel;
0N/Aimport com.sun.identity.console.base.model.AMPropertySheetModel;
0N/Aimport com.sun.identity.console.task.model.TaskModel;
0N/Aimport com.sun.identity.console.task.model.TaskModelImpl;
0N/Aimport com.sun.web.ui.model.CCPageTitleModel;
0N/Aimport com.sun.web.ui.view.alert.CCAlert;
0N/Aimport com.sun.web.ui.view.pagetitle.CCPageTitle;
0N/Aimport java.io.ByteArrayInputStream;
0N/Aimport java.io.DataInputStream;
0N/Aimport java.io.InputStream;
0N/Aimport java.io.IOException;
0N/Aimport java.text.MessageFormat;
0N/Aimport java.util.Collections;
0N/Aimport java.util.HashSet;
0N/Aimport java.util.Map;
0N/Aimport java.util.Set;
0N/Aimport java.util.logging.Level;
0N/Aimport java.util.logging.Logger;
0N/Aimport javax.servlet.ServletOutputStream;
0N/Aimport javax.servlet.http.HttpServletRequest;
0N/Aimport javax.servlet.http.HttpServletResponse;
0N/A
0N/A/**
0N/A * Create register product UI.
0N/A */
0N/Apublic class ConfigureSalesForceAppsCompleteViewBean
0N/A extends RedirectToRealmHomeViewBean {
0N/A
0N/A public static final String DEFAULT_DISPLAY_URL =
0N/A "/console/task/ConfigureSalesForceAppsComplete.jsp";
0N/A protected static final String PROPERTIES = "propertyAttributes";
0N/A private AMPropertySheetModel psModel;
0N/A private CCPageTitleModel ptModel;
0N/A private static final String PGTITLE_ONE_BTNS =
0N/A "pgtitleOneBtns";
0N/A private static final String ENTITY_ID = "entityId";
0N/A private boolean initialized;
0N/A
0N/A /**
0N/A * Creates a salesforce complete view bean.
0N/A */
0N/A public ConfigureSalesForceAppsCompleteViewBean() {
0N/A super("ConfigureSalesForceAppsComplete");
0N/A setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
0N/A }
0N/A
0N/A protected void initialize() {
0N/A if (!initialized) {
0N/A initialized = true;
0N/A createPropertyModel();
0N/A createPageTitleModel();
0N/A registerChildren();
0N/A super.initialize();
0N/A }
0N/A super.registerChildren();
0N/A }
0N/A
0N/A protected void registerChildren() {
0N/A super.registerChildren();
0N/A registerChild(PROPERTIES, AMPropertySheet.class);
0N/A registerChild(PGTITLE_ONE_BTNS, CCPageTitle.class);
0N/A psModel.registerChildren(this);
0N/A ptModel.registerChildren(this);
0N/A }
0N/A
0N/A protected View createChild(String name) {
0N/A View view = null;
0N/A if (name.equals(PGTITLE_ONE_BTNS)) {
0N/A view = new CCPageTitle(this, ptModel, name);
0N/A } else if (name.equals(PROPERTIES)) {
0N/A view = new AMPropertySheet(this, psModel, name);
0N/A } else if ((psModel != null) && psModel.isChildSupported(name)) {
0N/A view = psModel.createChild(this, name, getModel());
0N/A } else if ((ptModel != null) && ptModel.isChildSupported(name)) {
0N/A view = ptModel.createChild(this, name);
0N/A } else {
0N/A view = super.createChild(name);
0N/A }
0N/A return view;
0N/A }
0N/A
0N/A public void beginDisplay(DisplayEvent event)
0N/A throws ModelControlException {
0N/A try {
0N/A super.beginDisplay(event);
0N/A HttpServletRequest req = getRequestContext().getRequest();
0N/A String realm = req.getParameter("realm");
0N/A String idp = req.getParameter("idp");
0N/A String attrMapp = req.getParameter("attrMapp");
0N/A String spEntityId = req.getParameter(ENTITY_ID);
0N/A setPageSessionAttribute(ENTITY_ID, spEntityId);
0N/A setPageSessionAttribute("entityRealm", realm);
0N/A TaskModel model = (TaskModel) getModelInternal();
0N/A Map values = model.getConfigureSalesForceAppsURLs(realm, idp, attrMapp);
0N/A
0N/A String domainId = getModel().getLocalizedString("salesforce.link");
0N/A String msg = "<ul>";
0N/A String orgMsg = getModel().getLocalizedString(
0N/A "configure.salesforce.apps.complete.urllist");
0N/A msg += "<li>";
0N/A msg += MessageFormat.format(orgMsg, domainId, domainId);
0N/A msg += "</li>";
0N/A msg += "</ul>";
0N/A
0N/A values.put("urllist", returnEmptySetIfValueIsNull(msg));
0N/A AMPropertySheet ps = (AMPropertySheet) getChild(PROPERTIES);
0N/A ps.setAttributeValues(values, model);
0N/A
0N/A } catch (AMConsoleException ex) {
0N/A Logger.getLogger(ConfigureSalesForceAppsCompleteViewBean.class.getName()).log(Level.SEVERE, null, ex);
0N/A setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error",
0N/A ex.getMessage());
0N/A }
0N/A }
0N/A
0N/A private void createPageTitleModel() {
0N/A ptModel = new CCPageTitleModel(
0N/A getClass().getClassLoader().getResourceAsStream(
0N/A "com/sun/identity/console/oneBtnPageTitle.xml"));
0N/A ptModel.setValue("button1", "button.finish");
0N/A }
0N/A
0N/A protected AMModel getModelInternal() {
0N/A HttpServletRequest req = getRequestContext().getRequest();
0N/A return new TaskModelImpl(req, getPageSessionAttributes());
0N/A }
0N/A
0N/A private void createPropertyModel() {
0N/A psModel = new AMPropertySheetModel(
0N/A getClass().getClassLoader().getResourceAsStream(
0N/A "com/sun/identity/console/propertyConfigureSalesForceAppsComplete.xml"));
0N/A psModel.setValue("buttonDownloadCert",
0N/A "configure.salesforce.apps.complete.certificate.download");
0N/A psModel.clear();
0N/A }
0N/A
0N/A /**
0N/A * Handles finish button request.
0N/A *
0N/A * @param event Request invocation event
0N/A */
0N/A public void handleButton1Request(RequestInvocationEvent event)
0N/A throws ModelControlException {
0N/A String acsUrl = getDisplayFieldStringValue("SalesforceLoginURL");
0N/A try {
0N/A if ((acsUrl != null) && (acsUrl.length() > 0)) {
0N/A String realm = (String) getPageSessionAttribute("entityRealm");
0N/A String entityId = (String) getPageSessionAttribute(ENTITY_ID);
0N/A TaskModel model = (TaskModel) getModelInternal();
0N/A model.setAcsUrl(realm, entityId, acsUrl);
0N/A redirectToHome();
0N/A } else if ((acsUrl == null) || !(acsUrl.length() > 0)) {
0N/A ConfigureSalesForceAppsFinishWarningViewBean vb =
0N/A (ConfigureSalesForceAppsFinishWarningViewBean) getViewBean(
0N/A ConfigureSalesForceAppsFinishWarningViewBean.class);
0N/A vb.forwardTo(getRequestContext());
0N/A }
0N/A } catch (AMConsoleException e) {
0N/A setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error",
0N/A e.getMessage());
0N/A }
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Handles Verification Certificate download button request.
0N/A * Sends Verification Certificate to the ServletResponse output stream.
0N/A * @param event Request invocation event
0N/A */
0N/A public void handleButtonDownloadCertRequest(RequestInvocationEvent event)
0N/A throws ModelControlException {
0N/A RequestContext reqContext = event.getRequestContext();
0N/A HttpServletResponse resp = reqContext.getResponse();
0N/A String cert = (String) psModel.getValue("PubKey");
0N/A
0N/A ServletOutputStream op = null;
0N/A try {
0N/A int length = 0;
0N/A op = resp.getOutputStream();
0N/A
0N/A // Set the response
0N/A resp.setContentType("application/octet-stream");
0N/A resp.setContentLength(cert.length());
0N/A resp.setHeader("Content-Disposition",
0N/A "attachment; filename=\"" + "OpenSSOCert.txt" + "\"");
0N/A
0N/A // Stream to the requester.
0N/A int BUFSIZE = cert.length();
0N/A byte[] bbuf = new byte[BUFSIZE];
0N/A InputStream is = new ByteArrayInputStream(cert.getBytes());
0N/A DataInputStream in = new DataInputStream(is);
0N/A
0N/A while ((in != null) && ((length = in.read(bbuf)) != -1)) {
0N/A op.write(bbuf, 0, length);
0N/A }
0N/A
0N/A in.close();
0N/A op.flush();
0N/A } catch (IOException ex) {
0N/A debug.error("ConfigureSalesForceAppsCompleteViewBean.uploadCert", ex);
0N/A setInlineAlertMessage(CCAlert.TYPE_ERROR,
0N/A "configure.salesforce.apps.complete.certificate.download.error",
0N/A ex.getMessage());
0N/A } finally {
0N/A if (op != null) {
0N/A try {
0N/A op.close();
0N/A } catch (IOException ex) {
0N/A debug.error("ConfigureSalesForceAppsCompleteViewBean.uploadCert", ex);
0N/A setInlineAlertMessage(CCAlert.TYPE_ERROR,
0N/A "configure.SalesForce.apps.complete.certificate.download.error",
0N/A ex.getMessage());
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A private Set returnEmptySetIfValueIsNull(String str) {
0N/A Set set = Collections.EMPTY_SET;
0N/A if (str != null) {
0N/A set = new HashSet(2);
0N/A set.add(str);
0N/A }
0N/A return set;
0N/A }
0N/A}
0N/A