/* * 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.catalina.util;
/** * Determine the name to use for the session cookie for the provided * context. * @param context The context * @return the cookie name for the context
*/ publicstatic String getSessionCookieName(Context context) { return getConfiguredSessionCookieName(context, DEFAULT_SESSION_COOKIE_NAME);
}
/** * Determine the name to use for the session path parameter for the provided * context. * @param context The context * @return the parameter name for the session
*/ publicstatic String getSessionUriParamName(Context context) { return getConfiguredSessionCookieName(context, DEFAULT_SESSION_PARAMETER_NAME);
}
privatestatic String getConfiguredSessionCookieName(Context context, String defaultName) { // Priority is: // 1. Cookie name defined in context // 2. Cookie name configured for app // 3. Default defined by spec if (context != null) {
String cookieName = context.getSessionCookieName(); if (cookieName != null && cookieName.length() > 0) { return cookieName;
}
/** * Determine the value to use for the session cookie path for the provided * context. * * @param context The context * @return the parameter name for the session
*/ publicstatic String getSessionCookiePath(Context context) {
String contextPath = context.getSessionCookiePath(); if (contextPath == null || contextPath.length() == 0) {
contextPath = scc.getPath();
} if (contextPath == null || contextPath.length() == 0) {
contextPath = context.getEncodedPath();
} if (context.getSessionCookiePathUsesTrailingSlash()) { // Handle special case of ROOT context where cookies require a path of // '/' but the servlet spec uses an empty string // Also ensure the cookies for a context with a path of /foo don't get // sent for requests with a path of /foobar if (!contextPath.endsWith("/")) {
contextPath = contextPath + "/";
}
} else { // Only handle special case of ROOT context where cookies require a // path of '/' but the servlet spec uses an empty string if (contextPath.length() == 0) {
contextPath = "/";
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.