All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.sling.auth.core.spi.AbstractAuthenticationHandler Maven / Gradle / Ivy

There is a newer version: 6.5.21
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.sling.auth.core.spi;

import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.sling.auth.core.AuthUtil;

/**
 * The AbstractAuthenticationHandler implements the
 * AuthenticationHandler interface and extends the
 * {@link DefaultAuthenticationFeedbackHandler} providing some helper methods
 * which may be used by authentication handlers.
 *
 * @deprecated since Bundle 1.0.8; {@link AuthenticationHandler} implementations
 *             should extend {@link DefaultAuthenticationFeedbackHandler}
 *             directly and use the utility methods in the {@link AuthUtil}
 *             class.
 */
@Deprecated
public abstract class AbstractAuthenticationHandler extends DefaultAuthenticationFeedbackHandler implements
        AuthenticationHandler {

    /**
     * Returns the value of the named request attribute or parameter as a string
     * as follows:
     * 
    *
  1. If there is a request attribute of that name, which is a non-empty * string, it is returned.
  2. *
  3. If there is a non-empty request parameter of * that name, this parameter is returned. *
  4. *
  5. Otherwise the defaultValue is returned.
  6. *
* * @param request The request from which to return the attribute or request * parameter * @param name The name of the attribute/parameter * @param defaultValue The default value to use if neither a non-empty * string attribute or a non-empty parameter exists in the * request. * @return The attribute, parameter or defaultValue as defined * above. * @deprecated since Bundle 1.0.8, use * {@link AuthUtil#getAttributeOrParameter(HttpServletRequest, String, String)} */ @Deprecated public static String getAttributeOrParameter(final HttpServletRequest request, final String name, final String defaultValue) { return AuthUtil.getAttributeOrParameter(request, name, defaultValue); } /** * Returns any resource target to redirect to after successful * authentication. This method either returns a non-empty string or the * defaultLoginResource parameter. First the * resource request attribute is checked. If it is a non-empty * string, it is returned. Second the resource request * parameter is checked and returned if it is a non-empty string. * * @param request The request providing the attribute or parameter * @param defaultLoginResource The default login resource value * @return The non-empty redirection target or * defaultLoginResource. * @deprecated since Bundle 1.0.8, use * {@link AuthUtil#getLoginResource(HttpServletRequest, String)} */ @Deprecated public static String getLoginResource(final HttpServletRequest request, String defaultLoginResource) { return AuthUtil.getLoginResource(request, defaultLoginResource); } /** * Ensures and returns the {@link org.apache.sling.api.auth.Authenticator#LOGIN_RESOURCE} request * attribute is set to a non-null, non-empty string. If the attribute is not * currently set, this method sets it as follows: *
    *
  1. If the {@link org.apache.sling.api.auth.Authenticator#LOGIN_RESOURCE} request parameter is set * to a non-empty string, that parameter is set
  2. *
  3. Otherwise if the defaultValue is a non-empty string the * default value is used
  4. *
  5. Otherwise the attribute is set to "/"
  6. *
* * @param request The request to check for the resource attribute * @param defaultValue The default value to use if the attribute is not set * and the request parameter is not set. This parameter is * ignored if it is null or an empty string. * @return returns the value of resource request attribute * @since 1.0.2 (Bundle version 1.0.4) * @deprecated since Bundle 1.0.8, use * {@link AuthUtil#setLoginResourceAttribute(HttpServletRequest, String)} */ @Deprecated public static String setLoginResourceAttribute(final HttpServletRequest request, final String defaultValue) { return AuthUtil.setLoginResourceAttribute(request, defaultValue); } /** * Redirects to the given target path appending any parameters provided in * the parameter map. *

* This method implements the following functionality: *

    *
  • The target path is prefixed with the request's context path to ensure * proper redirection into the same web application. Therefore the * target path parameter must not be prefixed with the context * path.
  • *
  • If the params map does not contain a (non- * null) value for the {@link org.apache.sling.api.auth.Authenticator#LOGIN_RESOURCE * resource} entry, such an entry is generated from the request URI and the * (optional) query string of the given request.
  • *
  • The parameters from the params map or at least a single * {@link org.apache.sling.api.auth.Authenticator#LOGIN_RESOURCE resource} parameter are added to the * target path for the redirect. Each parameter value is encoded using the * java.net.URLEncoder with UTF-8 encoding to make it safe for * requests
  • *
* * @param request The request object used to get the current request URI and * request query string if the params map does not * have the {@link org.apache.sling.api.auth.Authenticator#LOGIN_RESOURCE resource} * parameter set. * @param response The response used to send the redirect to the client. * @param target The target path to redirect the client to. This parameter * must not be prefixed with the request's context path because * this will be added by this method. If this parameter is not a * valid target request as per the * {@link #isRedirectValid(HttpServletRequest, String)} method * the target is modified to be the root of the request's * context. * @param params The map of parameters to be added to the target path. This * may be null. * @throws IOException If an error occurs sending the redirect request * @throws IllegalStateException If the response was committed or if a * partial URL is given and cannot be converted into a valid URL * @throws InternalError If the UTF-8 character encoding is not supported by * the platform. This should not be caught, because it is a real * problem if the encoding required by the specification is * missing. * @since 1.0.2 (Bundle version 1.0.4) * @since 1.0.4 (bundle version 1.0.8) the target is validated with the * {@link AuthUtil#isRedirectValid(HttpServletRequest, String)} * method. * @deprecated since Bundle 1.0.8, use * {@link AuthUtil#sendRedirect(HttpServletRequest, HttpServletResponse, String, Map)} */ @Deprecated public static void sendRedirect(final HttpServletRequest request, final HttpServletResponse response, final String target, Map params) throws IOException { AuthUtil.sendRedirect(request, response, request.getContextPath() + target, params); } /** * This method calls * {@link AuthUtil#isRedirectValid(HttpServletRequest, String)}. * * @deprecated This method has been introduced after Bundle release 1.0.6 * but has been replaced with * {@link AuthUtil#isRedirectValid(HttpServletRequest, String)}. * Use the latter method. */ @Deprecated public static boolean isRedirectValid(final HttpServletRequest request, final String target) { return AuthUtil.isRedirectValid(request, target); } /** * Returns true if the the client just asks for validation of * submitted username/password credentials. *

* This implementation returns true if the request parameter * {@link org.apache.sling.auth.core.AuthConstants#PAR_J_VALIDATE} is set to true (case-insensitve). If * the request parameter is not set or to any value other than * true this method returns false. * * @param request The request to provide the parameter to check * @return true if the {@link org.apache.sling.auth.core.AuthConstants#PAR_J_VALIDATE} parameter is set * to true. * @since 1.0.2 (Bundle version 1.0.4) * @deprecated since Bundle 1.0.8, use * {@link AuthUtil#isValidateRequest(HttpServletRequest)} */ @Deprecated public static boolean isValidateRequest(final HttpServletRequest request) { return AuthUtil.isValidateRequest(request); } /** * Sends a 200/OK response to a credential validation request. * * @param response The response object * @since 1.0.2 (Bundle version 1.0.4) * @deprecated since Bundle 1.0.8, use * {@link AuthUtil#sendValid(HttpServletResponse)} */ @Deprecated public static void sendValid(final HttpServletResponse response) { AuthUtil.sendValid(response); } /** * Sends a 403/FORBIDDEN response optionally stating the reason for this * response code in the {@link org.apache.sling.auth.core.AuthConstants#X_REASON} header. The value for the * {@link org.apache.sling.auth.core.AuthConstants#X_REASON} header is taken from * {@link AuthenticationHandler#FAILURE_REASON} request attribute if set. * * @param request The request object * @param response The response object * @since 1.0.2 (Bundle version 1.0.4) * @deprecated since Bundle 1.0.8, use * {@link AuthUtil#sendInvalid(HttpServletRequest, HttpServletResponse)} */ @Deprecated public static void sendInvalid(final HttpServletRequest request, final HttpServletResponse response) { AuthUtil.sendInvalid(request, response); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy