@WithMockUser(username = "user") @Test void testGetSecurityContextsUserThreadNoUserSessions() { SecurityContext securityContext = SecurityContextHolder.getContext(); Object user = securityContext.getAuthentication().getPrincipal(); assertEquals( singletonList(securityContext), principalSecurityContextRegistryImpl.getSecurityContexts(user).collect(toList())); }
@Override public Stream<SecurityContext> getSecurityContexts(Object principal) { Set<SecurityContext> securityContexts = new HashSet<>(); SecurityContext currentExecutionThreadSecurityContext = getSecurityContextCurrentExecutionThread(principal); if (currentExecutionThreadSecurityContext != null) { securityContexts.add(currentExecutionThreadSecurityContext); } getSecurityContextsFromRegistry(principal).forEach(securityContexts::add); return securityContexts.stream(); }
PrincipalSecurityContextRegistryImpl implements PrincipalSecurityContextRegistry { @Override public Stream<SecurityContext> getSecurityContexts(Object principal) { Set<SecurityContext> securityContexts = new HashSet<>(); SecurityContext currentExecutionThreadSecurityContext = getSecurityContextCurrentExecutionThread(principal); if (currentExecutionThreadSecurityContext != null) { securityContexts.add(currentExecutionThreadSecurityContext); } getSecurityContextsFromRegistry(principal).forEach(securityContexts::add); return securityContexts.stream(); } }
PrincipalSecurityContextRegistryImpl implements PrincipalSecurityContextRegistry { @Override public Stream<SecurityContext> getSecurityContexts(Object principal) { Set<SecurityContext> securityContexts = new HashSet<>(); SecurityContext currentExecutionThreadSecurityContext = getSecurityContextCurrentExecutionThread(principal); if (currentExecutionThreadSecurityContext != null) { securityContexts.add(currentExecutionThreadSecurityContext); } getSecurityContextsFromRegistry(principal).forEach(securityContexts::add); return securityContexts.stream(); } PrincipalSecurityContextRegistryImpl(SecurityContextRegistry securityContextRegistry); }
PrincipalSecurityContextRegistryImpl implements PrincipalSecurityContextRegistry { @Override public Stream<SecurityContext> getSecurityContexts(Object principal) { Set<SecurityContext> securityContexts = new HashSet<>(); SecurityContext currentExecutionThreadSecurityContext = getSecurityContextCurrentExecutionThread(principal); if (currentExecutionThreadSecurityContext != null) { securityContexts.add(currentExecutionThreadSecurityContext); } getSecurityContextsFromRegistry(principal).forEach(securityContexts::add); return securityContexts.stream(); } PrincipalSecurityContextRegistryImpl(SecurityContextRegistry securityContextRegistry); @Override Stream<SecurityContext> getSecurityContexts(Object principal); }
PrincipalSecurityContextRegistryImpl implements PrincipalSecurityContextRegistry { @Override public Stream<SecurityContext> getSecurityContexts(Object principal) { Set<SecurityContext> securityContexts = new HashSet<>(); SecurityContext currentExecutionThreadSecurityContext = getSecurityContextCurrentExecutionThread(principal); if (currentExecutionThreadSecurityContext != null) { securityContexts.add(currentExecutionThreadSecurityContext); } getSecurityContextsFromRegistry(principal).forEach(securityContexts::add); return securityContexts.stream(); } PrincipalSecurityContextRegistryImpl(SecurityContextRegistry securityContextRegistry); @Override Stream<SecurityContext> getSecurityContexts(Object principal);  }