001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web;
018
019import javax.servlet.ServletException;
020
021import org.springframework.lang.Nullable;
022
023/**
024 * Exception thrown when an HTTP request handler requires a pre-existing session.
025 *
026 * @author Juergen Hoeller
027 * @since 2.0
028 */
029@SuppressWarnings("serial")
030public class HttpSessionRequiredException extends ServletException {
031
032        @Nullable
033        private final String expectedAttribute;
034
035
036        /**
037         * Create a new HttpSessionRequiredException.
038         * @param msg the detail message
039         */
040        public HttpSessionRequiredException(String msg) {
041                super(msg);
042                this.expectedAttribute = null;
043        }
044
045        /**
046         * Create a new HttpSessionRequiredException.
047         * @param msg the detail message
048         * @param expectedAttribute the name of the expected session attribute
049         * @since 4.3
050         */
051        public HttpSessionRequiredException(String msg, String expectedAttribute) {
052                super(msg);
053                this.expectedAttribute = expectedAttribute;
054        }
055
056
057        /**
058         * Return the name of the expected session attribute, if any.
059         * @since 4.3
060         */
061        @Nullable
062        public String getExpectedAttribute() {
063                return this.expectedAttribute;
064        }
065
066}