-
Notifications
You must be signed in to change notification settings - Fork 9
Get the authenticated user profiles
CAS in the cloud LELEU Jérôme edited this page Mar 24, 2022
·
3 revisions
Like for any Undertow web application, you can get the authenticated user via the exchange.getSecurityContext().getAuthenticatedAccount()
.
If the user is authenticated, the appropriate account will be stored in the context as a Pac4jAccount
,
on which you can get the main profile (getProfile
method) or all profiles (getProfiles
method) of the authenticated user:
SecurityContext securityContext = exchange.getSecurityContext();
if (securityContext != null) {
Account account = securityContext.getAuthenticatedAccount();
if (account instanceof Pac4jAccount) {
List<UserProfile> = ((Pac4jAccount) account).getProfiles();
}
}
Alternatively, you can get the profile of the authenticated user using the UndertowProfileManager
.
>> Read the documentation of the ProfileManager
component.
UndertowWebContext context = new UndertowWebContext(exchange);
UndertowSessionStore sessionStore = new UndertowSessionStore(exchange);
ProfileManager manager = new UndertowProfileManager(context, sessionStore);
Optional<UserProfile> profile = manager.getProfile();