Hi
Am working on a HCP extension application. Am using the above packages to retrieve the logged on User Information like Name & Email.
UserProvider users = UserManagementAccessor.getUserProvider();
and
User user = users.getUser(request.getUserPrincipal().getName()); both returns valid response and user is returned as PXXXXX user
But getAttribute("email") or getAttribute("firstname") or getName is returning null.
I have to use java ee6 web profile server as destinations also required in my extension app.
Any hints
******************************************************************************************************************************************************************************
Dependencies in pom.xml
<dependency> | |||
<groupId>com.sap.cloud</groupId> | |||
<artifactId>neo-javaee6-wp-api</artifactId> | |||
<version>2.62.4</version> | |||
<scope>provided</scope> | |||
</dependency |
I have tried these two implementations
web.xml
<resource-ref>
<res-ref-name>user/Provider</res-ref-name>
<res-type>com.sap.security.um.user.UserProvider</res-type>
</resource-ref>
First Implementation
try {
InitialContext usrctx = new InitialContext();
UserProvider userProvider = (UserProvider) usrctx.lookup("java:comp/env/user/Provider");
User user = null;
if (request.getUserPrincipal() != null) {
user = userProvider.getUser(request.getUserPrincipal().getName());
LOG.info("User Name" + user.getName());
LOG.info(("email" + user.getAttribute("email")));
}
}
catch (Exception e) {
// Handle errors
}
Second Implementation
try {
// UserProvider provides access to the user storage
UserProvider users = UserManagementAccessor.getUserProvider();
// Read the currently logged in user from the user storage
User user = users.getUser(request.getUserPrincipal().getName());
// Print the user name and email
LOG.info("User name: " + user.getAttribute("firstname") + " " + user.getAttribute("lastname"));
LOG.info("Email: " + user.getAttribute("email"));
} catch (Exception e) {
// Handle errors
}