Package org.pac4j.core.profile
Class ProfileManager<U extends UserProfile>
- java.lang.Object
-
- org.pac4j.core.profile.ProfileManager<U>
-
public class ProfileManager<U extends UserProfile> extends Object
This class is a generic way to manage the current user profile(s), i.e. the one(s) of the current authenticated user.- Since:
- 1.8.0
- Author:
- Jerome Leleu
-
-
Field Summary
Fields Modifier and Type Field Description protected Config
config
protected WebContext
context
protected org.slf4j.Logger
logger
protected SessionStore
sessionStore
-
Constructor Summary
Constructors Constructor Description ProfileManager(WebContext context)
ProfileManager(WebContext context, SessionStore sessionStore)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<U>
get(boolean readFromSession)
Retrieve the first user profile if it exists, ignoring anyAnonymousProfile
if possible.List<U>
getAll(boolean readFromSession)
Retrieve all user profiles.List<U>
getAllLikeDefaultSecurityLogic(boolean readFromSessionDefault)
Retrieve all user profiles.Config
getConfig()
Optional<U>
getLikeDefaultSecurityLogic(boolean readFromSessionDefault)
Retrieve the first user profile if it exists, ignoring anyAnonymousProfile
if possible.boolean
isAuthenticated()
Tests if the current user is authenticated (meaning a user profile exists which is not anAnonymousProfile
).void
logout()
Perform a logout by removing the current user profile(s).void
remove(boolean removeFromSession)
Remove the current user profile(s).protected void
removeOrRenewExpiredProfiles(LinkedHashMap<String,U> profiles, boolean readFromSession)
protected LinkedHashMap<String,U>
retrieveAll(boolean readFromSession)
Retrieve the map of profiles from the session or the request.protected String
retrieveClientName(U profile)
protected boolean
retrieveLoadProfilesFromSession(boolean readFromSessionDefault)
Compute whether we must read the user profiles from the session.void
save(boolean saveInSession, U profile, boolean multiProfile)
Save the given user profile (replace the current one if multi profiles are not supported, add it otherwise).protected void
saveAll(LinkedHashMap<String,U> profiles, boolean saveInSession)
void
setConfig(Config config)
void
setSessionStore(SessionStore sessionStore)
-
-
-
Field Detail
-
logger
protected final org.slf4j.Logger logger
-
context
protected final WebContext context
-
sessionStore
protected SessionStore sessionStore
-
config
protected Config config
-
-
Constructor Detail
-
ProfileManager
public ProfileManager(WebContext context)
-
ProfileManager
@Deprecated public ProfileManager(WebContext context, SessionStore sessionStore)
Deprecated.
-
-
Method Detail
-
setSessionStore
public void setSessionStore(SessionStore sessionStore)
-
get
public Optional<U> get(boolean readFromSession)
Retrieve the first user profile if it exists, ignoring anyAnonymousProfile
if possible.- Parameters:
readFromSession
- if the user profile must be read from session- Returns:
- the user profile
-
getLikeDefaultSecurityLogic
public Optional<U> getLikeDefaultSecurityLogic(boolean readFromSessionDefault)
Retrieve the first user profile if it exists, ignoring anyAnonymousProfile
if possible. From the session or not, depending on the behavior which occured in theDefaultSecurityLogic
.- Parameters:
readFromSessionDefault
- if the user profile must be read from session otherwise- Returns:
- the user profile
-
retrieveLoadProfilesFromSession
protected boolean retrieveLoadProfilesFromSession(boolean readFromSessionDefault)
Compute whether we must read the user profiles from the session. (depending on theDefaultSecurityLogic
behavior).- Parameters:
readFromSessionDefault
- if the user profile(s) must be read from session otherwise- Returns:
- whether we must read the user profiles from the session
-
getAll
public List<U> getAll(boolean readFromSession)
Retrieve all user profiles.- Parameters:
readFromSession
- if the user profiles must be read from session- Returns:
- the user profiles
-
getAllLikeDefaultSecurityLogic
public List<U> getAllLikeDefaultSecurityLogic(boolean readFromSessionDefault)
Retrieve all user profiles. From the session or not, depending on the behavior which occured in theDefaultSecurityLogic
.- Parameters:
readFromSessionDefault
- if the user profiles must be read from session otherwise- Returns:
- the user profiles
-
retrieveAll
protected LinkedHashMap<String,U> retrieveAll(boolean readFromSession)
Retrieve the map of profiles from the session or the request.- Parameters:
readFromSession
- if the user profiles must be read from session- Returns:
- the map of profiles
-
removeOrRenewExpiredProfiles
protected void removeOrRenewExpiredProfiles(LinkedHashMap<String,U> profiles, boolean readFromSession)
-
remove
public void remove(boolean removeFromSession)
Remove the current user profile(s).- Parameters:
removeFromSession
- if the user profile(s) must be removed from session
-
save
public void save(boolean saveInSession, U profile, boolean multiProfile)
Save the given user profile (replace the current one if multi profiles are not supported, add it otherwise).- Parameters:
saveInSession
- if the user profile must be saved in sessionprofile
- a given user profilemultiProfile
- whether multiple profiles are supported
-
saveAll
protected void saveAll(LinkedHashMap<String,U> profiles, boolean saveInSession)
-
logout
public void logout()
Perform a logout by removing the current user profile(s).
-
isAuthenticated
public boolean isAuthenticated()
Tests if the current user is authenticated (meaning a user profile exists which is not anAnonymousProfile
).- Returns:
- whether the current user is authenticated
-
getConfig
public Config getConfig()
-
setConfig
public void setConfig(Config config)
-
-