/** * Returns the string representation of this SimpleSession, equal to * <code>getClass().getName() + ",id=" + getId()</code>. * * @return the string representation of this SimpleSession, equal to * <code>getClass().getName() + ",id=" + getId()</code>. * @since 1.0 */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()).append(",id=").append(getId()); return sb.toString(); }
/** * Returns {@code true} if the specified argument is an {@code instanceof} {@code SimpleSession} and both * {@link #getId() id}s are equal. If the argument is a {@code SimpleSession} and either 'this' or the argument * does not yet have an ID assigned, the value of {@link #onEquals(SimpleSession) onEquals} is returned, which * does a necessary attribute-based comparison when IDs are not available. * <p/> * Do your best to ensure {@code SimpleSession} instances receive an ID very early in their lifecycle to * avoid the more expensive attributes-based comparison. * * @param obj the object to compare with this one for equality. * @return {@code true} if this object is equivalent to the specified argument, {@code false} otherwise. */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof SimpleSession) { SimpleSession other = (SimpleSession) obj; Serializable thisId = getId(); Serializable otherId = other.getId(); if (thisId != null && otherId != null) { return thisId.equals(otherId); } else { //fall back to an attribute based comparison: return onEquals(other); } } return false; }
getId() + "] is null. This value must be set at " + "least once, preferably at least upon instantiation. Please check the " + getClass().getName() + " implementation and ensure " + } else { if (log.isTraceEnabled()) { log.trace("No timeout for session with id [" + getId() + "]. Session is not considered expired.");
public void validate() throws InvalidSessionException { //check for stopped: if (isStopped()) { //timestamp is set, so the session is considered stopped: String msg = "Session with id [" + getId() + "] has been " + "explicitly stopped. No further interaction under this session is " + "allowed."; throw new StoppedSessionException(msg); } //check for expiration if (isTimedOut()) { expire(); //throw an exception explaining details of why it expired: Date lastAccessTime = getLastAccessTime(); long timeout = getTimeout(); Serializable sessionId = getId(); DateFormat df = DateFormat.getInstance(); String msg = "Session with id [" + sessionId + "] has expired. " + "Last access time: " + df.format(lastAccessTime) + ". Current time: " + df.format(new Date()) + ". Session timeout is set to " + timeout / MILLIS_PER_SECOND + " seconds (" + timeout / MILLIS_PER_MINUTE + " minutes)"; if (log.isTraceEnabled()) { log.trace(msg); } throw new ExpiredSessionException(msg); } }
/** * Returns the hashCode. If the {@link #getId() id} is not {@code null}, its hashcode is returned immediately. * If it is {@code null}, an attributes-based hashCode will be calculated and returned. * <p/> * Do your best to ensure {@code SimpleSession} instances receive an ID very early in their lifecycle to * avoid the more expensive attributes-based calculation. * * @return this object's hashCode * @since 1.0 */ @Override public int hashCode() { Serializable id = getId(); if (id != null) { return id.hashCode(); } int hashCode = getStartTimestamp() != null ? getStartTimestamp().hashCode() : 0; hashCode = 31 * hashCode + (getStopTimestamp() != null ? getStopTimestamp().hashCode() : 0); hashCode = 31 * hashCode + (getLastAccessTime() != null ? getLastAccessTime().hashCode() : 0); hashCode = 31 * hashCode + Long.valueOf(Math.max(getTimeout(), 0)).hashCode(); hashCode = 31 * hashCode + Boolean.valueOf(isExpired()).hashCode(); hashCode = 31 * hashCode + (getHost() != null ? getHost().hashCode() : 0); hashCode = 31 * hashCode + (getAttributes() != null ? getAttributes().hashCode() : 0); return hashCode; }
@Test(groups = "slow") public void testCRUD() throws Exception { // Note! We are testing the do* methods here to bypass the caching layer final JDBCSessionDao jdbcSessionDao = new JDBCSessionDao(dbi, roDbi); // Retrieve final SimpleSession session = createSession(); Assert.assertNull(jdbcSessionDao.doReadSession(session.getId())); // Create final Serializable sessionId = jdbcSessionDao.doCreate(session); final Session retrievedSession = jdbcSessionDao.doReadSession(sessionId); Assert.assertEquals(retrievedSession, session); // Update final String newHost = UUID.randomUUID().toString(); Assert.assertNotEquals(retrievedSession.getHost(), newHost); session.setHost(newHost); jdbcSessionDao.doUpdate(session); Assert.assertEquals(jdbcSessionDao.doReadSession(sessionId).getHost(), newHost); // Delete jdbcSessionDao.doDelete(session); Assert.assertNull(jdbcSessionDao.doReadSession(session.getId())); }
/** * Returns the string representation of this SimpleSession, equal to * <code>getClass().getName() + ",id=" + getId()</code>. * * @return the string representation of this SimpleSession, equal to * <code>getClass().getName() + ",id=" + getId()</code>. * @since 1.0 */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()).append(",id=").append(getId()); return sb.toString(); }
/** * Returns {@code true} if the specified argument is an {@code instanceof} {@code SimpleSession} and both * {@link #getId() id}s are equal. If the argument is a {@code SimpleSession} and either 'this' or the argument * does not yet have an ID assigned, the value of {@link #onEquals(SimpleSession) onEquals} is returned, which * does a necessary attribute-based comparison when IDs are not available. * <p/> * Do your best to ensure {@code SimpleSession} instances receive an ID very early in their lifecycle to * avoid the more expensive attributes-based comparison. * * @param obj the object to compare with this one for equality. * @return {@code true} if this object is equivalent to the specified argument, {@code false} otherwise. */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof SimpleSession) { SimpleSession other = (SimpleSession) obj; Serializable thisId = getId(); Serializable otherId = other.getId(); if (thisId != null && otherId != null) { return thisId.equals(otherId); } else { //fall back to an attribute based comparison: return onEquals(other); } } return false; }
getId() + "] is null. This value must be set at " + "least once, preferably at least upon instantiation. Please check the " + getClass().getName() + " implementation and ensure " + } else { if (log.isTraceEnabled()) { log.trace("No timeout for session with id [" + getId() + "]. Session is not considered expired.");
public void validate() throws InvalidSessionException { //check for stopped: if (isStopped()) { //timestamp is set, so the session is considered stopped: String msg = "Session with id [" + getId() + "] has been " + "explicitly stopped. No further interaction under this session is " + "allowed."; throw new StoppedSessionException(msg); } //check for expiration if (isTimedOut()) { expire(); //throw an exception explaining details of why it expired: Date lastAccessTime = getLastAccessTime(); long timeout = getTimeout(); Serializable sessionId = getId(); DateFormat df = DateFormat.getInstance(); String msg = "Session with id [" + sessionId + "] has expired. " + "Last access time: " + df.format(lastAccessTime) + ". Current time: " + df.format(new Date()) + ". Session timeout is set to " + timeout / MILLIS_PER_SECOND + " seconds (" + timeout / MILLIS_PER_MINUTE + " minutes)"; if (log.isTraceEnabled()) { log.trace(msg); } throw new ExpiredSessionException(msg); } }
/** * Returns the hashCode. If the {@link #getId() id} is not {@code null}, its hashcode is returned immediately. * If it is {@code null}, an attributes-based hashCode will be calculated and returned. * <p/> * Do your best to ensure {@code SimpleSession} instances receive an ID very early in their lifecycle to * avoid the more expensive attributes-based calculation. * * @return this object's hashCode * @since 1.0 */ @Override public int hashCode() { Serializable id = getId(); if (id != null) { return id.hashCode(); } int hashCode = getStartTimestamp() != null ? getStartTimestamp().hashCode() : 0; hashCode = 31 * hashCode + (getStopTimestamp() != null ? getStopTimestamp().hashCode() : 0); hashCode = 31 * hashCode + (getLastAccessTime() != null ? getLastAccessTime().hashCode() : 0); hashCode = 31 * hashCode + Long.valueOf(Math.max(getTimeout(), 0)).hashCode(); hashCode = 31 * hashCode + Boolean.valueOf(isExpired()).hashCode(); hashCode = 31 * hashCode + (getHost() != null ? getHost().hashCode() : 0); hashCode = 31 * hashCode + (getAttributes() != null ? getAttributes().hashCode() : 0); return hashCode; }
/** * Returns the string representation of this SimpleSession, equal to * <code>getClass().getName() + ",id=" + getId()</code>. * * @return the string representation of this SimpleSession, equal to * <code>getClass().getName() + ",id=" + getId()</code>. * @since 1.0 */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()).append(",id=").append(getId()); return sb.toString(); }
/** * Returns {@code true} if the specified argument is an {@code instanceof} {@code SimpleSession} and both * {@link #getId() id}s are equal. If the argument is a {@code SimpleSession} and either 'this' or the argument * does not yet have an ID assigned, the value of {@link #onEquals(SimpleSession) onEquals} is returned, which * does a necessary attribute-based comparison when IDs are not available. * <p/> * Do your best to ensure {@code SimpleSession} instances receive an ID very early in their lifecycle to * avoid the more expensive attributes-based comparison. * * @param obj the object to compare with this one for equality. * @return {@code true} if this object is equivalent to the specified argument, {@code false} otherwise. */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof SimpleSession) { SimpleSession other = (SimpleSession) obj; Serializable thisId = getId(); Serializable otherId = other.getId(); if (thisId != null && otherId != null) { return thisId.equals(otherId); } else { //fall back to an attribute based comparison: return onEquals(other); } } return false; }
@Override public Session start(SessionContext context) { log.debug("starting VaadinSessionManager"); // Retrieve the VaadinSession for the current user. VaadinSession vaadinSession = sessionProvider.get(); // Create a new security session using the session factory. SimpleSession shiroSession = (SimpleSession) sessionFactory.createSession(context); // Assign a unique ID to the session now because this session manager // doesn't use a SessionDAO for persistence as it delegates to any // VaadinSession configured persistence. shiroSession.setId(UUID.randomUUID() .toString()); // Put the security session in the VaadinSession. We use the session's ID as // part of the key just to be safe so we can double check that the security // session matches when it is requested in getSession. vaadinSession.setAttribute(SESSION_ATTRIBUTE_PREFIX + shiroSession.getId(), shiroSession); return shiroSession; }
@Override public Session start(SessionContext context) { log.debug("starting VaadinSessionManager"); // Retrieve the VaadinSession for the current user. VaadinSession vaadinSession = sessionProvider.get(); // Create a new security session using the session factory. SimpleSession shiroSession = (SimpleSession) sessionFactory.createSession(context); // Assign a unique ID to the session now because this session manager // doesn't use a SessionDAO for persistence as it delegates to any // VaadinSession configured persistence. shiroSession.setId(UUID.randomUUID() .toString()); // Put the security session in the VaadinSession. We use the session's ID as // part of the key just to be safe so we can double check that the security // session matches when it is requested in getSession. vaadinSession.setAttribute(SESSION_ATTRIBUTE_PREFIX + shiroSession.getId(), shiroSession); return shiroSession; }
public void validate() throws InvalidSessionException { //check for stopped: if (isStopped()) { //timestamp is set, so the session is considered stopped: String msg = "Session with id [" + getId() + "] has been " + "explicitly stopped. No further interaction under this session is " + "allowed."; throw new StoppedSessionException(msg); } //check for expiration if (isTimedOut()) { expire(); //throw an exception explaining details of why it expired: Date lastAccessTime = getLastAccessTime(); long timeout = getTimeout(); Serializable sessionId = getId(); DateFormat df = DateFormat.getInstance(); String msg = "Session with id [" + sessionId + "] has expired. " + "Last access time: " + df.format(lastAccessTime) + ". Current time: " + df.format(new Date()) + ". Session timeout is set to " + timeout / MILLIS_PER_SECOND + " seconds (" + timeout / MILLIS_PER_MINUTE + " minutes)"; if (log.isTraceEnabled()) { log.trace(msg); } throw new ExpiredSessionException(msg); } }
/** * Returns the hashCode. If the {@link #getId() id} is not {@code null}, its hashcode is returned immediately. * If it is {@code null}, an attributes-based hashCode will be calculated and returned. * <p/> * Do your best to ensure {@code SimpleSession} instances receive an ID very early in their lifecycle to * avoid the more expensive attributes-based calculation. * * @return this object's hashCode * @since 1.0 */ @Override public int hashCode() { Serializable id = getId(); if (id != null) { return id.hashCode(); } int hashCode = getStartTimestamp() != null ? getStartTimestamp().hashCode() : 0; hashCode = 31 * hashCode + (getStopTimestamp() != null ? getStopTimestamp().hashCode() : 0); hashCode = 31 * hashCode + (getLastAccessTime() != null ? getLastAccessTime().hashCode() : 0); hashCode = 31 * hashCode + Long.valueOf(Math.max(getTimeout(), 0)).hashCode(); hashCode = 31 * hashCode + Boolean.valueOf(isExpired()).hashCode(); hashCode = 31 * hashCode + (getHost() != null ? getHost().hashCode() : 0); hashCode = 31 * hashCode + (getAttributes() != null ? getAttributes().hashCode() : 0); return hashCode; }
@Test(groups = "slow") public void testCRUD() throws Exception { // Note! We are testing the do* methods here to bypass the caching layer final JDBCSessionDao jdbcSessionDao = new JDBCSessionDao((DBI) dbi); // Retrieve final SimpleSession session = createSession(); Assert.assertNull(jdbcSessionDao.doReadSession(session.getId())); // Create final Serializable sessionId = jdbcSessionDao.doCreate(session); final Session retrievedSession = jdbcSessionDao.doReadSession(sessionId); Assert.assertEquals(retrievedSession, session); // Update final String newHost = UUID.randomUUID().toString(); Assert.assertNotEquals(retrievedSession.getHost(), newHost); session.setHost(newHost); jdbcSessionDao.doUpdate(session); Assert.assertEquals(jdbcSessionDao.doReadSession(sessionId).getHost(), newHost); // Delete jdbcSessionDao.doDelete(session); Assert.assertNull(jdbcSessionDao.doReadSession(session.getId())); }
@Test(groups = "slow") public void testCRUD() throws Exception { // Note! We are testing the do* methods here to bypass the caching layer final JDBCSessionDao jdbcSessionDao = new JDBCSessionDao(dbi, roDbi); // Retrieve final SimpleSession session = createSession(); Assert.assertNull(jdbcSessionDao.doReadSession(session.getId())); // Create final Serializable sessionId = jdbcSessionDao.doCreate(session); final Session retrievedSession = jdbcSessionDao.doReadSession(sessionId); Assert.assertEquals(retrievedSession, session); // Update final String newHost = UUID.randomUUID().toString(); Assert.assertNotEquals(retrievedSession.getHost(), newHost); session.setHost(newHost); jdbcSessionDao.doUpdate(session); Assert.assertEquals(jdbcSessionDao.doReadSession(sessionId).getHost(), newHost); // Delete jdbcSessionDao.doDelete(session); Assert.assertNull(jdbcSessionDao.doReadSession(session.getId())); }