Getting EMail Adress from local user

I have configured an email adress for the users in the *.yaml files for the local users which I want to retrieve from the currently logged in user in dataservices.

username: admin
password: admin
authorities:
  - guest
  - admin
  - systemAdmin
firstname: Ad
lastname: min
email: admin@example.com

In order to get the current user, i found the 2 ways:

com.mgmtp.a12.uaa.authorization.UserUtil.resolveCurrentUser();
        final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        ExtendedUser user =  (ExtendedUser) authentication.getPrincipal();

Both of which return the configured local user but without firstname, lastname nor email address (everything is null)
Also when logging in via /user/local/login, the user returned does not contain this information:

{
	"username": "admin",
	"eMail": null,
	"firstName": null,
	"lastName": null,
	"displayName": "admin",
	"accountNonExpired": true,
	"accountNonLocked": true,
	"credentialsNonExpired": true,
	"enabled": true,
	"roles": [

Is it possible, to read out the email adress (Which according to the documentation is not an additional property) of the user in the code & if so, how?

Thanks!

Sebastian

Hi Sebastian,
Normally users are stored on IDP or LDAP server but in case of LOCAL auth type your server is responsible for storing users. For this you can use preconfigured YAML users. The YAML user is just an internal user representation. After login you credentials are validated against the YAML user and when everything is fine the principal object is created. The principal is then stored in SecurityContext. In your case it’s ExtendedUser. Those 2 objects are detached and internal must be converted to principal. We have a process for that which is quite extensible and you can tweak it with many extension points. In your case the situation is simple. You have the same property in YAML iser and also in principal ExtendedUser. Then you can just add following config yo your properties:

mgmtp.a12.uaa.authentication.user.additional-properties=email

And magic happen :slight_smile: