XuiRedirectHelper.java revision 0fa457ad5568b6445c5fd4537bc22392f68e157e
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington/*
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * The contents of this file are subject to the terms of the Common Development and
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * Distribution License (the License). You may not use this file except in compliance with the
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * License.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington *
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * specific language governing permission and limitations under the License.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington *
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * When distributing Covered Software, include this CDDL Header Notice in each file and include
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * Header, with the fields enclosed by brackets [] replaced by your own identifying
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * information: "Portions copyright [year] [name of copyright owner]".
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington *
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * Copyright 2015 ForgeRock AS.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington */
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonpackage com.sun.identity.console;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport javax.servlet.http.HttpServletRequest;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport java.io.IOException;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport java.text.MessageFormat;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport com.iplanet.am.util.SystemProperties;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport com.iplanet.jato.CompleteRequestException;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport com.iplanet.jato.RequestContext;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport com.iplanet.jato.RequestManager;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport com.sun.identity.shared.Constants;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport org.forgerock.guice.core.InjectorHolder;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport org.forgerock.openam.xui.XUIState;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington/**
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * Helper for redirecting back to the XUI.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington *
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * @since 13.0.0
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington */
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonpublic final class XuiRedirectHelper {
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington private static final String XUI_CONSOLE_BASE_PAGE = "{0}/XUI/{1}#{2}";
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington private static final String XUI_CONSOLE_REALM = "?realm={0}";
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington private XuiRedirectHelper() {
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington }
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington /**
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * Redirects to the XUI to the specified realm and hash.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington *
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * @param redirectRealm The realm.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * @param xuiHash The XUI location hash.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington */
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington public static void redirectToXui(String redirectRealm, String xuiHash) {
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington String deploymentUri = SystemProperties.get(Constants.AM_SERVICES_DEPLOYMENT_DESCRIPTOR);
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington String redirect;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington if (!"/".equals(redirectRealm)) {
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington redirect = MessageFormat.format(XUI_CONSOLE_BASE_PAGE, deploymentUri,
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington MessageFormat.format(XUI_CONSOLE_REALM, redirectRealm), xuiHash);
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington } else {
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington redirect = MessageFormat.format(XUI_CONSOLE_BASE_PAGE, deploymentUri, "", xuiHash);
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington }
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington RequestContext rc = RequestManager.getRequestContext();
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington try {
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington rc.getResponse().sendRedirect(redirect);
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington throw new CompleteRequestException();
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington } catch (IOException e) {
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington //never thrown, empty catch
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington }
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington }
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington /**
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * Determines if request is from XUI to get a JATO page session.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington *
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * @param request The request.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * @return {@code true} if the request is from the XUI, {@code false} otherwise.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington */
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington public static boolean isJatoSessionRequestFromXUI(HttpServletRequest request) {
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington return "XUI".equals(request.getParameter("requester"));
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington }
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington /**
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * Determines if the XUI admin console is enabled.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington *
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * @return {@code true} if the XUI admin console is enabled, {@code false} otherwise.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington */
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington public static boolean isXuiAdminConsoleEnabled() {
0fa457ad5568b6445c5fd4537bc22392f68e157ePhill Cunnington return InjectorHolder.getInstance(XUIState.class).isXUIAdminEnabled();
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington }
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington}