Show TOC Start of Content Area

Background documentation User Locate the document in its SAP Library structure

The SAP WebAS Java and the SAP Enterprise Portal are provides interfaces to get details about the current user.

User Management Factory

The user management factory give access to the user management functions. The user management factory is in the following package:

com.sap.security.api.UMFactory

 

Interface IUser

The IUser interface provides read access to the available user information.

Examples for user information:

·        Company the user belongs to.

·        Profile information, like full name and address)

·        Authorization information. Which rights does the user have.

The IUserMaint interface extends the IUser interface and provides methods to change the user information. One reason for the separation is the performance. Most applications only need read access. The IUser interface does not have to deal with the overhead necessary to change a user and is therefore faster.

Getting a User Object

The user management factory provides several methods to get the IUser object, for example, get user by user name. For all available methods, please refer to the Javadoc.

Example:

//Get an 'IUserFactory'-object to instantiate user-objects.
    
IUserFactory userFactory= UMFactory.getUserFactory();
    
IUser myUser = userFactory.getUser(request.getUser().getUserId());

 

Accessing the Logon ID of a User

In EP 5.0 it was possible to get the logon ID with the getUid() method of the user factory. This method is deprecated in EP 6.0 due to the fact that a user can be associated with several logon accounts. The method getUniqueId() is a substitution for getUid(), but the returned value has to be parsed to get the logon ID. You can access the logon ID by iterating through the IUserAccounts array that is returned by method getUserAccounts()T, with method getLogonUid().

    String logonID = user.getUid();
    IUserAccount accounts[]= 
null;
    
try {
        accounts= user.getUserAccounts();
    } 
catch (UMException e) {
        response
            .write(
                (
"<br>Error getting accounts: "
                    
+ e.getLocalizedMessage());
    }
    
if (accounts != null) {
        response.write(
            
"<br>Number of Login Accounts: " + accounts.length);
        
for (int i= 0; i < accounts.length; i++) {
            response.write(
                
"<br>** Login ID #"
                    
+ i
                    + 
": LogonUID="
                    
+ accounts[i].getLogonUid()
                    + 
", AssignedUID="
                    
+ accounts[i].getAssignedUserID());
            response.write(
                
"<br>Last Login: "
                    
+ accounts[i]
                        .getLastSuccessfulLogonDate()
                        .toString());
            response.write(
                
"<br># Logins: "
                    
+ accounts[i].getSuccessfulLogonCounts());
        }
    }

 

End of Content Area