blob: 40e4fd5aab2d9e7bd6a5148558716c1b6cd327b8 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>DelegatingSession.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">Apache Shiro :: Jar Bundle</a> &gt; <a href="../index.html" class="el_bundle">shiro-core</a> &gt; <a href="index.source.html" class="el_package">org.apache.shiro.session.mgt</a> &gt; <span class="el_source">DelegatingSession.java</span></div><h1>DelegatingSession.java</h1><pre class="source lang-java linenums">/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* &quot;License&quot;); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.shiro.session.mgt;
import org.apache.shiro.session.InvalidSessionException;
import org.apache.shiro.session.Session;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
/**
* A DelegatingSession is a client-tier representation of a server side
* {@link org.apache.shiro.session.Session Session}.
* This implementation is basically a proxy to a server-side {@link NativeSessionManager NativeSessionManager},
* which will return the proper results for each method call.
* &lt;p/&gt;
* &lt;p&gt;A &lt;tt&gt;DelegatingSession&lt;/tt&gt; will cache data when appropriate to avoid a remote method invocation,
* only communicating with the server when necessary.
* &lt;p/&gt;
* &lt;p&gt;Of course, if used in-process with a NativeSessionManager business POJO, as might be the case in a
* web-based application where the web classes and server-side business pojos exist in the same
* JVM, a remote method call will not be incurred.
*
* @since 0.1
*/
public class DelegatingSession implements Session, Serializable {
//TODO - complete JavaDoc
private final SessionKey key;
//cached fields to avoid a server-side method call if out-of-process:
<span class="fc" id="L50"> private Date startTimestamp = null;</span>
<span class="fc" id="L51"> private String host = null;</span>
/**
* Handle to the target NativeSessionManager that will support the delegate calls.
*/
private final transient NativeSessionManager sessionManager;
<span class="fc" id="L59"> public DelegatingSession(NativeSessionManager sessionManager, SessionKey key) {</span>
<span class="pc bpc" id="L60" title="1 of 2 branches missed."> if (sessionManager == null) {</span>
<span class="nc" id="L61"> throw new IllegalArgumentException(&quot;sessionManager argument cannot be null.&quot;);</span>
}
<span class="pc bpc" id="L63" title="1 of 2 branches missed."> if (key == null) {</span>
<span class="nc" id="L64"> throw new IllegalArgumentException(&quot;sessionKey argument cannot be null.&quot;);</span>
}
<span class="pc bpc" id="L66" title="1 of 2 branches missed."> if (key.getSessionId() == null) {</span>
<span class="nc" id="L67"> String msg = &quot;The &quot; + DelegatingSession.class.getName() + &quot; implementation requires that the &quot; +</span>
&quot;SessionKey argument returns a non-null sessionId to support the &quot; +
&quot;Session.getId() invocations.&quot;;
<span class="nc" id="L70"> throw new IllegalArgumentException(msg);</span>
}
<span class="fc" id="L72"> this.sessionManager = sessionManager;</span>
<span class="fc" id="L73"> this.key = key;</span>
<span class="fc" id="L74"> }</span>
/**
* @see org.apache.shiro.session.Session#getId()
*/
public Serializable getId() {
<span class="fc" id="L80"> return key.getSessionId();</span>
}
/**
* @see org.apache.shiro.session.Session#getStartTimestamp()
*/
public Date getStartTimestamp() {
<span class="nc bnc" id="L87" title="All 2 branches missed."> if (startTimestamp == null) {</span>
<span class="nc" id="L88"> startTimestamp = sessionManager.getStartTimestamp(key);</span>
}
<span class="nc" id="L90"> return startTimestamp;</span>
}
/**
* @see org.apache.shiro.session.Session#getLastAccessTime()
*/
public Date getLastAccessTime() {
//can't cache - only business pojo knows the accurate time:
<span class="nc" id="L98"> return sessionManager.getLastAccessTime(key);</span>
}
public long getTimeout() throws InvalidSessionException {
<span class="fc" id="L102"> return sessionManager.getTimeout(key);</span>
}
public void setTimeout(long maxIdleTimeInMillis) throws InvalidSessionException {
<span class="fc" id="L106"> sessionManager.setTimeout(key, maxIdleTimeInMillis);</span>
<span class="fc" id="L107"> }</span>
public String getHost() {
<span class="pc bpc" id="L110" title="1 of 2 branches missed."> if (host == null) {</span>
<span class="fc" id="L111"> host = sessionManager.getHost(key);</span>
}
<span class="fc" id="L113"> return host;</span>
}
/**
* @see org.apache.shiro.session.Session#touch()
*/
public void touch() throws InvalidSessionException {
<span class="fc" id="L120"> sessionManager.touch(key);</span>
<span class="fc" id="L121"> }</span>
/**
* @see org.apache.shiro.session.Session#stop()
*/
public void stop() throws InvalidSessionException {
<span class="fc" id="L127"> sessionManager.stop(key);</span>
<span class="fc" id="L128"> }</span>
/**
* @see org.apache.shiro.session.Session#getAttributeKeys
*/
public Collection&lt;Object&gt; getAttributeKeys() throws InvalidSessionException {
<span class="nc" id="L134"> return sessionManager.getAttributeKeys(key);</span>
}
/**
* @see org.apache.shiro.session.Session#getAttribute(Object key)
*/
public Object getAttribute(Object attributeKey) throws InvalidSessionException {
<span class="fc" id="L141"> return sessionManager.getAttribute(this.key, attributeKey);</span>
}
/**
* @see Session#setAttribute(Object key, Object value)
*/
public void setAttribute(Object attributeKey, Object value) throws InvalidSessionException {
<span class="pc bpc" id="L148" title="1 of 2 branches missed."> if (value == null) {</span>
<span class="nc" id="L149"> removeAttribute(attributeKey);</span>
} else {
<span class="fc" id="L151"> sessionManager.setAttribute(this.key, attributeKey, value);</span>
}
<span class="fc" id="L153"> }</span>
/**
* @see Session#removeAttribute(Object key)
*/
public Object removeAttribute(Object attributeKey) throws InvalidSessionException {
<span class="fc" id="L159"> return sessionManager.removeAttribute(this.key, attributeKey);</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.7.201606060606</span></div></body></html>