1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 module hunt.shiro.session.mgt.DefaultSessionContext;
20 
21 import hunt.shiro.session.mgt.SessionContext;
22 
23 import hunt.shiro.util.MapContext;
24 // import hunt.shiro.util.StringUtils;
25 
26 import hunt.String;
27 import hunt.util.Common;
28 import hunt.collection.Map;
29 
30 import std.array;
31 import std.traits;
32 
33 /**
34  * Default implementation of the {@link SessionContext} interface which provides getters and setters that
35  * wrap interaction with the underlying backing context map.
36  *
37  */
38 class DefaultSessionContext : MapContext, SessionContext {
39 
40     private enum string HOST = fullyQualifiedName!(DefaultSessionContext) ~ ".HOST";
41     private enum string SESSION_ID = fullyQualifiedName!(DefaultSessionContext) ~ ".SESSION_ID";
42 
43     this() {
44         super();
45     }
46 
47     this(Map!(string, Object) map) {
48         super(map);
49     }
50 
51     string getHost() {
52         String str = getTypedValue!String(HOST);
53         if(str is null)
54             return null;
55         return str.value;
56     }
57 
58     void setHost(string host) {
59         if (!host.empty()) {
60             put(HOST, new String(host));
61         }
62     }
63 
64     string getSessionId() {
65         return SESSION_ID; // getTypedValue!Serializable(SESSION_ID);
66     }
67 
68      void setSessionId(string sessionId) {
69         nullSafePut(SESSION_ID, new String(sessionId));
70     }
71 }