0
votes

For a project I would like to use the UserBean set up by Oliver Busse:

http://oliverbusse.notesx.net/Privat/osnippets.nsf/%24%24OpenDominoDocument.xsp?documentId=90035C4B1B5984C0C1257B5000625C25&action=openDocument

I have altered it a bit so I can also use it for other databases, not just the current database.

Most of the my bean is from the original code although I made some additions to capture the user acl priviliges too:

int accPriv = thisDb.queryAccessPrivileges(session.getEffectiveUserName());

if ((accPriv & thisDb.DBACL_CREATE_DOCS) > 0) {
    if (!aclPriviliges.contains("DBACL_CREATE_DOCS")) {
        aclPriviliges.add("DBACL_CREATE_DOCS");
    }
}
if ((accPriv & thisDb.DBACL_DELETE_DOCS) > 0) {
    if (!aclPriviliges.contains("DBACL_DELETE_DOCS")) {
        aclPriviliges.add("DBACL_DELETE_DOCS");
    }
}
if ((accPriv & thisDb.DBACL_CREATE_PRIV_AGENTS) > 0) {
    if (!aclPriviliges.contains("DBACL_CREATE_PRIV_AGENTS")) {
        aclPriviliges.add("DBACL_CREATE_PRIV_AGENTS");
    }
} //etc...

faces-config:

 <managed-bean>
    <managed-bean-name>UserBean</managed-bean-name>
    <managed-bean-class>org.quintessens.comments.utils.UserBean
        </managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
  </managed-bean>

Here is how I initiate the bean:

<xp:this.beforePageLoad><![CDATA[#{javascript:var db:NotesDatabase = session.getDatabase("","apps/quintessens/comments.nsf");
UserBean.init(db);}]]></xp:this.beforePageLoad>

I notice I can only use the bean with session and request scope. View scope gives a 500 error.

The UserBean class itself is mostly as the original:

Some modifications:

public Database db;

    public UserBean() {
        this.init( db);
    } 

and

public void init(Database db) {
        session = getCurrentSession();
        try {
            Database thisDb = db;
...
int accPriv = thisDb.queryAccessPrivileges(session.getEffectiveUserName());
...
}

Although I do not get an error with the session and request scope, the ACL user priviliges are incorrect.

If I run the class not as Managed Bean as followed:

var thisDb:NotesDatabase = session.getDatabase("","apps/quintessens/comments2.nsf");
Bean = new org.quintessens.comments.utils.UserBean(thisDb);
return Bean.aclPriviliges;

I get the correct user information returned.

Can someone shine a light how I can run the class with parameters once again as a managed bean?

2
One more thought: your snippet of code adds privileges to the list, but id does not care about removing them. That's possible reason you get wrong ACL when your code runs over two different dbs or users.Frantisek Kossuth
You can access the domino object through the faces context see for example this naveegator.blogspot.ch/2011/12/…umeli
Always start looking at the stack trace when you get an error 500. It will give you much more info about the issue. If you don't already use the LogReader database (find it on OpenNTF.org) then you should use that to make it easier to read those log files.John Dalsgaard

2 Answers

1
votes

my guess for the reason you are getting error 500 on viewscope could be because of using a NotesObject as a field in your bean.

public Database db;

Theses objects are not serializable and will throw a NotSerializable exception in View Scope (if you are using on disk persistence).

Application, Session and Request scope are not serialized so you probably won't see that error under those scopes.

Instead of storing the db on the bean, you could store either the filepath or replica Id. Mark you DB field 'transient', this tells the serialization process to ignore that field. then create a lazy loading getDb() method which will re-initialize the db field if it is null (because it will be null after it is de-serialized)

0
votes

Think again about your bean. The main problem (IMO) is the same bean for different databases - any code can reinitialize the bean again and your page, especially with session scope, may/will get wrong results.

For your scenario I highly recommend to implement Map or DataObject in your bean. You can bind with EL and get proper ACL for different databases. Instead of init(db) method you can implement get(key)/getValue(key) method, that will return POJO with ACL properties.

Sample binding: ${Bean['apps/quintessens/comments2.nsf'].aclPrivileges}.

More info here.

P.S: Never ever use Domino object (Database in your case) as bean attribute (the only exception - request scoped bean).