a4544a5a0e622ef69e38641f87ab1b5685e05911Phill Cunnington/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: RedirectCallback.java,v 1.5 2008/08/19 19:08:55 veiming Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
a4544a5a0e622ef69e38641f87ab1b5685e05911Phill Cunnington * Portions Copyrighted 2015 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.authentication.spi;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Map;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.security.auth.callback.Callback;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/* iPlanet-PUBLIC-CLASS */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This <code>RedirectCallback</code> class implements <code>Callback</code>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * and is used by the authentication module when redirect to a particulat URL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * is required with specific redirect data.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class RedirectCallback implements Callback, java.io.Serializable {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String redirectUrl = null;
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken Stubbings private Map<String, String> redirectData = new HashMap<>();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String method = "get";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String status = null;
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna private boolean trackingCookie = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String statusParameter = "AM_AUTH_SUCCESS_PARAM";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String redirectBackUrlCookie = "AM_REDIRECT_BACK_SERVER_URL";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The status as the result of redirection, as "SUCCESS".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String SUCCESS = "SUCCESS";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The status as the result of redirection, as "FAILED".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String FAILED = "FAILED";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs a <code>RedirectCallback</code> object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public RedirectCallback() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs a <code>RedirectCallback</code> object with
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * redirect URL,redirect data and redirect method.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param redirectUrl URL to be redirected to.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param redirectData the data to be redirected to redirect URL.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param method Method used for redirection, either "GET" or "POST".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public RedirectCallback(String redirectUrl, Map redirectData,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String method) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.redirectUrl = redirectUrl;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.redirectData = redirectData;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.method = method;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs a <code>RedirectCallback</code> object with
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * redirect URL,redirect data,redirect method,status parameter
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * and redirect back URL Cookie name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param redirectUrl URL to be redirected to.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param redirectData the data to be redirected to redirect URL.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param method Method used for redirection, either "GET" or "POST".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param statusParameter statusParameter to be checked from
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * HttpServletRequest object at the result of redirection.
8d3140b524c0e28c0a49dc7c7d481123ef3cfe11Chris Lee * @param redirectBackUrlCookie redirectBackUrlCookie name to be set as the
8d3140b524c0e28c0a49dc7c7d481123ef3cfe11Chris Lee * OpenAM server URL when redirecting to external web site.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public RedirectCallback(String redirectUrl, Map redirectData,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String method, String statusParameter,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String redirectBackUrlCookie) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.redirectUrl = redirectUrl;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.redirectData = redirectData;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.method = method;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.statusParameter = statusParameter;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.redirectBackUrlCookie = redirectBackUrlCookie;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the URL to be redirected to.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param redirectUrl URL to be redirected to.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setRedirectUrl(String redirectUrl) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.redirectUrl = redirectUrl;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the URL to be redirected to.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the URL to be redirected to.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getRedirectUrl() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return redirectUrl;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the data to be redirected to redirect URL. This data is in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * form of HashMap of name / value pairs.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param redirectData the data to be redirected to redirect URL.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setRedirectData(Map redirectData) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.redirectData = redirectData;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the data to be redirected to redirect URL.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the Map of data to be redirected to redirect URL.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken Stubbings public Map<String, String> getRedirectData() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return redirectData;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the Method used for redirection, either "GET" or "POST".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param method Method used for redirection, either "GET" or "POST".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setMethod(String method) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.method = method;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the Method used for redirection, either "GET" or "POST".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the Method used for redirection, either "GET" or "POST".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getMethod() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return method;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the status as the result of redirection,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * either "SUCCESS" or "FAILED".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param status status as the result of redirection,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * either "SUCCESS" or "FAILED".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setStatus(String status) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.status = status;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the status as the result of redirection,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * either "SUCCESS" or "FAILED".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the status as the result of redirection,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * either "SUCCESS" or "FAILED".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getStatus() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return status;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the status parameter to be checked from HTTP Servlet Request object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at the result of redirection.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param statusParameter Status parameter.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setStatusParameter(String statusParameter) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.statusParameter = statusParameter;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the statusParameter to be checked from HttpServletRequest object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at the result of redirection.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the statusParameter to be checked from HttpServletRequest object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at the result of redirection.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getStatusParameter() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return statusParameter;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8d3140b524c0e28c0a49dc7c7d481123ef3cfe11Chris Lee * Sets the redirectBackUrlCookie name to be set as the OpenAM
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * server URL when redirecting to external web site.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8d3140b524c0e28c0a49dc7c7d481123ef3cfe11Chris Lee * @param redirectBackUrlCookie redirectBackUrlCookie name to be set as the
8d3140b524c0e28c0a49dc7c7d481123ef3cfe11Chris Lee * OpenAM server URL when redirecting to external web site.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setRedirectBackUrlCookieName(String redirectBackUrlCookie) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.redirectBackUrlCookie = redirectBackUrlCookie;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna /**
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna * Whether the XUI should execute this immediately, or expect we'll be returned from it --
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna * necessary to be set if this redirect is expected to be returned from.
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna * @param enableCookie if a cookie should store the current authId position.
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna */
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna public void setTrackingCookie(boolean enableCookie) {
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna this.trackingCookie = enableCookie;
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna }
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna /**
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna * Gets the value of this RedirectCallback's trackingCookie, indicating whether we should
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna * store information about the current authId in a cookie via the XUI.
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna * @return true if we should store, false otherwise.
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna */
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna public boolean getTrackingCookie() {
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna return trackingCookie;
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna }
61b4091b1d49fc8b736ee1e150a1b76c14f05c91David Luna
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8d3140b524c0e28c0a49dc7c7d481123ef3cfe11Chris Lee * Returns the redirectBackUrlCookie name to be set as the OpenAM
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * server URL when redirecting to external web site.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8d3140b524c0e28c0a49dc7c7d481123ef3cfe11Chris Lee * @return the redirectBackUrlCookie name to be set as the OpenAM
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * server URL when redirecting to external web site.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getRedirectBackUrlCookieName() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return redirectBackUrlCookie;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster