|
 |
 |
 |
 |
Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms
of Use |
Trademarks
Article ID: 232485 - Last Review: September 11, 2006 - Revision: 5.0 How To Programmatically Create Members in Site Server 3.0 Using JavaThis article was previously published under Q232485
This article describes how to programmatically create members in Site
Server 3.0 Membership Directory, using Active Directory Service Interfaces
(ADSI) 2.0 and 2.5, Java/COM integration, and J/Direct.
When you create a new Member object, the following three properties must
be set:
- objectClass
- cn (Common Name)
- GUID
The first two, objectClass and cn, are set when the Create() method is
called. The third, GUID, must explicitly be set. If these properties are
not set properly, the call to SetInfo() will fail and the new Member
object will not be created.
The following code demonstrates adding a member programmatically:
import activeds.*;
//import autoobj.*;
//Uncomment the above line if you want to use
//early binding for the GuidGen object.
import com.ms.com.*;
import com.ms.win32.*;
public class ADSISamp
{
IADsContainer oADsContainer;
IADs oADsNewUser;
Object oGuidGen;
Variant strGuid;
String strLdapPath;
public static void main (String[] args) throws Exception
{
ADSISamp app = new ADSISamp();
app.run();
System.in.read();
}
public void run()
{
try
{
//The path to the ou=Members container.
strLdapPath = "LDAP://localhost:5292/o=Microsoft/ou=Members";
//Instantiate the GUID Generator that comes with Site Server
//and store the GUID for use later on.
//Using CoCreateInstance here, but could
//also use a wrapper from autoobj.dll
//in the Bin\P&M directory of the Site Server installation.
oGuidGen = createObject("Membership.GuidGen.1");
//oGuidGen = (IGuidGen)new GuidGen();
//strGuid.putString(((IGuidGen)oGuidGen).GenerateGuid());
//Using the IDispatch pointer returned from createObject
//via the Dispatch class to call GenerateGuid.
//Once again, could also use early-binding via the wrapper class.
//Use of IDispatch allows us to use this object with out
//importing the wrapper classes for autoobj.dll.
strGuid = Dispatch.call(oGuidGen, "GenerateGuid");
//Bind to the container in which the Member will be created.
//Note that this is an API call, and is declared native
//with other API J/Direct declarations at the bottom of this
//source file. It does, however, return a COM Interface
//exposed by the activeds.dll and described in activeds.tlb,
//both of which can be found in the %windir%\system32 directory.
oADsContainer = (IADsContainer)ADsGetObject(strLdapPath, IADs.iid);
//Create the new user object. Note that the Create() method
//returns an Interface pointer that maps to the IADs wrapper
//class in Java, which is the core ADSI COM Interface.
oADsNewUser = (IADs)oADsContainer.Create("member", "cn=JohnDoe");
oADsNewUser.Put("givenName", new Variant("John"));
oADsNewUser.Put("sn", new Variant("Doe"));
oADsNewUser.Put("userPassword", new Variant("password"));
//No need for a new Variant as Dispatch.call returns a Variant.
oADsNewUser.Put("GUID", strGuid);
oADsNewUser.SetInfo();
//Destroy the objects.
ComLib.release(oGuidGen);
ComLib.release(oADsNewUser);
ComLib.release(oADsContainer);
}
catch (Exception ex)
{
User32.MessageBox(0,
ex.toString(),
"Java Exception",
0);
}
}
// J/Direct native API method declarations.
//*******************************************************
/** @dll.import("activeds", ole) */
public static native IUnknown ADsGetObject(String pathname,
_Guid riid);
/** @dll.import("ole32", ole) */
public static native IUnknown CoCreateInstance(_Guid clsid,
IUnknown punkOuter,
int context,
_Guid riid);
/** @dll.import("ole32", ole) */
public static native _Guid CLSIDFromString(String str);
public static _Guid IID_IUnknown = new _Guid("{00000000-0000-0000-C000-000000000046}");
public static Object createObject(String str)
{
return CoCreateInstance(CLSIDFromString(str),
null,
ComContext.INPROC_SERVER | ComContext.LOCAL_SERVER,
IID_IUnknown);
}
}
Microsoft Developer Network (MSDN) Library: "Active Directory Service Interfaces Version 2.0" located in SDK Documentation/Platform
SDK/Networking and Distributed Services.
For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:
APPLIES TO- Microsoft Java Virtual Machine
- Microsoft Visual J++ 6.0 Standard Edition
- Microsoft Software Development Kit for Java 3.1
- Microsoft Active Directory Service Interfaces 2.0
- Microsoft Active Directory Service Interfaces 2.5
| kbhowto kbjava kbjnative KB232485 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
|
 |
 |
 |
 |
 |
 |
 |
| |