This discussion is archived
2 Replies Latest reply: Dec 10, 2012 6:04 AM by AshishEasow RSS

Working with User and Role API

811051 Newbie
Currently Being Moderated
Hi
I am having usecase to access information of my users. eg. getting email etc.
I am using SQLAuthenticator and able to access users using dbprovider.jar which is sample application, My USER table has columns U_NAME, U_PASSWORD, U_DESCRIPTION AND EMPLOYEE_ID, where EMPLOYEE_ID pointing to my EMPLOYEE table which holds further information of USER like EMAIL, CONTACT_INFO etc.

*1. How can I access other fields present in database, for example how can I access U_DESCRIPTION ?*
*2. I am stuck how to access EMPLOYEE table's fields (email, contact_no, etc) using User and Role API or any other way ? so that It can be called in SOA/BPM related functions like ids:getUserProperty(ora:getCreator(),'mail')?*

My code is as following to have idea what I have achieved so far.

IdentityStoreFactoryBuilder builder = new IdentityStoreFactoryBuilder();
IdentityStoreFactory factory = null;
IdentityStore store = null;
try {
Hashtable factEnv = new Hashtable();
Hashtable storeEnv = new Hashtable();

factEnv.put(DBIdentityStoreFactory.ST_DATASOURCE_NAME,
"SQLAuthenticatorDS");

factory =
builder.getIdentityStoreFactory("org.sample.providers.db.DBIdentityStoreFactory",
factEnv);
System.out.println("Factory: " + factory);

store = factory.getIdentityStoreInstance(storeEnv);
System.out.println("Store: " + store);

SimpleSearchFilter sf =
store.getSimpleSearchFilter(UserProfile.USER_NAME,
SimpleSearchFilter.TYPE_EQUAL, null);
sf.setValue("j" + sf.getWildCardChar());

SearchParameters params = new SearchParameters();
params.setFilter(sf);

Class cls = Class.forName("oracle.security.idm.UserProfile");
Field[] flds = cls.getFields();
int len = flds.length;

// Searching for users
SearchResponse resp = store.searchUsers(params);
UserManager umanager = store.getUserManager();
System.out.println("Searched users are:");
while (resp.hasNext()) {
System.out.println("========================================");
Identity idy = resp.next();
UserProfile userProfile = (UserProfile)idy;
System.out.println("Unique name: " + idy.getUniqueName());
System.out.println("GUID: " + idy.getGUID());

for (int i = 0; i < len; i++) {
String fname = flds.getName();
System.out.println(fname + ": " + userProfile.getPropertyVal(fname)); //it is returning only user name for all sout print
}
System.out.println("========================================");
System.out.println("");
}

Will appreciate for quick reply, thanks in advance.
Regards

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points