<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "../../Reference_Guide.ent">
%BOOK_ENTITIES;
]>
<section id="sect-Reference_Guide-Accessing_User_Profile">
	<title>Access User Profile</title>
	<para>
		The following code retrieves the details for a logged-in user:
	</para>
	
<programlisting language="java">// 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();
  }
}
</programlisting>
	<para>
		Below are two alternatives for retrieving the Organization Service:
	</para>
	<orderedlist>
		<listitem>
			
<programlisting language="java">OrganizationService service = (OrganizationService)
   ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(OrganizationService.class);
</programlisting>
		</listitem>
		<listitem>
			
<programlisting language="java">OrganizationService service = (OrganizationService)
   PortalContainer.getInstance().getComponentInstanceOfType(OrganizationService.class);
</programlisting>
		</listitem>
	</orderedlist>
</section>


