EMC Developer Network

Create a Login Ticket for another User

October 2005

Software Environment

FeatureTested on
Operating SystemWindows 2000 Server SP4
CompilerSun JDK 1.4.2_08
RuntimeSun JRE 1.4.2_08
DFC5.3 SP1
Content Server5.3

Abstract

This code snippet demonstrates obtaining a login ticket for another user using super user credentials.

Snippet


/*
 * Created on Oct 10, 2005
 *
 * EMC Documentum Developer Program 2005
 */
package com.documentum.devprog.snippets.session;

import com.documentum.fc.common.DfException;
import com.documentum.fc.common.IDfLoginInfo;

import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;

import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;

public class CreateTicketForAnotherUser
{

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        String superUsername = "dmadmin";
        String superUserPassword = "dmadmin";
        String repoName = "devprog";
        String username = "dm_bof_registry";
        
        try
        {
            createTicketForUser(superUsername,superUserPassword,repoName,username);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }

    }
        
    private static void createTicketForUser(String superUser,String superUserPassword,String repoName,String username) throws DfException
    {
        IDfSessionManager sessMgr = createSessionManager();
        addIdentity(sessMgr,superUser,superUserPassword,repoName);
        
        IDfSession superUserSession = null;
        try        
        {
            superUserSession = sessMgr.getSession(repoName);
            String userTicket = superUserSession.getLoginTicketForUser(username);
            System.out.println("User ticket: " + userTicket);
            
            IDfSessionManager userSm = createSessionManager();
            addIdentity(userSm,username,userTicket,repoName);
            IDfSession userSess = null;
            try
            {
                userSess = userSm.getSession(repoName);
                System.out.println("Got user session: " + userSess.getSessionId());
            }
            finally
            {
                if((userSm != null) && (userSess != null))
                {
                    userSm.release(userSess);
                }
            }
        }
        finally
        {
            if((sessMgr != null) && (superUserSession != null))
            {
                sessMgr.release(superUserSession);
            }
        }
    }

    
    /**
     * Creates a new session manager instance. The session manager does not have
     * any identities associated with it.
     * 
     * @return a new session manager object.
     * @throws DfException
     */
    private static IDfSessionManager createSessionManager() throws DfException
    {
        IDfClientX clientX = new DfClientX();
        IDfClient localClient = clientX.getLocalClient();
        IDfSessionManager sessMgr = localClient.newSessionManager();
        return sessMgr;
    }

    /**
     * Adds a new identity to the session manager.
     * 
     */
    private static void addIdentity(IDfSessionManager sm, String username,
            String password, String repoName) throws DfException
    {
        IDfClientX clientX = new DfClientX();

        IDfLoginInfo li = clientX.getLoginInfo();
        li.setUser(username);
        li.setPassword(password);

        // check if session manager already has an identity.
        // if yes, remove it.
        if (sm.hasIdentity(repoName))
        {
            sm.clearIdentity(repoName);
        }

        sm.setIdentity(repoName, li);
    }

}

Using the code

The above code snippet comes with a main method and is thus a standalone program. To use it, copy-paste the entire code into a new Java class created in your IDE. Adjust the package and class name of the pasted code according to your preference. Change the username,password, repository name and any other necessary variables. Compile and run the code. For details on setting up your IDE for DFC development, refer to the article Setting up a DFC Development Environment

Note:The above code demonstrates a specific piece of functionality and is not meant to be a complete solution