[opencms-dev] OpenCMS authentication

Bill Edwards wse at jimmy.harvard.edu
Thu Jul 6 23:13:44 CEST 2006


I never saw an answer to the attached message that I sent on June 8.   
I am still getting a similar exception stack backtrace to the  
attached.  I found email from Alexander Kandzior from July 2004 that  
implied that one needed to obtain an "application context" for  
OpenCMS.  I am not sure how either to obtain this context (do I use  
ServletContext.getServletContext()) or how to plug it into the  
OpenCMS runtime.

Again, I am trying to set up an automatic login between my portal Web  
app and OpenCMS, and I seem to be having difficulty accessing the  
OpenCMS Web app from my Web app.  Any hints (including code  
fragments) would be welcome.  I will definitely post the solution.   
Thanks. -- Bill Edwards
-----OLD  
MESSAGE----------------------------------------------------------------- 
-----

When I try to run the attached code, I get the following:

java.lang.NullPointerException
    at org.opencms.main.OpenCmsCore.initCmsObject(OpenCmsCore.java:1835)
    at org.opencms.main.OpenCmsCore.initCmsObject(OpenCmsCore.java:755)
    at org.opencms.main.OpenCmsCore.initCmsObject(OpenCmsCore.java:780)
    at org.opencms.main.OpenCms.initCmsObject(OpenCms.java:541)
    at org.frontier.ecog.opencms.auth.OpenCmsAuth.<init> 
(OpenCmsAuth.java:40)
    at org.frontier.ecog.opencms.auth.OpenCmsAuth.main 
(OpenCmsAuth.java:60)

Any pointers would be welcome.  I would like to authenticate to  
OpenCMS from another (Web) application to save double authentication  
on our system.   Thanks. -- Bill Edwards
------------------------------------------------------------------------ 
----------------------------------------------
package org.frontier.ecog.opencms.auth;

import org.opencms.file.CmsObject;
import org.opencms.main.OpenCms;
import org.opencms.main.CmsException;
import org.opencms.db.CmsDefaultUsers;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class OpenCmsAuth
{
  private static final String GUEST = "Guest";
  private static final String USERNAME = "Admin";
  private static final String PASSWORD = "admin";

  private CmsObject theCmsObject;

  public OpenCmsAuth(String userName, String password)
  {
    super();
    try
    {
      System.out.println("Creating CmsDefaultUsers");
      CmsDefaultUsers theDefaultUsers = new CmsDefaultUsers();

      System.out.println("Getting guest username");
      String theGuestUser = theDefaultUsers.getUserGuest();
          System.out.println("Getting CmsObject");
      theCmsObject = OpenCms.initCmsObject(theGuestUser);

      System.out.println("Logging in user " + userName);
      String theLoggedInUser = theCmsObject.loginUser(userName,  
password);

      if (theLoggedInUser.equals(userName))
        System.out.println("User " + userName + " logged in");
      else
        System.out.println("Login failed for user " + userName);

    }
    catch (CmsException ce)
    {
      System.err.println("Caught CmsException: " + ce.getMessage());
    }

  }

  public static void main(String[] args)
  {
    OpenCmsAuth opencmsauth = new OpenCmsAuth(args[0], args[1]);
  }
}



More information about the opencms-dev mailing list