Package org.pac4j.core.profile
Class ProfileManager
- java.lang.Object
-
- org.pac4j.core.profile.ProfileManager
-
public class ProfileManager extends java.lang.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, SessionStore sessionStore)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Config
getConfig()
java.util.Optional<UserProfile>
getProfile()
Retrieve the first user profile if it exists, ignoring anyAnonymousProfile
if possible.<U extends UserProfile>
java.util.Optional<U>getProfile(java.lang.Class<U> clazz)
java.util.List<UserProfile>
getProfiles()
Retrieve all user profiles.boolean
isAuthenticated()
Tests if the current user is authenticated (meaning a user profile exists which is not anAnonymousProfile
).protected void
removeOrRenewExpiredProfiles(java.util.LinkedHashMap<java.lang.String,UserProfile> profiles, boolean readFromSession)
void
removeProfiles()
Remove the current user profile(s).protected java.util.LinkedHashMap<java.lang.String,UserProfile>
retrieveAll(boolean readFromSession)
Retrieve the map of profiles from the session or the request.protected java.lang.String
retrieveClientName(UserProfile profile)
void
save(boolean saveInSession, UserProfile profile, boolean multiProfile)
Save the given user profile (replace the current one if multi profiles are not supported, add it otherwise).protected void
saveAll(java.util.LinkedHashMap<java.lang.String,UserProfile> profiles, boolean saveInSession)
void
setConfig(Config config)
-
-
-
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, SessionStore sessionStore)
-
-
Method Detail
-
getProfile
public java.util.Optional<UserProfile> getProfile()
Retrieve the first user profile if it exists, ignoring anyAnonymousProfile
if possible.- Returns:
- the user profile
-
getProfile
public <U extends UserProfile> java.util.Optional<U> getProfile(java.lang.Class<U> clazz)
-
getProfiles
public java.util.List<UserProfile> getProfiles()
Retrieve all user profiles.- Returns:
- the user profiles
-
retrieveAll
protected java.util.LinkedHashMap<java.lang.String,UserProfile> 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(java.util.LinkedHashMap<java.lang.String,UserProfile> profiles, boolean readFromSession)
-
removeProfiles
public void removeProfiles()
Remove the current user profile(s).
-
save
public void save(boolean saveInSession, UserProfile 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
-
retrieveClientName
protected java.lang.String retrieveClientName(UserProfile profile)
-
saveAll
protected void saveAll(java.util.LinkedHashMap<java.lang.String,UserProfile> profiles, boolean saveInSession)
-
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)
-
-