BEA/Oracle: July 2008 Archives

I've seen a couple questions lately about ways to connect to the ALUI API Service. There are two ways to use the EDK to connect to the API server. Which way you connect depends on the intend of the specific application.

One way to connect is with a specific username and password. That works well if you need the API server to access information or do actions not necessarily available to the browsing user. Let's take the example where you want to report the number of portlets in the system.

If you want all users to see the total number of portlets including portlets they do not have access too, then you would specify a privileged user for the API connection so that it could query everything. This would be hardcoded or set in admin preferences.

If you want users to see only the number of portlets to which they have access, then you would make the API connection using the credential of the current user. This uses something called the login token, and it is obtained programmatically.

I'll give example code for both, but let me first say that in either case, a variable should be set in the web.config file. The API call will want to know where the PTHOME directory is, and that's is best set in web.config rather than hardcoded. So with either solution, this should be in web.config:

  <appSettings>
    <add key="pthome" value="i:\\apps\\plumtree"/>
  </appSettings>

Then either case, you'll grab that variable from your code.

So if you want to connect using a specific user (usually one with elevated permissions), then you would do it like this:

  // create a session to portal and connect
  string sAdminName = ConfigurationSettings.AppSettings["admin-name"];
  string sAdminPass = ConfigurationSettings.AppSettings["admin-pass"];
  string sPTHome = ConfigurationSettings.AppSettings["pthome"] + "";
  com.plumtree.openkernel.config.IOKContext context = com.plumtree.openkernel.factory.OKConfigFactory.createInstance( sPTHome + "\\settings", "portal");
  PortalObjectsFactory.Init(context);
  IPTSession session = PortalObjectsFactory.CreateSession();
  try
  {
           session.Connect(sAdminName,sAdminPass,null);
  }

The admin-name and admin-pass for a production application should be set with an administrative preference and retrieved through the EDK so that they are not visible in the source file.

And if you want to connect with the individual user's context, then do this:

  // connect a session
  string sPTHome = ConfigurationSettings.AppSettings["pthome"] + "";
  com.plumtree.openkernel.config.IOKContext context = com.plumtree.openkernel.factory.OKConfigFactory.createInstance( sPTHome + "\\settings", "portal");
  PortalObjectsFactory.Init(context);
  session = PortalObjectsFactory.CreateSession();
  // we'll use the context of the logged in user
  try
  {
            session.Reconnect(edk.GetRequest().GetLoginToken());
  }

I have a sample portlet application attached that uses the user's individual context to connect to the API service and gather some information. Its zip file is here. It has a folder called install-resources with some install instructions.

I hope that helps,

Bill

About this Archive

This page is a archive of entries in the BEA/Oracle category from July 2008.

BEA/Oracle: June 2008 is the previous archive.

BEA/Oracle: August 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.