EMC Developer Network

Authenticating with a Documentum Repository

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 SP1

Abstract

This code snippet demonstrates explicitly authenticating with a Documentum Repository.

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.DfLoginInfo;
import com.documentum.fc.common.IDfLoginInfo;

import com.documentum.fc.client.DfAuthenticationException;
import com.documentum.fc.client.DfClient;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfSessionManager;

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


public class ExplicitAuthentication
{

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        String repoName = "devprog";
        String username = "dmadmin";
        String password = "dmadn";
        
        try
        {
            authenticate(username,password,repoName);
            System.out.println("Authentication successful");
        }
        catch(DfException dfe)
        {
            System.out.println("Authentication failed");
            dfe.printStackTrace();
        }

    }
    
    /**
     * Authenticates a user to the specified repository.  
     * 
     *
     * @throws DfException if authentication fails for some reason.
     */
    private static void authenticate(String username, String password,
            String repoName) throws DfException
    {

        IDfClientX clientX = new DfClientX();

        //create login info
        IDfLoginInfo li = clientX.getLoginInfo();
        li.setUser(username);
        li.setPassword(password);

        //create session manager
        IDfClient localClient = DfClient.getLocalClient();
        IDfSessionManager sessMgr = localClient.newSessionManager();

        //setIdentity does not authenticate or create a session.
        //The first getSession(...) authenticates
        //or you can call authenticate() for explicit authentication
        sessMgr.setIdentity(repoName, li);
        sessMgr.authenticate(repoName);

        //if authenticate() does not throw an exception it means 
        //authentication was successful.                       

    }

}

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