I am trying to dynamically determine, in an organization-agnostic fashion, whether Apex is executing in an authenticated environment --- whether Customer Portal, Partner Portal, Salesforce Communities, or regular logins. Basically, anything except for an unauthenticated Force.com Site login.
My understanding is that if the Apex running user does NOT have the Site Guest User license, then you are in an authenticated environment. Therefore, querying the
User object for the related Profile's UserLicense record should provide this capability:
boolean isAuthenticated = [ select Profile.UserLicense.LicenseDefinitionKey from User where Id = :UserInfo.getUserId() limit 1 ].Profile.UserLicense.LicenseDefinitionKey != 'GUEST';
Ideally, I would like to avoid having to use a SOQL query just to get this information. Is there any other way to get this, without having to use a SOQL query? Ideally there'd be some Apex system class or programmatic check that I could run that would guarantee that I'm in an authenticated environment or not.