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.ProxiedSession;
20 
21 import hunt.shiro.session.Session;
22 
23 import hunt.Exceptions;
24 import hunt.util.Common;
25 import hunt.collection;
26 // // import java.util.Date;
27 
28 /**
29  * Simple <code>Session</code> implementation that immediately delegates all corresponding calls to an
30  * underlying proxied session instance.
31  * <p/>
32  * This class is mostly useful for framework subclassing to intercept certain <code>Session</code> calls
33  * and perform additional logic.
34  *
35  */
36 class ProxiedSession : Session {
37 
38     /**
39      * The proxied instance
40      */
41     protected Session session;
42 
43     /**
44      * Constructs an instance that proxies the specified <code>target</code>.  Subclasses may access this
45      * target via the <code>protected final 'session'</code> attribute, i.e. <code>this.session</code>.
46      *
47      * @param target the specified target <code>Session</code> to proxy.
48      */
49      this(Session target) {
50         if (target  is null) {
51             throw new IllegalArgumentException("Target session to proxy cannot be null.");
52         }
53         session = target;
54     }
55 
56     /**
57      * Immediately delegates to the underlying proxied session.
58      */
59     string getId() {
60         return session.getId();
61     }
62 
63     /**
64      * Immediately delegates to the underlying proxied session.
65      */
66     Date getStartTimestamp() {
67         return session.getStartTimestamp();
68     }
69 
70     /**
71      * Immediately delegates to the underlying proxied session.
72      */
73     Date getLastAccessTime() {
74         return session.getLastAccessTime();
75     }
76 
77     /**
78      * Immediately delegates to the underlying proxied session.
79      */
80     long getTimeout(){
81         return session.getTimeout();
82     }
83 
84     /**
85      * Immediately delegates to the underlying proxied session.
86      */
87     void setTimeout(long maxIdleTimeInMillis){
88         session.setTimeout(maxIdleTimeInMillis);
89     }
90 
91     /**
92      * Immediately delegates to the underlying proxied session.
93      */
94      string getHost() {
95         return session.getHost();
96     }
97 
98     /**
99      * Immediately delegates to the underlying proxied session.
100      */
101      void touch(){
102         session.touch();
103     }
104 
105     /**
106      * Immediately delegates to the underlying proxied session.
107      */
108      void stop(){
109         session.stop();
110     }
111 
112     /**
113      * Immediately delegates to the underlying proxied session.
114      */
115     Object[] getAttributeKeys(){
116         return session.getAttributeKeys();
117     }
118 
119     /**
120      * Immediately delegates to the underlying proxied session.
121      */
122     Object getAttribute(Object key){
123         return session.getAttribute(key);
124     }
125 
126     /**
127      * Immediately delegates to the underlying proxied session.
128      */
129     void setAttribute(Object key, Object value){
130         session.setAttribute(key, value);
131     }
132 
133     /**
134      * Immediately delegates to the underlying proxied session.
135      */
136      Object removeAttribute(Object key){
137         return session.removeAttribute(key);
138     }
139 
140 }