How can I get all user names registered in JDBC or LDAP real

Posted by Admin on 29-Feb-2012 01:08

We are creating a limited demonstration project that will provide a feature to dynamically select human performer on portal. We would like to have a combobox populated with user names selected dynamically from JDBCRealm or LDAPRealm.

I attemped to use the following code to extract an array of user names and print the first one:

String realmName = "JDBCRealm";
        com.tdiinc.userManager.Realm realm = UserManager.getRealm(realmName);
        java.lang.String[] userNames = realm.getUserNames();
        System.out.println(userNames[0]);

In this code UserManager.getRealm(realmName) method returns <null>.

Has anyone, by chance, implemented anything similar to what I'm trying to achieve?

Thank you in advance.

-Viatcheslav.

All Replies

Posted by sandips on 29-Feb-2012 01:37

Hi Viatcheslav,

Below code will return all the JDBC and LDAP users.

JDBCRealm jdbcrm=(JDBCRealm) UserManager.getDefaultRealm();

//LDAPRealmjdbcrm=(LDAPRealm) UserManager.getDefaultRealm();

java.lang.String[] userNames = jdbcrm.getUserNames();
System.out.println(userNames[0]);

Thanks,

Sandip

Posted by Admin on 05-Mar-2012 02:34

Sandip,

Thanks a lot for your solution! I checked it and it works as required. Following your idea I created my own that relies on polymorphism of getUserNames() defined in Realm interface to abstract the code from realm type:

import com.tdiinc.userManager.Realm;
import com.tdiinc.userManager.UserManager;

/..../

public void execute() {
        Realm realm = UserManager.getDefaultRealm();
        String[] users = realm.getUserNames();
        this.lstPerformers  = new Vector();
        for (int i = 0; i
            this.lstPerformers.addElement(users[i]);
        }
    }

Another way one may find useful is to create JDBCRealm/LDAPRealm object with default constructors:

JDBCRealm realm = new JDBCRealm();

// LDAPRealm realm = new LDAPRealm();

Thanks again for the correct answer!

-Viatcheslav.

This thread is closed