EMC Developer Network

Enabling Principal Authentication Mode from .NET

December 2005
Contributed by - Brendan McLoughlin from ISGN Solutions Ltd.

Software Environment

FeatureTested on
Operating SystemWindows 2000 Server SP4
CompilerMicrosoft (R) Visual C# .NET Compiler version 7.10.6001.4
RuntimeMicrosoft (R) .NET Framework version 1.1.4322
DFC5.3 SP1
Documentum Primary Interop Assembly(PIA)5.3.0.53

Abstract

This article discusses the process of enabling and using the Principal Authentication mode from .NET. It was contributed by Brendan McLoughlin from ISGN Solutions Ltd. The code is part of their Enterprise Risk Management solution, Risk Management Compass which has been developed for all types of regulatory compliance.

Description

If you are new to the Principal Authentication mode we recommend that you read the article 'Principal Authentication Mode' before reading this code sample.

The proces for enabling the principal authentication mode from .NET is two step -

  • Write a Service-based Business Object (SBO) that calls the Java specific classes.
  • Write code in .NET to invoke this SBO to enable the principal authentication mode

SBO

The code for SBO is as follows -

package com.documentum.rmc;

import com.documentum.fc.client.DfService;
import com.documentum.fc.common.DfLogger;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfLoginInfo;
import com.documentum.fc.common.IDfLoginInfo;

import com.documentum.fc.client.*;
import com.documentum.com.IDfClientX;

public class PrincipalModeLauncherService extends DfService
{
	// Enable principal mode
    public IDfClient enablePrincipalMode(IDfClient client, IDfLoginInfo loginInfo)
    {
        try
        {
        	DfSimpleTrustManager objSimpleTrustManager = new DfSimpleTrustManager(loginInfo);
        	DfDefaultPrincipalSupport objDefaultPrincipalSupport = 
			     new DfDefaultPrincipalSupport(client,objSimpleTrustManager);
        	
			client.setPrincipalSupport(objDefaultPrincipalSupport);

        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return client;
    }
    
	// Return SBO version
    public String getVersion()
    {
        return "1.0";
    }

	// Return the vendor
    public String getVendorString()
    {
        return "ISG Solutions";
    }

	// Insure version compatibility
    public boolean isCompatible(String version)
    {
        return true;
    }
    
}

Invoking the SBO from .NET

Here is the code for invoking the above SBO from .NET

using System;
using System.Reflection;
using System.Web;
using GTEL.Common.Configuration;
using GTEL.Common.Utils; 
using GTEL.Common.DocumentManagement; 
using GTEL.Common.DocumentManagement.Exceptions;
using System.Text;
using Documentum.Interop.DFC;
using System.Runtime.InteropServices;


namespace GTEL.Common.DocumentManagement.Emc
{
	
	public class EmcDocumentManager:DocumentFactory
	{

		#region constructors
		
		public EmcDocumentManager()
		{
		}
		#endregion

		#region  overrides

		
		public override object Authenticate(string userName, 
					string password, string proxyUser) 
		{
			IDfClientX objClientx =null;
			IDfClient objClient =null;
			IDfLoginInfo objLoginInfo = null;

			try
			{
				// Obtain an IDfClient interface from the DFC
				objClientx = new DfClientXClass();
				objClient = objClientx.getLocalClient();
				
				// Set up the login info object for the super user			
				objLoginInfo = objClientx.getLoginInfo();	
				objLoginInfo.setUser(userName);
				objLoginInfo.setPassword(password);
			
				IDfSessionManager sMgr = objClient.newSessionManager();

				// Set up the SBO reference - SBO should be part of the CLASSPATH
				string strServiceName = "com.documentum.rmc.PrincipalModeLauncherService";

				// Use reflection to get a COM reference  to the SBO
				Type lcType = objClient.GetType();
			
				object[] objParams = {strServiceName, sMgr};
				object servObj = lcType.InvokeMember("newService",
					BindingFlags.InvokeMethod,
					null,
					objClient,
					objParams);

				// User reflection to execute the SBO method to enable principal mode
				Type serviceObjectType = servObj.GetType();
			
				object[] servMethodParams = {objClient, objLoginInfo};
				
				objClient = (IDfClient)serviceObjectType.InvokeMember("enablePrincipalMode",
					BindingFlags.InvokeMethod,
					null,servObj,servMethodParams);
		
				// Set the proxy
				sMgr.setPrincipalName(proxyUser);
	
			return sMgr;

			}
			catch(Exception ex)
			{
				// Emit the exception to the ASP.Net trace (if an ASP.net implementation)
				EmitExceptionToTrace("EmcDocumentManager:Authenticate", ex);
				throw;
			}
			finally
			{
				if (objClientx!=null){do {}while(Marshal.ReleaseComObject(objClientx)>0);}
				if (objClient!=null){do {}while(Marshal.ReleaseComObject(objClient)>0);}
				if (objLoginInfo!=null){do {}while(Marshal.ReleaseComObject(objLoginInfo)>0);}
			}
		}

	#endregion

}
}