ConfigureSocialAuthNViewBean.java revision 3fc1b5e9b2ff286cd528a06154cc998198de1e70
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * The contents of this file are subject to the terms of the Common Development and
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * Distribution License (the License). You may not use this file except in compliance with the
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * specific language governing permission and limitations under the License.
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * When distributing Covered Software, include this CDDL Header Notice in each file and include
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * Header, with the fields enclosed by brackets [] replaced by your own identifying
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * information: "Portions copyright [year] [name of copyright owner]".
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * Copyright 2014 ForgeRock AS.
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.iplanet.jato.model.ModelControlException;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.iplanet.jato.view.event.DisplayEvent;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.console.base.AMPrimaryMastHeadViewBean;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.console.base.AMPropertySheet;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.console.base.model.AMConsoleException;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.console.base.model.AMModel;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.console.base.model.AMPropertySheetModel;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.console.task.model.SocialAuthNModel;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.identity.console.task.model.SocialAuthNModelImpl;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.web.ui.model.CCPageTitleModel;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.web.ui.view.html.CCDropDownMenu;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport com.sun.web.ui.view.pagetitle.CCPageTitle;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellimport javax.servlet.http.HttpServletRequest;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * JATO view bean for configuring social login providers (Google, Facebook etc) via OpenID Connect or some other
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * mechanism. Assumes that all mechanisms are loosely based on OIDC -- i.e., OAuth2 with some form of identity.
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell * @since 12.0.0
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnellpublic class ConfigureSocialAuthNViewBean extends AMPrimaryMastHeadViewBean {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell public static final String DEFAULT_DISPLAY_URL = "/console/task/ConfigureSocialAuthN.jsp";
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private static final String PROPERTY_DIR = "com/sun/identity/console/";
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private static final String KNOWN_PROVIDER_PROPERTIES =
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell PROPERTY_DIR + "propertyConfigureSocialAuthNKnownProvider.xml";
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private static final String UNKNOWN_PROVIDER_PROPERTIES =
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell PROPERTY_DIR + "propertyConfigureSocialAuthNUnknownProvider.xml";
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private static final String TITLE_MESSAGE = "configure.social.authentication.title.message";
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private static final String PAGETITLE = "pgtitle";
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private static final String PROPERTY_ATTRIBUTE = "propertyAttributes";
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private static final String REALM_FIELD = "tfRealm";
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private static final String REDIRECT_URL_FIELD = "tfRedirectUrl";
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private static final String PROVIDER_ATTR = "provider";
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private final AMPropertySheetModel propertySheetModel;
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell super("ConfigureSocialAuthN");
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell this.propertySheetModel = createPropertyModel();
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell HttpServletRequest req = getRequestContext().getRequest();
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell return new SocialAuthNModelImpl(req, getPageSessionAttributes());
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell protected void registerChildren() {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell registerChild(PAGETITLE, CCPageTitle.class);
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell view = new CCPageTitle(this, ptModel, name);
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell } else if (ptModel.isChildSupported(name)) {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell } else if (name.equals(PROPERTY_ATTRIBUTE)) {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell view = new AMPropertySheet(this, propertySheetModel, name);
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell } else if (propertySheetModel.isChildSupported(name)) {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell view = propertySheetModel.createChild(this, name, getModel());
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private CCPageTitleModel createPageTitleModel() {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell CCPageTitleModel model = new CCPageTitleModel(getClass().getClassLoader().getResourceAsStream(
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell "com/sun/identity/console/twoBtnsPageTitle.xml"));
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private AMPropertySheetModel createPropertyModel() {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell // NB: at this point we cannot access the RequestContext so do not know if the provider is known or not.
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell // Default to unknown and then switch in the beginDisplay method
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell AMPropertySheetModel model = new AMPropertySheetModel(openPropertySheetXml(UNKNOWN_PROVIDER_PROPERTIES));
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell public void beginDisplay(DisplayEvent event) throws ModelControlException {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell HttpServletRequest req = getRequestContext().getRequest();
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell SocialAuthNModel model = (SocialAuthNModel) getModel();
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell // If provider is known then use the simplified property sheet
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell propertySheetModel.setDocument(openPropertySheetXml(KNOWN_PROVIDER_PROPERTIES));
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell final String titleMessage = model.getLocalizedString(TITLE_MESSAGE);
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell ptModel.setPageTitleText(MessageFormat.format(titleMessage, model.getProviderDisplayName()));
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell ptModel.setPageTitleHelpMessage(model.getLocalizedProviderHelpMessage());
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell SortedSet<String> realms = model.getRealms();
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell CCDropDownMenu menuRealm = (CCDropDownMenu) getChild(REALM_FIELD);
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell menuRealm.setOptions(createOptionList(realms));
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell if (realm != null && !realm.trim().isEmpty()) {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell setDisplayFieldValue(REDIRECT_URL_FIELD, model.getDefaultRedirectUrl());
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell if (provider != null && !provider.trim().isEmpty()) {
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell setPageSessionAttribute(PROVIDER_ATTR, provider.trim());
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", ex.getMessage());
3fc1b5e9b2ff286cd528a06154cc998198de1e70Craig McDonnell private InputStream openPropertySheetXml(final String file) {