org.springframework.session.security.SpringSessionBackedSessionRegistry Maven / Gradle / Ivy
/*
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* 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 "AS IS" 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.springframework.session.security;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.springframework.security.core.session.SessionInformation;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.session.ExpiringSession;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.util.Assert;
/**
* A {@link SessionRegistry} that retrieves session information from Spring Session, rather than maintaining it itself.
* This allows concurrent session management with Spring Security in a clustered environment.
*
* Relies on being able to derive the same String-based representation of the principal given to
* {@link #getAllSessions(Object, boolean)} as used by Spring Session in order to look up the user's sessions.
*
* Does not support {@link #getAllPrincipals()}, since that information is not available.
*
* @author Joris Kuipers
* @since 1.3
*/
public class SpringSessionBackedSessionRegistry implements SessionRegistry {
private final FindByIndexNameSessionRepository sessionRepository;
public SpringSessionBackedSessionRegistry(FindByIndexNameSessionRepository sessionRepository) {
Assert.notNull(sessionRepository, "sessionRepository cannot be null");
this.sessionRepository = sessionRepository;
}
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy