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;
020    
021    import java.io.Serializable;
022    import java.util.Collection;
023    import java.util.Date;
024    
025    /**
026     * Simple <code>Session</code> implementation that immediately delegates all corresponding calls to an
027     * underlying proxied session instance.
028     * <p/>
029     * This class is mostly useful for framework subclassing to intercept certain <code>Session</code> calls
030     * and perform additional logic.
031     *
032     * @author Les Hazlewood
033     * @since 0.9
034     */
035    public class ProxiedSession implements Session {
036    
037        /**
038         * The proxied instance
039         */
040        protected final Session delegate;
041    
042        /**
043         * Constructs an instance that proxies the specified <code>target</code>.  Subclasses may access this
044         * target via the <code>protected final 'delegate'</code> attribute, i.e. <code>this.delegate</code>.
045         *
046         * @param target the specified target <code>Session</code> to proxy.
047         */
048        public ProxiedSession(Session target) {
049            if (target == null) {
050                throw new IllegalArgumentException("Target session to proxy cannot be null.");
051            }
052            delegate = target;
053        }
054    
055        /**
056         * Immediately delegates to the underlying proxied session.
057         */
058        public Serializable getId() {
059            return delegate.getId();
060        }
061    
062        /**
063         * Immediately delegates to the underlying proxied session.
064         */
065        public Date getStartTimestamp() {
066            return delegate.getStartTimestamp();
067        }
068    
069        /**
070         * Immediately delegates to the underlying proxied session.
071         */
072        public Date getLastAccessTime() {
073            return delegate.getLastAccessTime();
074        }
075    
076        /**
077         * Immediately delegates to the underlying proxied session.
078         */
079        public long getTimeout() throws InvalidSessionException {
080            return delegate.getTimeout();
081        }
082    
083        /**
084         * Immediately delegates to the underlying proxied session.
085         */
086        public void setTimeout(long maxIdleTimeInMillis) throws InvalidSessionException {
087            delegate.setTimeout(maxIdleTimeInMillis);
088        }
089    
090        /**
091         * Immediately delegates to the underlying proxied session.
092         */
093        public String getHost() {
094            return delegate.getHost();
095        }
096    
097        /**
098         * Immediately delegates to the underlying proxied session.
099         */
100        public void touch() throws InvalidSessionException {
101            delegate.touch();
102        }
103    
104        /**
105         * Immediately delegates to the underlying proxied session.
106         */
107        public void stop() throws InvalidSessionException {
108            delegate.stop();
109        }
110    
111        /**
112         * Immediately delegates to the underlying proxied session.
113         */
114        public Collection<Object> getAttributeKeys() throws InvalidSessionException {
115            return delegate.getAttributeKeys();
116        }
117    
118        /**
119         * Immediately delegates to the underlying proxied session.
120         */
121        public Object getAttribute(Object key) throws InvalidSessionException {
122            return delegate.getAttribute(key);
123        }
124    
125        /**
126         * Immediately delegates to the underlying proxied session.
127         */
128        public void setAttribute(Object key, Object value) throws InvalidSessionException {
129            delegate.setAttribute(key, value);
130        }
131    
132        /**
133         * Immediately delegates to the underlying proxied session.
134         */
135        public Object removeAttribute(Object key) throws InvalidSessionException {
136            return delegate.removeAttribute(key);
137        }
138    
139    }