Express (Distributed operating systems), v8.0 > Secure applications and their environment > Authenticate users > Select a registry or repository > Manage realms in a federated repository > Virtual member manager > Develop with virtual member manager > Integrate virtual member manager into the application > Program tasks


Log in

Use the login(DataObject) method and LoginControl to authenticate a user.


About this task

Use the LoginAccount data object or explicit sub-type to authenticate a user. Use the optional LoginControl to retrieve the properties of the entity being authenticated.

If the user does not belong to the default realm, then the realm name needs to be set in the context using the realm key. When logging in through the WebSphere Administrative Console, username@realmName needs to be used.

This example shows how to authenticate using a PersonAccount object with a principalName and password.

To authenticate a using a PersonAccount object with a principalName and password, add this sample code to the application code and replace the variables with the actual values to use for this request:

try {
    DataObject root = SDOHelper.createRootDataObject();
    DataObject paccount = SDOHelper.createEntityDataObject(root, null, DO_PERSON_ACCOUNT);
    paccount.set(PROP_PRINCIPAL_NAME, "bob");
    paccount.set(Service.PROP_PASSWORD,
                 com.ibm.websphere.wim.util.PasswordUtil.getByteArrayPassword("mypassword"));
    DataObject loginCtrl = SDOHelper.createControlDataObject(root, null, DO_LOGIN_CONTROL);
    loginCtrl.getList(PROP_SEARCH_BASES).add("cn=users,dc=yourco,dc=com");
    loginCtrl.getList(PROP_PROPERTIES).add("uid");
    loginCtrl.getList(PROP_PROPERTIES).add("cn");
    root = service.login(root);
} catch (WIMException e) {
    e.printStackTrace();
}


Sample input and output data graphs

For this particular example the input data graph is:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
               xmlns:sdo="commonj.sdo"
               xmlns:wim="//www.ibm.com/websphere/wim">
<wim:Root>
<wim:entities xsi:type="wim:PersonAccount">
<wim:principalName>bob
</wim:principalName>
<wim:password>KioqKg==
</wim:password>
</wim:entities>
<wim:controls xsi:type="wim:LoginControl">
<wim:searchBases>cn=users,dc=yourco,dc=com
</wim:searchBases>
<wim:properties>cn
</wim:properties>
<wim:properties>uid
</wim:properties>
</wim:controls>
</wim:Root>
</sdo:datagraph> 

The resulting output data graph is:

<?xml version="1.0" encoding="UTF-8"?>
<sdo:datagraph xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
               xmlns:sdo="commonj.sdo"
               xmlns:wim="//www.ibm.com/websphere/wim">
<changeSummary/>
<Root>
<entities xsi:type="PersonAccount">  
<identifier uniqueId="f0cf975b-eca8-4331-8a70-6b90556f4f65"
                    uniqueName="accountName=bob,cn=users,dc=yourco,dc=com">    
<cn>bob W
</cn>    
<uid>bob
</uid>
</entities>
</Root>
</sdo:datagraph> 

Parent topic: Program tasks



+

Search Tips   |   Advanced Search