/*
* Copyright (c) 1997, 2017 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.grizzly.servlet;
Class that may be used to configure various properties of cookies
used for session tracking purposes.
/**
* Class that may be used to configure various properties of cookies
* used for session tracking purposes.
*/
public class SessionCookieConfig implements javax.servlet.SessionCookieConfig {
private String name;
private String domain;
private String path;
private String comment;
private boolean httpOnly = true;
private boolean secure;
private final WebappContext ctx;
private int maxAge = -1;
Constructor
/**
* Constructor
*/
public SessionCookieConfig(WebappContext ctx) {
this.ctx = ctx;
}
Params: - name – the cookie name to use
Throws: - IllegalStateException – if the ServletContext
from which this SessionCookieConfig was acquired has
already been initialized
/**
* @param name the cookie name to use
*
* @throws IllegalStateException if the <tt>ServletContext</tt>
* from which this <tt>SessionCookieConfig</tt> was acquired has
* already been initialized
*/
@Override
public void setName(String name) {
if (ctx.deployed) {
throw new IllegalArgumentException("WebappContext has already been deployed");
}
this.name = name;
}
Returns: the cookie name set via setName
, or JSESSIONID if setName
was never called
/**
* @return the cookie name set via {@link #setName}, or
* <tt>JSESSIONID</tt> if {@link #setName} was never called
*/
@Override
public String getName() {
return name;
}
Params: - domain – the cookie domain to use
Throws: - IllegalStateException – if the ServletContext
from which this SessionCookieConfig was acquired has
already been initialized
/**
* @param domain the cookie domain to use
*
* @throws IllegalStateException if the <tt>ServletContext</tt>
* from which this <tt>SessionCookieConfig</tt> was acquired has
* already been initialized
*/
@Override
public void setDomain(String domain) {
if (ctx.deployed) {
throw new IllegalArgumentException("WebappContext has already been deployed");
}
this.domain = domain;
}
Returns: the cookie domain set via setDomain
, or null if setDomain
was never called
/**
* @return the cookie domain set via {@link #setDomain}, or
* <tt>null</tt> if {@link #setDomain} was never called
*/
@Override
public String getDomain() {
return domain;
}
Params: - path – the cookie path to use
Throws: - IllegalStateException – if the ServletContext
from which this SessionCookieConfig was acquired has
already been initialized
/**
* @param path the cookie path to use
*
* @throws IllegalStateException if the <tt>ServletContext</tt>
* from which this <tt>SessionCookieConfig</tt> was acquired has
* already been initialized
*/
@Override
public void setPath(String path) {
if (ctx.deployed) {
throw new IllegalArgumentException("WebappContext has already been deployed");
}
this.path = path;
}
Returns: the cookie path set via setPath
, or the context path of the ServletContext from which this
SessionCookieConfig was acquired if setPath
was never called
/**
* @return the cookie path set via {@link #setPath}, or the context
* path of the <tt>ServletContext</tt> from which this
* <tt>SessionCookieConfig</tt> was acquired if {@link #setPath}
* was never called
*/
@Override
public String getPath() {
return path;
}
Params: - comment – the cookie comment to use
Throws: - IllegalStateException – if the ServletContext
from which this SessionCookieConfig was acquired has
already been initialized
/**
* @param comment the cookie comment to use
*
* @throws IllegalStateException if the <tt>ServletContext</tt>
* from which this <tt>SessionCookieConfig</tt> was acquired has
* already been initialized
*/
@Override
public void setComment(String comment) {
if (ctx.deployed) {
throw new IllegalArgumentException("WebappContext has already been deployed");
}
this.comment = comment;
}
Returns: the cookie comment set via setComment
, or null if setComment
was never called
/**
* @return the cookie comment set via {@link #setComment}, or
* <tt>null</tt> if {@link #setComment} was never called
*/
@Override
public String getComment() {
return comment;
}
Params: - httpOnly – true if the session tracking cookies created
on behalf of the ServletContext from which this
SessionCookieConfig was acquired shall be marked as
HttpOnly, false otherwise
Throws: - IllegalStateException – if the ServletContext
from which this SessionCookieConfig was acquired has
already been initialized
/**
* @param httpOnly true if the session tracking cookies created
* on behalf of the <tt>ServletContext</tt> from which this
* <tt>SessionCookieConfig</tt> was acquired shall be marked as
* <i>HttpOnly</i>, false otherwise
*
* @throws IllegalStateException if the <tt>ServletContext</tt>
* from which this <tt>SessionCookieConfig</tt> was acquired has
* already been initialized
*/
@Override
public void setHttpOnly(boolean httpOnly) {
if (ctx.deployed) {
throw new IllegalArgumentException("WebappContext has already been deployed");
}
this.httpOnly = httpOnly;
}
Returns: true if the session tracking cookies created on behalf of the
ServletContext from which this SessionCookieConfig
was acquired will be marked as HttpOnly, false otherwise
/**
* @return true if the session tracking cookies created on behalf of the
* <tt>ServletContext</tt> from which this <tt>SessionCookieConfig</tt>
* was acquired will be marked as <i>HttpOnly</i>, false otherwise
*/
@Override
public boolean isHttpOnly() {
return httpOnly;
}
Params: - secure – true if the session tracking cookies created on
behalf of the ServletContext from which this
SessionCookieConfig was acquired shall be marked as
secure even if the request that initiated the corresponding
session is using plain HTTP instead of HTTPS, and false if they
shall be marked as secure only if the request that initiated
the corresponding session was also secure
Throws: - IllegalStateException – if the ServletContext
from which this SessionCookieConfig was acquired has
already been initialized
/**
* @param secure true if the session tracking cookies created on
* behalf of the <tt>ServletContext</tt> from which this
* <tt>SessionCookieConfig</tt> was acquired shall be marked as
* <i>secure</i> even if the request that initiated the corresponding
* session is using plain HTTP instead of HTTPS, and false if they
* shall be marked as <i>secure</i> only if the request that initiated
* the corresponding session was also secure
*
* @throws IllegalStateException if the <tt>ServletContext</tt>
* from which this <tt>SessionCookieConfig</tt> was acquired has
* already been initialized
*/
@Override
public void setSecure(boolean secure) {
if (ctx.deployed) {
throw new IllegalArgumentException("WebappContext has already been deployed");
}
this.secure = secure;
}
Returns: true if the session tracking cookies created on behalf of the
ServletContext from which this SessionCookieConfig
was acquired will be marked as secure even if the request
that initiated the corresponding session is using plain HTTP
instead of HTTPS, and false if they will be marked as secure
only if the request that initiated the corresponding session was
also secure
/**
* @return true if the session tracking cookies created on behalf of the
* <tt>ServletContext</tt> from which this <tt>SessionCookieConfig</tt>
* was acquired will be marked as <i>secure</i> even if the request
* that initiated the corresponding session is using plain HTTP
* instead of HTTPS, and false if they will be marked as <i>secure</i>
* only if the request that initiated the corresponding session was
* also secure
*/
@Override
public boolean isSecure() {
return secure;
}
@Override
public void setMaxAge(int maxAge) {
if (ctx.deployed) {
throw new IllegalArgumentException("WebappContext has already been deployed");
}
this.maxAge = maxAge;
}
@Override
public int getMaxAge() {
return maxAge;
}
}