Class MongoIndexedSessionRepository

java.lang.Object
org.springframework.session.data.mongo.MongoIndexedSessionRepository
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationEventPublisherAware, FindByIndexNameSessionRepository<org.springframework.session.data.mongo.MongoSession>, SessionRepository<org.springframework.session.data.mongo.MongoSession>

public class MongoIndexedSessionRepository extends Object implements FindByIndexNameSessionRepository<org.springframework.session.data.mongo.MongoSession>, org.springframework.context.ApplicationEventPublisherAware, org.springframework.beans.factory.InitializingBean
Session repository implementation which stores sessions in Mongo. Uses AbstractMongoSessionConverter to transform session objects from/to native Mongo representation (DBObject). Repository is also responsible for removing expired sessions from database. Cleanup is done every minute.
Since:
2.2.0
  • Field Details

  • Constructor Details

    • MongoIndexedSessionRepository

      public MongoIndexedSessionRepository(org.springframework.data.mongodb.core.MongoOperations mongoOperations)
  • Method Details

    • createSession

      public org.springframework.session.data.mongo.MongoSession createSession()
      Description copied from interface: SessionRepository
      Creates a new Session that is capable of being persisted by this SessionRepository.

      This allows optimizations and customizations in how the Session is persisted. For example, the implementation returned might keep track of the changes ensuring that only the delta needs to be persisted on a save.

      Specified by:
      createSession in interface SessionRepository<org.springframework.session.data.mongo.MongoSession>
      Returns:
      a new Session that is capable of being persisted by this SessionRepository
    • save

      public void save(org.springframework.session.data.mongo.MongoSession session)
      Description copied from interface: SessionRepository
      Ensures the Session created by SessionRepository.createSession() is saved.

      Some implementations may choose to save as the Session is updated by returning a Session that immediately persists any changes. In this case, this method may not actually do anything.

      Specified by:
      save in interface SessionRepository<org.springframework.session.data.mongo.MongoSession>
      Parameters:
      session - the Session to save
    • findById

      @Nullable public org.springframework.session.data.mongo.MongoSession findById(String id)
      Description copied from interface: SessionRepository
      Gets the Session by the Session.getId() or null if no Session is found.
      Specified by:
      findById in interface SessionRepository<org.springframework.session.data.mongo.MongoSession>
      Parameters:
      id - the Session.getId() to lookup
      Returns:
      the Session by the Session.getId() or null if no Session is found.
    • findByIndexNameAndIndexValue

      public Map<String,org.springframework.session.data.mongo.MongoSession> findByIndexNameAndIndexValue(String indexName, String indexValue)
      Currently this repository allows only querying against PRINCIPAL_NAME_INDEX_NAME.
      Specified by:
      findByIndexNameAndIndexValue in interface FindByIndexNameSessionRepository<org.springframework.session.data.mongo.MongoSession>
      Parameters:
      indexName - the name if the index (i.e. FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME)
      indexValue - the value of the index to search for.
      Returns:
      sessions map
    • deleteById

      public void deleteById(String id)
      Description copied from interface: SessionRepository
      Deletes the Session with the given Session.getId() or does nothing if the Session is not found.
      Specified by:
      deleteById in interface SessionRepository<org.springframework.session.data.mongo.MongoSession>
      Parameters:
      id - the Session.getId() to delete
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • setApplicationEventPublisher

      public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher eventPublisher)
      Specified by:
      setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware
    • setDefaultMaxInactiveInterval

      public void setDefaultMaxInactiveInterval(Duration defaultMaxInactiveInterval)
      Set the maximum inactive interval in seconds between requests before newly created sessions will be invalidated. A negative time indicates that the session will never time out. The default is 30 minutes.
      Parameters:
      defaultMaxInactiveInterval - the default maxInactiveInterval
    • setMaxInactiveIntervalInSeconds

      @Deprecated(since="3.0.0") public void setMaxInactiveIntervalInSeconds(Integer defaultMaxInactiveInterval)
      Deprecated.
      Set the maximum inactive interval in seconds between requests before newly created sessions will be invalidated. A negative time indicates that the session will never time out. The default is 1800 (30 minutes).
      Parameters:
      defaultMaxInactiveInterval - the default maxInactiveInterval in seconds
    • setCollectionName

      public void setCollectionName(String collectionName)
    • setMongoSessionConverter

      public void setMongoSessionConverter(AbstractMongoSessionConverter mongoSessionConverter)