2016-02-03 10:20:22 +00:00
/ *
* Copyright 2016 Red Hat , Inc . and / or its affiliates
* and other contributors as indicated by the @author tags .
*
* 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 .
* /
2015-07-17 11:45:43 +00:00
package org.keycloak.models ;
import org.keycloak.provider.Provider ;
import java.util.List ;
2017-05-29 19:25:44 +00:00
import java.util.function.Predicate ;
2015-07-17 11:45:43 +00:00
/ * *
* @author < a href = " mailto:bill@burkecentral.com " > Bill Burke < / a >
* @version $Revision : 1 $
* /
public interface UserSessionProvider extends Provider {
2017-03-27 09:23:25 +00:00
AuthenticatedClientSessionModel createClientSession ( RealmModel realm , ClientModel client , UserSessionModel userSession ) ;
2015-07-17 11:45:43 +00:00
2017-03-27 20:41:36 +00:00
UserSessionModel createUserSession ( String id , RealmModel realm , UserModel user , String loginUsername , String ipAddress , String authMethod , boolean rememberMe , String brokerSessionId , String brokerUserId ) ;
2015-07-17 11:45:43 +00:00
UserSessionModel getUserSession ( RealmModel realm , String id ) ;
List < UserSessionModel > getUserSessions ( RealmModel realm , UserModel user ) ;
List < UserSessionModel > getUserSessions ( RealmModel realm , ClientModel client ) ;
List < UserSessionModel > getUserSessions ( RealmModel realm , ClientModel client , int firstResult , int maxResults ) ;
List < UserSessionModel > getUserSessionByBrokerUserId ( RealmModel realm , String brokerUserId ) ;
UserSessionModel getUserSessionByBrokerSessionId ( RealmModel realm , String brokerSessionId ) ;
2017-05-29 19:25:44 +00:00
/ * *
* Return userSession of specified ID as long as the predicate passes . Otherwise returs null .
* If predicate doesn ' t pass , implementation can do some best - effort actions to try have predicate passing ( eg . download userSession from other DC )
* /
UserSessionModel getUserSessionWithPredicate ( RealmModel realm , String id , boolean offline , Predicate < UserSessionModel > predicate ) ;
2016-01-05 18:15:26 +00:00
long getActiveUserSessions ( RealmModel realm , ClientModel client ) ;
2017-03-06 10:39:47 +00:00
2017-04-21 12:24:47 +00:00
/** This will remove attached ClientLoginSessionModels too **/
2015-07-17 11:45:43 +00:00
void removeUserSession ( RealmModel realm , UserSessionModel session ) ;
void removeUserSessions ( RealmModel realm , UserModel user ) ;
2015-10-05 14:52:45 +00:00
2017-04-21 12:24:47 +00:00
/** Implementation should propagate removal of expired userSessions to userSessionPersister too **/
2016-01-05 18:15:26 +00:00
void removeExpired ( RealmModel realm ) ;
2015-07-17 11:45:43 +00:00
void removeUserSessions ( RealmModel realm ) ;
2016-06-13 10:46:18 +00:00
UserLoginFailureModel getUserLoginFailure ( RealmModel realm , String userId ) ;
UserLoginFailureModel addUserLoginFailure ( RealmModel realm , String userId ) ;
void removeUserLoginFailure ( RealmModel realm , String userId ) ;
2015-07-22 16:30:52 +00:00
void removeAllUserLoginFailures ( RealmModel realm ) ;
2015-07-17 11:45:43 +00:00
void onRealmRemoved ( RealmModel realm ) ;
void onClientRemoved ( RealmModel realm , ClientModel client ) ;
2017-04-21 12:24:47 +00:00
/** Newly created userSession won't contain attached AuthenticatedClientSessions **/
2015-10-05 14:52:45 +00:00
UserSessionModel createOfflineUserSession ( UserSessionModel userSession ) ;
UserSessionModel getOfflineUserSession ( RealmModel realm , String userSessionId ) ;
2017-04-21 12:24:47 +00:00
/** Removes the attached clientSessions as well **/
2016-02-19 10:49:30 +00:00
void removeOfflineUserSession ( RealmModel realm , UserSessionModel userSession ) ;
2015-10-05 14:52:45 +00:00
2017-04-21 12:24:47 +00:00
/** Will automatically attach newly created offline client session to the offlineUserSession **/
AuthenticatedClientSessionModel createOfflineClientSession ( AuthenticatedClientSessionModel clientSession , UserSessionModel offlineUserSession ) ;
2017-03-06 10:39:47 +00:00
List < UserSessionModel > getOfflineUserSessions ( RealmModel realm , UserModel user ) ;
2015-10-05 14:52:45 +00:00
2016-01-05 18:15:26 +00:00
long getOfflineSessionsCount ( RealmModel realm , ClientModel client ) ;
2015-10-05 14:52:45 +00:00
List < UserSessionModel > getOfflineUserSessions ( RealmModel realm , ClientModel client , int first , int max ) ;
2017-04-21 12:24:47 +00:00
/** Triggered by persister during pre-load. It optionally imports authenticatedClientSessions too if requested. Otherwise the imported UserSession will have empty list of AuthenticationSessionModel **/
UserSessionModel importUserSession ( UserSessionModel persistentUserSession , boolean offline , boolean importAuthenticatedClientSessions ) ;
2015-10-15 18:46:08 +00:00
2015-07-17 11:45:43 +00:00
void close ( ) ;
}