XuiRedirectHelper.java revision 0e8bc8c8be7bf9b827d1d025079244092584f506
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 com.iplanet.jato.CompleteRequestException;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport com.iplanet.jato.RequestContext;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport com.iplanet.jato.RequestManager;
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunningtonimport com.iplanet.jato.view.ViewBeanBase;
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunningtonimport com.sun.identity.console.base.model.AMAdminConstants;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport org.forgerock.guice.core.InjectorHolder;
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunningtonimport org.forgerock.openam.services.baseurl.BaseURLProviderFactory;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunningtonimport org.forgerock.openam.xui.XUIState;
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington
0e8bc8c8be7bf9b827d1d025079244092584f506Jaco Joosteimport javax.servlet.http.HttpServletRequest;
0e8bc8c8be7bf9b827d1d025079244092584f506Jaco Joosteimport java.io.IOException;
0e8bc8c8be7bf9b827d1d025079244092584f506Jaco Joosteimport java.text.MessageFormat;
0e8bc8c8be7bf9b827d1d025079244092584f506Jaco Jooste
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
0e8bc8c8be7bf9b827d1d025079244092584f506Jaco Jooste private static final String XUI_CONSOLE_BASE_PAGE = "{0}/XUI/#{1}";
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 *
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington * @param request Used to determine the OpenAM deployment URI.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * @param redirectRealm The realm.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington * @param xuiHash The XUI location hash.
a28658e7b50a29668499ee011576a857117fea4fPhill Cunnington */
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington public static void redirectToXui(HttpServletRequest request, String redirectRealm, String xuiHash) {
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington String deploymentUri = InjectorHolder.getInstance(BaseURLProviderFactory.class).get(redirectRealm)
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington .getURL(request);
0e8bc8c8be7bf9b827d1d025079244092584f506Jaco Jooste String redirect = MessageFormat.format(XUI_CONSOLE_BASE_PAGE, deploymentUri, xuiHash);
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
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington /**
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington * Gets the realm to redirect to from the JATO page session.
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington *
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington * @param viewBean The view bean.
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington * @return The redirect realm.
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington */
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington public static String getRedirectRealm(ViewBeanBase viewBean) {
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington String redirectRealm = (String) viewBean.getPageSessionAttribute(AMAdminConstants.CURRENT_REALM);
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington if (redirectRealm == null) {
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington redirectRealm = (String) viewBean.getPageSessionAttribute(AMAdminConstants.CURRENT_PROFILE);
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington }
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington return redirectRealm;
6328925537fd7e5d853fe7540b10d6f909057805Phill Cunnington }
6328925537fd7e5d853fe7540b10d6f909057805Phill 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}