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