[opencms-dev] OpenCMS authentication

Bill Edwards wse at jimmy.harvard.edu
Fri Jun 9 00:22:09 CEST 2006


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