5.6. Access User Profile

The following code retrieves the details for a logged-in user:

// Alternative context: WebuiRequestContext context = WebuiRequestContext.getCurrentInstance() ;

PortalRequestContext context = PortalRequestContext.getCurrentInstance() ;
// Get the id of the user logged
String userId = context.getRemoteUser();
// Request the information from OrganizationService:
OrganizationService orgService = getApplicationComponent(OrganizationService.class) ;
if (userId != null)
  {
  User user = orgService.getUserHandler().findUserByName(userId) ;
  if (user != null)
  {
    String firstName = user.getFirstName();
    String lastName = user.getLastName();
    String email = user.getEmail();
  }
}

Below are two alternatives for retrieving the Organization Service:

  1. OrganizationService service = (OrganizationService)
    
       ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(OrganizationService.class);
  2. OrganizationService service = (OrganizationService)
    
       PortalContainer.getInstance().getComponentInstanceOfType(OrganizationService.class);
Copyright ©2012. All rights reserved. eXo Platform SAS