congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
SessionRegistryImpl
Code IndexAdd Tabnine to your IDE (free)

How to use
SessionRegistryImpl
in
org.springframework.security.core.session

Best Java code snippets using org.springframework.security.core.session.SessionRegistryImpl (Showing top 20 results out of 315)

origin: 527515025/springBoot

  @Bean
  public SessionRegistry getSessionRegistry(){
    SessionRegistry sessionRegistry=new SessionRegistryImpl();
    return sessionRegistry;
  }
}
origin: spring-projects/spring-security

public void registerNewSession(String sessionId, Object principal) {
  Assert.hasText(sessionId, "SessionId required as per interface contract");
  Assert.notNull(principal, "Principal required as per interface contract");
  if (logger.isDebugEnabled()) {
    logger.debug("Registering session " + sessionId + ", for principal "
        + principal);
  }
  if (getSessionInformation(sessionId) != null) {
    removeSessionInformation(sessionId);
  }
  sessionIds.put(sessionId,
      new SessionInformation(principal, sessionId, new Date()));
  Set<String> sessionsUsedByPrincipal = principals.computeIfAbsent(principal, key -> new CopyOnWriteArraySet<>());
  sessionsUsedByPrincipal.add(sessionId);
  if (logger.isTraceEnabled()) {
    logger.trace("Sessions used by '" + principal + "' : "
        + sessionsUsedByPrincipal);
  }
}
origin: spring-projects/spring-security

@Test
public void testMultiplePrincipals() throws Exception {
  Object principal1 = "principal_1";
  Object principal2 = "principal_2";
  String sessionId1 = "1234567890";
  String sessionId2 = "9876543210";
  String sessionId3 = "5432109876";
  sessionRegistry.registerNewSession(sessionId1, principal1);
  sessionRegistry.registerNewSession(sessionId2, principal1);
  sessionRegistry.registerNewSession(sessionId3, principal2);
  assertThat(sessionRegistry.getAllPrincipals()).hasSize(2);
  assertThat(sessionRegistry.getAllPrincipals().contains(principal1)).isTrue();
  assertThat(sessionRegistry.getAllPrincipals().contains(principal2)).isTrue();
}
origin: spring-projects/spring-security

@Test
public void sessionDestroyedEventRemovesSessionFromRegistry() {
  Object principal = "Some principal object";
  final String sessionId = "zzzz";
  // Register new Session
  sessionRegistry.registerNewSession(sessionId, principal);
  // De-register session via an ApplicationEvent
  sessionRegistry.onApplicationEvent(new SessionDestroyedEvent("") {
    @Override
    public String getId() {
      return sessionId;
    }
    @Override
    public List<SecurityContext> getSecurityContexts() {
      return null;
    }
  });
  // Check attempts to retrieve cleared session return null
  assertThat(sessionRegistry.getSessionInformation(sessionId)).isNull();
}
origin: spring-projects/spring-security

@Test
public void testTwoSessionsOnePrincipalHandling() throws Exception {
  Object principal = "Some principal object";
  String sessionId1 = "1234567890";
  String sessionId2 = "9876543210";
  sessionRegistry.registerNewSession(sessionId1, principal);
  List<SessionInformation> sessions = sessionRegistry.getAllSessions(principal,
      false);
  assertThat(sessions).hasSize(1);
  assertThat(contains(sessionId1, principal)).isTrue();
  sessionRegistry.registerNewSession(sessionId2, principal);
  sessions = sessionRegistry.getAllSessions(principal, false);
  assertThat(sessions).hasSize(2);
  assertThat(contains(sessionId2, principal)).isTrue();
  sessionRegistry.removeSessionInformation(sessionId1);
  sessions = sessionRegistry.getAllSessions(principal, false);
  assertThat(sessions).hasSize(1);
  assertThat(contains(sessionId2, principal)).isTrue();
  sessionRegistry.removeSessionInformation(sessionId2);
  assertThat(sessionRegistry.getSessionInformation(sessionId2)).isNull();
  assertThat(sessionRegistry.getAllSessions(principal, false)).isEmpty();
}
origin: spring-projects/spring-security

public void refreshLastRequest(String sessionId) {
  Assert.hasText(sessionId, "SessionId required as per interface contract");
  SessionInformation info = getSessionInformation(sessionId);
  if (info != null) {
    info.refreshLastRequest();
  }
}
origin: spring-projects/spring-security

