-
Notifications
You must be signed in to change notification settings - Fork 27
Get the authenticated user profiles
You can get the profile of the authenticated user using profileManager.get(true)
(false
not to use the session, but only the current HTTP request).
You can test if the user is authenticated using profileManager.isAuthenticated()
.
You can get all the profiles of the authenticated user (if ever multiple ones are kept) using profileManager.getAll(true)
.
Example:
WebContext context = new J2EContext(request, response);
ProfileManager manager = new ProfileManager(context);
Optional<CommonProfile> profile = manager.get(true);
The retrieved profile is at least a CommonProfile
, from which you can retrieve the most common attributes that all profiles share. But you can also cast the user profile to the appropriate profile according to the provider used for authentication. For example, after a Facebook authentication:
FacebookProfile facebookProfile = (FacebookProfile) commonProfile;
First, you must register the components:
@ComponentScan(basePackages = "org.pac4j.springframework.component")
or
@Import(ComponentConfig.class)
Then, you can inject the ProfileManager
(and for other needs the J2EContext
):
@Autowired
private ProfileManager profileManager;
and retrieve the user profile(s) using this component:
Optional<CommonProfile> getProfile()
-
List<CommonProfile> getProfiles()
.