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.
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
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.