Authors
Overview
This Gadget uses GWT and access the Organization service to display some information about a user.
Description
Portlets by default allow for a wide range of access to useful information about the user and the portal environment its running in. With GateIn, a portlet also has easy access to a Portlet or Portal RequestContext to access GateIn specific services.
A gadget on the other hand has a bit more difficultly accessing this information. It doesn't have the same access to kind of information that a portlet usually does, and it doesn't have access to the Portlet or Portal RequestContext.
Since a gadget is normally run as javascript inside the browser of a client, we need to have a server side component to access the portal environment information. A GWT gadget using an RPC component will allow for us to easily have this server side component.
For information on how to get started using GWT and Google Gadgets please see http://code.google.com/p/gwt-google-apis/wiki/GadgetsGettingStarted
Attached to this wiki article is a simple gwt gadget example that will show a welcome message with the users first name and the last time they logged into the server. The example has a simple client interface that will access this information from a servlet using RPC.
Getting Portal Information from a Servlet
Its easy enough to get most of the GateIn services from a servlet if its running on the same server. Most of these services are available directly from the eXoKernel or from a factory's getInstance method.
In our example we get an instance of the PortalContainer and then use the PortalContainer to get access to the OrganizationService (internally via the eXoKernel):
PortalContainer portalContainer = PortalContainer.getInstance(); OrganizationService orgService = portalContainer.getComponentInstanceOfType(OrganizationService.class);
Once we have access to the OrganizationService we can get access to a User object which will contain information about a user:
orgService.getUserHandler().findUserByName(remoteUser);
The problem is getting access to the username. This information is coming from a servlet via ajax and is not being run inside the portal environment. In order to get the username we can have the servlet use the same realm as GateIn and enable the SingleSignOn valve so that they will share login details.
In the servlet's web.xml set up the same realm as GateIn:
<login-config> <auth-method>BASIC</auth-method> <realm-name>gatein-domain</realm-name> </login-config>
In the servlet's jboss-web.xml setup the same realm as GateIn:
<jboss-web> <security-domain>java:/jaas/gatein-domain</security-domain> </jboss-web>
Once we have this setup, within our servlet we can use the remote user name from the GWT threadRequest:
this.perThreadRequest.get().getRemoteUser();
Installation procedure
- Build the example: mvn clean install
- Uncomment the single sign on authenticator valve: <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
- for JBoss located in server/default/deploy/jbossweb.sar/server.xml
- for Tomcat located in conf/server.xml
- Deploy the example on the same server that is running the GateIn server
- Add a new gadget with url http://localhost:8080/gwtgadget/gwtgadget/org.gatein.gadget.client.Application.gadget.xml
Build system: Maven
Source location: Attached file
Compatibility list (please add to this list if you have tested a new version of GateIn):
Tester Version of the example Version of GateIn Result Comment
Comments