public void onApplicationEvent(SessionDestroyedEvent event) {
  String sessionId = event.getId();
  removeSessionInformation(sessionId);
}
origin: spring-projects/spring-security

@Test
public void testTwoSessionsOnePrincipalExpiring() throws Exception {
  Object principal = "Some principal object";
  String sessionId1 = "1234567890";
  String sessionId2 = "9876543210";
  sessionRegistry.registerNewSession(sessionId1, principal);
  List<SessionInformation> sessions = sessionRegistry.getAllSessions(principal,
      false);
  assertThat(sessions).hasSize(1);
  assertThat(contains(sessionId1, principal)).isTrue();
  sessionRegistry.registerNewSession(sessionId2, principal);
  sessions = sessionRegistry.getAllSessions(principal, false);
  assertThat(sessions).hasSize(2);
  assertThat(contains(sessionId2, principal)).isTrue();
  // Expire one session
  SessionInformation session = sessionRegistry.getSessionInformation(sessionId2);
  session.expireNow();
  // Check retrieval still correct
  assertThat(sessionRegistry.getSessionInformation(sessionId2).isExpired()).isTrue();
  assertThat(sessionRegistry.getSessionInformation(sessionId1).isExpired()).isFalse();
}
origin: spring-projects/spring-security

@Test
public void testSessionInformationLifecycle() throws Exception {
  Object principal = "Some principal object";
  String sessionId = "1234567890";
  // Register new Session
  sessionRegistry.registerNewSession(sessionId, principal);
  // Retrieve existing session by session ID
  Date currentDateTime = sessionRegistry.getSessionInformation(sessionId)
      .getLastRequest();
  assertThat(sessionRegistry.getSessionInformation(sessionId).getPrincipal()).isEqualTo(principal);
  assertThat(sessionRegistry.getSessionInformation(sessionId).getSessionId()).isEqualTo(sessionId);
  assertThat(sessionRegistry.getSessionInformation(sessionId).getLastRequest()).isNotNull();
  // Retrieve existing session by principal
  assertThat(sessionRegistry.getAllSessions(principal, false)).hasSize(1);
  // Sleep to ensure SessionRegistryImpl will update time
  Thread.sleep(1000);
  // Update request date/time
  sessionRegistry.refreshLastRequest(sessionId);
  Date retrieved = sessionRegistry.getSessionInformation(sessionId)
      .getLastRequest();
  assertThat(retrieved.after(currentDateTime)).isTrue();
  // Check it retrieves correctly when looked up via principal
  assertThat(sessionRegistry.getAllSessions(principal, false).get(0).getLastRequest()).isCloseTo(retrieved, 2000L);
  // Clear session information
  sessionRegistry.removeSessionInformation(sessionId);
  // Check attempts to retrieve cleared session return null
  assertThat(sessionRegistry.getSessionInformation(sessionId)).isNull();
  assertThat(sessionRegistry.getAllSessions(principal, false)).isEmpty();
}
origin: org.springframework.security/spring-security-core

public void refreshLastRequest(String sessionId) {
  Assert.hasText(sessionId, "SessionId required as per interface contract");
  SessionInformation info = getSessionInformation(sessionId);
  if (info != null) {
    info.refreshLastRequest();
  }
}
origin: org.springframework.security/spring-security-core

public void onApplicationEvent(SessionDestroyedEvent event) {
  String sessionId = event.getId();
  removeSessionInformation(sessionId);
}
origin: spring-projects/spring-security

private SessionRegistry getSessionRegistry(H http) {
  if (this.sessionRegistry == null) {
    SessionRegistryImpl sessionRegistry = new SessionRegistryImpl();
    registerDelegateApplicationListener(http, sessionRegistry);
    this.sessionRegistry = sessionRegistry;
  }
  return this.sessionRegistry;
}
origin: org.springframework.security/spring-security-core

public void registerNewSession(String sessionId, Object principal) {
  Assert.hasText(sessionId, "SessionId required as per interface contract");
  Assert.notNull(principal, "Principal required as per interface contract");
  if (logger.isDebugEnabled()) {
    logger.debug("Registering session " + sessionId + ", for principal "
        + principal);
  }
  if (getSessionInformation(sessionId) != null) {
    removeSessionInformation(sessionId);
  }
  sessionIds.put(sessionId,
      new SessionInformation(principal, sessionId, new Date()));
  Set<String> sessionsUsedByPrincipal = principals.computeIfAbsent(principal, key -> new CopyOnWriteArraySet<>());
  sessionsUsedByPrincipal.add(sessionId);
  if (logger.isTraceEnabled()) {
    logger.trace("Sessions used by '" + principal + "' : "
        + sessionsUsedByPrincipal);
  }
}
origin: spring-projects/spring-security

