001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    package org.apache.shiro.session.mgt;
020    
021    import org.apache.shiro.util.MapContext;
022    import org.apache.shiro.util.StringUtils;
023    
024    import java.io.Serializable;
025    import java.util.Map;
026    
027    /**
028     * Default implementation of the {@link SessionContext} interface which provides getters and setters that
029     * wrap interaction with the underlying backing context map.
030     *
031     * @author Les Hazlewood
032     * @since 1.0
033     */
034    public class DefaultSessionContext extends MapContext implements SessionContext {
035    
036        private static final long serialVersionUID = -1424160751361252966L;
037    
038        private static final String HOST = DefaultSessionContext.class.getName() + ".HOST";
039        private static final String SESSION_ID = DefaultSessionContext.class.getName() + ".SESSION_ID";
040    
041        public DefaultSessionContext() {
042            super();
043        }
044    
045        public DefaultSessionContext(Map<String, Object> map) {
046            super(map);
047        }
048    
049        public String getHost() {
050            return getTypedValue(HOST, String.class);
051        }
052    
053        public void setHost(String host) {
054            if (StringUtils.hasText(host)) {
055                put(HOST, host);
056            }
057        }
058    
059        public Serializable getSessionId() {
060            return getTypedValue(SESSION_ID, Serializable.class);
061        }
062    
063        public void setSessionId(Serializable sessionId) {
064            nullSafePut(SESSION_ID, sessionId);
065        }
066    }