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 */
019package org.apache.shiro.session.mgt;
020
021import org.apache.shiro.util.MapContext;
022import org.apache.shiro.util.StringUtils;
023
024import java.io.Serializable;
025import 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 * @since 1.0
032 */
033public class DefaultSessionContext extends MapContext implements SessionContext {
034
035    private static final long serialVersionUID = -1424160751361252966L;
036
037    private static final String HOST = DefaultSessionContext.class.getName() + ".HOST";
038    private static final String SESSION_ID = DefaultSessionContext.class.getName() + ".SESSION_ID";
039
040    public DefaultSessionContext() {
041        super();
042    }
043
044    public DefaultSessionContext(Map<String, Object> map) {
045        super(map);
046    }
047
048    public String getHost() {
049        return getTypedValue(HOST, String.class);
050    }
051
052    public void setHost(String host) {
053        if (StringUtils.hasText(host)) {
054            put(HOST, host);
055        }
056    }
057
058    public Serializable getSessionId() {
059        return getTypedValue(SESSION_ID, Serializable.class);
060    }
061
062    public void setSessionId(Serializable sessionId) {
063        nullSafePut(SESSION_ID, sessionId);
064    }
065}