Session session = getRequest().getResourceResolver().adaptTo(Session.class);
UserManager userManager = getResource().adaptTo(UserManager.class);
Authorizable auth = userManager.getAuthorizable(session.getUserID());
userId = auth.getID();
So I have the code above to get the currently logged in username in my local AEM instance.
In my testing, session.getUserID() = auth.getID(). I feel that using session.getUserID() should be sufficient in trying to get the username of the currently logged in user.
In our stage and production environments, we have SSO setup and we're using Okta as our provider.
Is there anything I need to change in my code to make it better? Thanks