This Space has blogs on various topics in the field of SAP. These blogs point out solutions to various technical and functional issues that consultants face during implementation or support of SAP Projects. Readers/followers are welcome to contribute to this space by emailing your content at bohra.mohammadi@gmail.com. You will be rewarded according to the topic/number of words/complexity of the topic/issue which are you addressing in your blog.
Sunday, June 12
Methods of IUserFactory API and Iuser API
There are various tasks which can be perfomed by using the IUSERFACTORY API of the UME(user management engine).
Instantiate user objects
Create New Users
Delete existing users
search users
and perform mass commit/rollback operations on a set of users
Access to the users factory is possible by using the following lines of code
import com.sap.security.api.*
IUserfactory userfact = Umfactory.getUserfactory();
You can obtain a user object by using the userfactory provided you know the logon ID or the Unique ID of the user.
getUserFactory.getUser(String UniqueID);
getUserFactory.getUserbyLogonID(String LogonID);
If you want to get user and prepopulate specific attributes, use the following method
getUserFactory.getUser(String UniqueID, AttributeList AttrList);
Most of the information needed for processing in a web dynpro java application is present in the IUser Object. Information about the name of the user, their unique ID, LDAP attributes, display name, role membership, etc are available from the IUser object.It is also possible to edit the corresponding profile data with the interface IUserMaint.
Obtaining information about the current User
The user associated with current portal request can be obtained by using getUser() methos in the IPortalComponentRequest Object.
IPortalComponentRequest request = .... ;
IUser user = request.getUser();
String Username = user.getDisplayName();
String depname = user.getDepartment();
Obtaining Information about another User
You can access any user by using the getuserbyLogonID() provided you have the logon ID of the desired user
An Exception would occur if the user does not exist
String uid = "demouser";
try
{
Iuser user = UmFactory.getuserFactory().getUserbyLogonID(uid);
String username = user.getDisplayName();
}
cartch(UME Exception e)
{
wdComponentAPI.getMessagemanager.reportexception(e.getlocalizedmessage, false);
}
The above lines of code also are applicable if you know the unique ID of the user whose information is required. Instead of method getUserbyLogonID(), use getUserbyUniqueID().
Searching for Users
steps are :
create a search filter from the userfactory.
set the search attributes for the search.
invoke the search
iterate thourgh the results
The result of the search is of type ISearchResult and returns an iterator containing the UniqueIDs of the principals returned.
The SearchReult also contain the state of the search.
Search_Result_Incomplete
Search_Result_OK
Search_Result_UNDEFINED
Search_Result_EXCEEDED
TIME_LIMIT_EXCEEDED
IUserFActory userfact = UMFactory.getUserFactory();
IUserSearchFilter userfilt = userfact.getUserSearchFilter();
userfilt.setLastName("bohra*");
ISearchResult result = userfact.SearchUsers(userfilt);
if (result.getState() == ISearchResult.SEARCH_RESULT_OK)
{
while(result.hasNext())
{
String uniqID = (string) result.next();
IUser thisuser = userfact.getuser(uniqID);
}
}
else
{
// print error or warning.
}
}
Instantiate user objects
Create New Users
Delete existing users
search users
and perform mass commit/rollback operations on a set of users
Access to the users factory is possible by using the following lines of code
import com.sap.security.api.*
IUserfactory userfact = Umfactory.getUserfactory();
You can obtain a user object by using the userfactory provided you know the logon ID or the Unique ID of the user.
getUserFactory.getUser(String UniqueID);
getUserFactory.getUserbyLogonID(String LogonID);
If you want to get user and prepopulate specific attributes, use the following method
getUserFactory.getUser(String UniqueID, AttributeList AttrList);
Most of the information needed for processing in a web dynpro java application is present in the IUser Object. Information about the name of the user, their unique ID, LDAP attributes, display name, role membership, etc are available from the IUser object.It is also possible to edit the corresponding profile data with the interface IUserMaint.
Obtaining information about the current User
The user associated with current portal request can be obtained by using getUser() methos in the IPortalComponentRequest Object.
IPortalComponentRequest request = .... ;
IUser user = request.getUser();
String Username = user.getDisplayName();
String depname = user.getDepartment();
Obtaining Information about another User
You can access any user by using the getuserbyLogonID() provided you have the logon ID of the desired user
An Exception would occur if the user does not exist
String uid = "demouser";
try
{
Iuser user = UmFactory.getuserFactory().getUserbyLogonID(uid);
String username = user.getDisplayName();
}
cartch(UME Exception e)
{
wdComponentAPI.getMessagemanager.reportexception(e.getlocalizedmessage, false);
}
The above lines of code also are applicable if you know the unique ID of the user whose information is required. Instead of method getUserbyLogonID(), use getUserbyUniqueID().
Searching for Users
steps are :
create a search filter from the userfactory.
set the search attributes for the search.
invoke the search
iterate thourgh the results
The result of the search is of type ISearchResult and returns an iterator containing the UniqueIDs of the principals returned.
The SearchReult also contain the state of the search.
Search_Result_Incomplete
Search_Result_OK
Search_Result_UNDEFINED
Search_Result_EXCEEDED
TIME_LIMIT_EXCEEDED
IUserFActory userfact = UMFactory.getUserFactory();
IUserSearchFilter userfilt = userfact.getUserSearchFilter();
userfilt.setLastName("bohra*");
ISearchResult result = userfact.SearchUsers(userfilt);
if (result.getState() == ISearchResult.SEARCH_RESULT_OK)
{
while(result.hasNext())
{
String uniqID = (string) result.next();
IUser thisuser = userfact.getuser(uniqID);
}
}
else
{
// print error or warning.
}
}
Labels:
Iuserfactory,
sap iusersearchfilter,
sap userfactory,
userfactory,
userfactory api,
userfactory getuser,
userfactory sap
Subscribe to:
Post Comments (Atom)
Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating mulesoft Online Training
ReplyDelete