public List<SessionInformation> getAllSessions(Object principal,
    boolean includeExpiredSessions) {
  final Set<String> sessionsUsedByPrincipal = principals.get(principal);
  if (sessionsUsedByPrincipal == null) {
    return Collections.emptyList();
  }
  List<SessionInformation> list = new ArrayList<>(
      sessionsUsedByPrincipal.size());
  for (String sessionId : sessionsUsedByPrincipal) {
    SessionInformation sessionInformation = getSessionInformation(sessionId);
    if (sessionInformation == null) {
      continue;
    }
    if (includeExpiredSessions || !sessionInformation.isExpired()) {
      list.add(sessionInformation);
    }
  }
  return list;
}
origin: org.springframework.security/org.springframework.security.core

public void onApplicationEvent(SessionDestroyedEvent event) {
  String sessionId = event.getId();
  removeSessionInformation(sessionId);
}
origin: spring-projects/spring-security

@Before
public void setUp() throws Exception {
  sessionRegistry = new SessionRegistryImpl();
}
origin: apache/servicemix-bundles

public void registerNewSession(String sessionId, Object principal) {
  Assert.hasText(sessionId, "SessionId required as per interface contract");
  Assert.notNull(principal, "Principal required as per interface contract");
  if (logger.isDebugEnabled()) {
    logger.debug("Registering session " + sessionId + ", for principal "
        + principal);
  }
  if (getSessionInformation(sessionId) != null) {
    removeSessionInformation(sessionId);
  }
  sessionIds.put(sessionId,
      new SessionInformation(principal, sessionId, new Date()));
  Set<String> sessionsUsedByPrincipal = principals.computeIfAbsent(principal, key -> new CopyOnWriteArraySet<>());
  sessionsUsedByPrincipal.add(sessionId);
  if (logger.isTraceEnabled()) {
    logger.trace("Sessions used by '" + principal + "' : "
        + sessionsUsedByPrincipal);
  }
}
origin: org.springframework.security/spring-security-core

public List<SessionInformation> getAllSessions(Object principal,
    boolean includeExpiredSessions) {
  final Set<String> sessionsUsedByPrincipal = principals.get(principal);
  if (sessionsUsedByPrincipal == null) {
    return Collections.emptyList();
  }
  List<SessionInformation> list = new ArrayList<>(
      sessionsUsedByPrincipal.size());
  for (String sessionId : sessionsUsedByPrincipal) {
    SessionInformation sessionInformation = getSessionInformation(sessionId);
    if (sessionInformation == null) {
      continue;
    }
    if (includeExpiredSessions || !sessionInformation.isExpired()) {
      list.add(sessionInformation);
    }
  }
  return list;
}
origin: apache/servicemix-bundles

public void onApplicationEvent(SessionDestroyedEvent event) {
  String sessionId = event.getId();
  removeSessionInformation(sessionId);
}
origin: org.springframework.security/spring-security-config

private SessionRegistry getSessionRegistry(H http) {
  if (this.sessionRegistry == null) {
    SessionRegistryImpl sessionRegistry = new SessionRegistryImpl();
    registerDelegateApplicationListener(http, sessionRegistry);
    this.sessionRegistry = sessionRegistry;
  }
  return this.sessionRegistry;
}
org.springframework.security.core.sessionSessionRegistryImpl

Javadoc

Default implementation of org.springframework.security.core.session.SessionRegistry which listens for org.springframework.security.core.session.SessionDestroyedEvents published in the Spring application context.

For this class to function correctly in a web application, it is important that you register an HttpSessionEventPublisher in the web.xml file so that this class is notified of sessions that expire.

Most used methods

  • <init>
  • getSessionInformation
  • removeSessionInformation
  • getAllPrincipals
  • getAllSessions
  • onApplicationEvent
  • refreshLastRequest
  • registerNewSession

Popular in Java

  • Start an intent from android
  • addToBackStack (FragmentTransaction)
  • setScale (BigDecimal)
  • requestLocationUpdates (LocationManager)
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • Collectors (java.util.stream)
  • BoxLayout (javax.swing)
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • Top 17 Plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now