Authentication 通过com.Filenet.api.util.UserContext进行Filenet身份验证

Authentication 通过com.Filenet.api.util.UserContext进行Filenet身份验证,authentication,jaas,filenet,filenet-content-engine,Authentication,Jaas,Filenet,Filenet Content Engine,我得到了演示示例CeConnection.javaclass,可从IBM站点()获得 您可以在消息顶部找到此类的列表 因此,我的webapp使用单用户与内容引擎通信(是的,单“ce_user”和“passw123”)。 请您解释一下在我的Vaadin webapp中为每个用户的会话使用这个CeConnection类的好做法和好方法(Vaadin的入口点-AppMain.java类可以有CeConnection字段) 以下哪种方法可以 1. When the webapp starts I est

我得到了演示示例
CeConnection.java
class,可从IBM站点()获得 您可以在消息顶部找到此类的列表

因此,我的webapp使用单用户与内容引擎通信(是的,单“ce_user”和“passw123”)。 请您解释一下在我的Vaadin webapp中为每个用户的会话使用这个
CeConnection
类的好做法和好方法(Vaadin的入口点-AppMain.java类可以有
CeConnection
字段)

以下哪种方法可以

1. When the webapp starts I establish connection: 
  void init() {  // this is vaadins entry point

  ceConnection  = new CeConnection();

  ceConnection.establishConnection(...);

  }



OR

2. Create new CeConnection for every request to Content Engine. like:

    Document getDoc(String id) {
         CeConnection ceConnection = new CeConnection(...) 
         try {
         ceConnection.establish(); // (contains UserContext.pushSubject)

         ...get data from CE....
         } finally {
         ceConenction.logofMethod();  (contains UserContext.popSubject)
         }
        }
谢谢大家!

/**
    IBM grants you a nonexclusive copyright license to use all programming code 
    examples from which you can generate similar function tailored to your own 
    specific needs.

    All sample code is provided by IBM for illustrative purposes only.
    These examples have not been thoroughly tested under all conditions.  IBM, 
    therefore cannot guarantee or imply reliability, serviceability, or function of 
    these programs.

    All Programs or code component contained herein are provided to you �AS IS � 
    without any warranties of any kind.
    The implied warranties of non-infringement, merchantability and fitness for a 
    particular purpose are expressly disclaimed.

    � Copyright IBM Corporation 2007, ALL RIGHTS RESERVED.
 */

package cesample;

import java.util.Iterator;
import java.util.Vector;
import javax.security.auth.Subject;
import com.filenet.api.collection.ObjectStoreSet;
import com.filenet.api.core.Connection;
import com.filenet.api.core.Domain;
import com.filenet.api.core.Factory;
import com.filenet.api.core.ObjectStore;
import com.filenet.api.util.UserContext;

/**
 * This object represents the connection with
 * the Content Engine. Once connection is established
 * it intializes Domain and ObjectStoreSet with
 * available Domain and ObjectStoreSet.
 * 
 */
public class CEConnection 
{
    private Connection con;
    private Domain dom;
    private String domainName;
    private ObjectStoreSet ost;
    private Vector osnames;
    private boolean isConnected;
    private UserContext uc;

    /*
     * constructor
     */
    public CEConnection()
    {
        con = null;
        uc = UserContext.get();
        dom = null;
        domainName = null;
        ost = null;
        osnames = new Vector();
        isConnected = false;
    }

    /*
     * Establishes connection with Content Engine using
     * supplied username, password, JAAS stanza and CE Uri.
     */
    public void establishConnection(String userName, String password, String stanza, String uri)
    {
        con = Factory.Connection.getConnection(uri);
        Subject sub = UserContext.createSubject(con,userName,password,stanza);
        uc.pushSubject(sub);
        dom = fetchDomain();
        domainName = dom.get_Name();
        ost = getOSSet();
        isConnected = true;
    }

    /*
     * Returns Domain object.
     */
    public Domain fetchDomain()
    {
        dom = Factory.Domain.fetchInstance(con, null, null);
        return dom;
    }

    /*
     * Returns ObjectStoreSet from Domain
     */
    public ObjectStoreSet getOSSet()
    {
        ost = dom.get_ObjectStores();
        return ost;
    }

    /*
     * Returns vector containing ObjectStore
     * names from object stores available in
     * ObjectStoreSet.
     */
    public Vector getOSNames()
    {
        if(osnames.isEmpty())
        {
            Iterator it = ost.iterator();
            while(it.hasNext())
            {
                ObjectStore os = (ObjectStore) it.next();
                osnames.add(os.get_DisplayName());
            }
        }
        return osnames;
    }

    /*
     * Checks whether connection has established
     * with the Content Engine or not.
     */
    public boolean isConnected() 
    {
        return isConnected;
    }

    /*
     * Returns ObjectStore object for supplied
     * object store name.
     */
    public ObjectStore fetchOS(String name)
    {
        ObjectStore os = Factory.ObjectStore.fetchInstance(dom, name, null);
        return os;
    }

    /*
     * Returns the domain name.
     */
    public String getDomainName()
    {
        return domainName;
    }
}
编辑:添加

我想知道,若两个客户端几乎同时调用servlet方法,而一个客户端首先调用PopSubject,会发生什么情况? com.filenet.api.util.UserContext类是线程安全的吗

servlet方法:

public String getDocumentNumber(String id) {

 UserContext.get().pushSubject(mySubject);
 try {
   ....
   ....
   ....
   ....
 } finally {
   UserContext.get().popSubject();
 }

}
//com.filenet.api.util.UserContext类

public static UserContext get() {
        UserContext cntx = (UserContext)tl.get();
        if(cntx == null) {
            cntx = new UserContext();
            tl.set(cntx);
        }

        return cntx;
    }


public synchronized void pushSubject(Subject sub) {

        if(sub == null) {
            throw new EngineRuntimeException(ExceptionCode.E_NULL_OR_INVALID_PARAM_VALUE, "Subject");
        } else {
            this.subjects.add(sub);
        }
}


public synchronized Subject popSubject() {

        return this.subjects.isEmpty()?null:(Subject)this.subjects.remove(this.subjects.size() - 1);
}

我建议在需要时连接到CE,而不是在应用程序加载期间。在应用程序启动时进行连接并没有什么坏处,因为CE objectstore只是一个POJO,但我更喜欢在需要时进行连接

同样从您的代码中,我可以看到您使用了
cecononnection.logofMethod()警告一句,当您完成所有CE操作时,您需要调用此方法,否则将出现错误。让我们举个例子

  • 用户登录
  • 用户希望添加一个文档以便建立连接
  • 您的代码将添加文档
  • 然后执行finally块并执行
    ceconnection.logofMethod()
  • 紧接着,如果您希望用户执行任何CE操作,如删除或更新,您将得到一个异常。因此,您需要再次获取objectstore

  • 希望这有帮助。

    谢谢你的回答。我已经编辑了我的问题,你能复习一下吗。“我想知道,如果两个客户端几乎同时调用servlet方法,而一个客户端首先调用PopSubject,会发生什么情况?com.filenet.api.util.UserContext类是线程安全的吗?”这个链接应该可以消除您的疑问