Creating eDirectory Utilities Using ActiveX
Download
Report
Transcript Creating eDirectory Utilities Using ActiveX
™
eDirectory
Creating Novell
Utilities Using ActiveX
www.novell.com
Gary J. Porter
Senior Network Analyst
MindWorks, Inc. of Kentucky
[email protected]
Deployed Versions Novell eDirectory™
and Novell Directory Services® (NDS)
Product Version
Build Version
Platforms
NetWare 5.1 SP4 (NDS 7)
DS.nlm v7.57
NetWare 5.1
NetWare 5.1 SP 4 (NDS 8)
DS.nlm v8.79
NetWare 5.1
eDirectory 8
DS.nlm & DS.dlm v8.79
NetWare 5.0,Win NT/2K
eDirectory 8.5.x
DS v85.23
NetWare 5.x,Win,Solaris
NetWare 6 (eDirectory 8.6)
DS.nlm v10110.20
NetWare 6
eDirectory 8.6.1
DS v10210.43
NW 5.1,NW 6,Win,Solaris,Linux
NetWare 6 SP1 (eDirectory 8.6.2)
DS.nlm v10310.17
NetWare 6
eDirectory 8.6.2
DS v103xx.xx
NW 5.1,NW 6,Win,Solaris,Linux
eDirectory 8.7
DS v10410.xx
NW 5.1,NW 6,Win,Solaris,Linux,AIX
Differences Between eDirectory
and NDS®
NDS
eDirectory
NOS directory focused on
managing NetWare® servers
A cross-platform, scalable,
standards-based directory
used for managing identities
that span all aspects of
the network—eDirectory
is the foundation for eBusiness
NetWare 5
NetWare
NetWare 6
The History of ActiveX
•
•
•
•
•
•
Dynamic Data Exchange (DDE)
Object Linking and Embedding (OLE)
OLE 2/Component Object Model (COM)
Visual Basic Controls (VBX)
OLE Custom Controls (OCX)
ActiveX
ActiveX
• In 1996, in an attempt to make the technology
less confusing, Microsoft branded the name
ActiveX and used it to define COM-based
technologies
• OLE was assigned the mission of referring only
to compound documents
• ActiveX open the door to RAD programming
RAD (Rapid Application Development)
• RAD allows reusability
• The logic behind this new revolution is simple—in order
to keep the costs down and productivity up, the
programmer follows four steps, only writing new code
when all else fails
1.
2.
3.
4.
Re-use existing code
Modify existing code
Buy someone’s code
Write new code
• This class is based on RAD—develop applications quickly
Terminology
Novell eDirectory™
ActiveX
Tree
Directory
Class
Layout
Syntax
Field
Object
Entry
Attribute
Field
Fully
Full
Distinguished Name
Relative Distinguished Name
type
Name
Short Name
NWBind
• The Bindery control allow you to
Create
and delete local users
Search and filter entries
Manage passwords
Perform backup and restore functions
on the local Bindery
NWDir (The Keys to the Kingdom)
• With this control, the RAD programmer can
Edit
*NDS® entries
Add objects
Delete objects
Search for objects
* Novell Directory Services®
NWIDir
• Provides the functionality to
Search
and filter LDAP entries
Determine the entry layout and associated fields
Return a user name and fields
Add, delete and modify LDAP entries
Collections
• Groups of like objects
• The ActiveX controls
consists of several
controls, each with
several collections
NWDir—10
collections
NWIDir—8 collections
Directory Collections (NWDir/NWIDir)
• NWEntries
All
objects in the eDirectory instance
To add a new user you use the NWEntries collection
• NWEntry
A
single entry
A user, itself, is a collection of attributes
To display a users attributes, you would use the
NWEntry collection
Methods and Properties
• Most programmers dealing with Microsoft
products have a thorough understanding of the
terms Method and Property but for the sake of
those that are new to the visual environment…
Property
is an attribute of a control
Method is a function that an object can perform
—What I can do…
—A description of me…
Double-click
background
Project One—Display Trees
• Open Visual Basic
• Select Standard EXE
• Right click on the “Components” toolbox
Select Novell
Session Control
Right mouse click
Project One—Display Trees
• Add the Session control to the Form
• Select
“ListBox” and wipe across the Form
Project One—Display Trees
• Add the Session control to the Form
• Select
“ListBox” and wipe across the Form
Project One—Display Trees
• Double-click in the form—not in the ListBox
In here…
NWDir
• It is used to set context (which determines which
collections are in view) and enables the
collections that you will use to read information
and effect changes
• It allows you to search for entries and/or filter
entries
• If you’re using NDS version 8 (eDirectory), sort
collections according to an index
• The control itself has eleven properties, nine
methods, and four events
NWDir Properties
• Entries—(NWEntries Collection) the entries contained in
•
•
•
•
•
the current context of the directory
Entry—(NWEntry object) the root object represented by
the current context or FullName
FieldTypes—(NWFieldTypes collection) the field types or
attributes of the directory
Filters—(String) allows searching and display of specific
layouts at run time
FullName—(String) sets or displays the current context
Layouts—(NWLayoutDescription) the object classes or
layouts contained in the current tree
NWDir Properties
(cont.)
• LoginName—(String) the FullName of the current logged•
•
•
•
in user
Pictures—(NWPictures collection) a collection of bitmaps
that iconize standard NDS objects
ShortName—(String) the relative distinguished name of
the root most object of the current context
SortedEntries—(Boolean) sorts the NWEntries collection
when set to TRUE (only available for eDirectory)
SortBy—(String) sets or returns the index key to sort the
NWEntries collection (only available for eDirectory)
NWDir Methods
• ContextFromFullName—returns only the context portion
•
•
•
•
of a FullName
FindEntry—locates and establishes a link to an entry in
the Directory
FindNextEntry—returns the following entry from the list
sorted by the key specified in the FindEntry method (only
available for eDirectory)
FindPrevEntry—returns the previous entry from the list
sorted by the key specified in FindEntry (only available
for eDirectory)
FullNameFromTreeAndContext—concatenates a given tree
name and context to form a FullName
NWDir Methods
(cont.)
• Search—initiates a search of the current context and/or
its subordinates for a specific set of elements
• StopSearch—stops the search begun by the search method
• TreeFromFullName—returns the name of the tree from
the FullName property
• SearchLimited—used to narrow a search to a specific
element, layout, or number of objects
NWDir Events—Event Triggers
• EntryAdded—triggers when an entry has been successfully
added to the tree
• EntryDeleted—triggers when an entry has been
successfully deleted from the tree
• RefreshViews—triggers when the current context or tree
name has been modified
• SearchCompleted—triggers when a directory search has
been completed
NWDir Collections
•
•
•
•
•
•
•
•
•
•
NWEntries
NWEntry
NWPictures
NWPicture
NWLayout Descriptions
NWLayoutDescription
NWFieldTypes
NWFieldType
NWFieldDescriptions
NWFieldDescription
Project Three—What’s Here?
• In this exercise we’ll display other items at
the same context
• Place a Label and a List Box on the form
Project Three—What’s Here?
What’s Here?—Running
NWEntries Properties
• Count—(Long) the number of objects within a
collection
• Item—(Index) returns a specific NWEntry object
• RelativeIndex—(Boolean) specifies whether an
index passed to an item is relative or absolute
NWEntries Methods
• Add—used to add an item to the collection
• Remove—used to delete an item from the
collection
• Refresh—used to refresh the contents of the
collection
NWEntries
• If you think about it, there are few things
you can do with an entire collection, except
Displaying
it
Adding to it
Deleting from it
Add Items Method
• To add items to a collection, you must supply the
control with the layout and the object name
NWDir1.Entries.Add(layout,objectName)
• A layout represents the recipe for an entire class
of objects
• A layout describes the very essence of what the
object is—for instance, User or Printer or Server
In NDS and eDirectory, the concept of layout is complicated
(mostly because of inheritance, super classes and base classes)
Add Items Method
• X.500 rules state that a user must have a
surname before it can be created
• It may seem a little strange that an entity must
have an attribute before it is created
• We’ll explore this as soon as we have a few more
tricks up our sleeve…however, it looks something
like this
Dim AddObject As NWEntry
Set AddObject = NWDir1.Entries.Add("User","Jan")
Remove Item Method
• Removing or deleting objects within a collection
is rather simple and merely reference the object
in the function
• Remember, however, the current collection of
entries is represented by the current
context-only the named object in the current
context will be deleted
Dim Success as Boolean
Success = NWDir1.Entries.Remove("Ken")
Refresh Method
• The refresh method is used to reload
the contents of a collection
NWDir1.Entries.Refresh
NWEntry Properties
• Alias—(Boolean) indicates if an entry is an alias of
•
•
•
•
another entry
Entries—(Abstracts the NWEntries collection) returns the
contents of a container
FullName—(String) returns the fully qualified
distinguished name of the selected context
ImageIndex—(String) the index key that’s used to locate a
corresponding icon or bitmap in NWDir.Pictures
Layout—(NWLayoutDescription) returns information on
the object class of an entry
NWEntry Properties
• OtherNames—(Variant) returns additional values (if
present) for the ShortName property
• PartitionRoot—(Boolean) indicates whether an entry is
a Partition Root object by returning True or False if the
object is not a Partition Root object
• ShortName—(String) returns the relative distinguished
name of an object
• Tag—(String) a user-defined property available for
programming purposes
NWEntry Methods
•
•
•
•
•
•
•
•
Update/abort
GetFieldValue
UpdateFieldValueFromFile
SaveFieldValueToFile
SetFieldValue
SetPassword
ValidatePassword
Move
Update/Abort Methods
• Once an entry has been successfully defined,
the Update method is used to “seal the deal”
and actually create the object in eDirectory
If Something then
Object.Update
Else
Object.Abort
End if
Project Four—Add a User (Using NWDir)
• Open new “Standard EXE” project
• Add the Novell Directory Control to the form
• Add and run
Dim Success As NWEntry
Set Success = NWDir1.Entries.Add("User", "Anna")
If Success.SetFieldValue("Surname", "Kerr") Then
Success.Update
Else
Success.Abort
End If
GetFieldValue Method
• Similar to SetFieldValue—this method is used
to retrieve the contents of an attribute
Object.GetFieldValue(FieldName, DefaultValue, ForceAsArray)
GetFieldValue Method
Private Sub Form_Load()
DIM NDSObj as NWEntry
' find Jan's entry in NDS
Set NDSObj = NWDir1.FindEntry("NDS:\\MWI_INC\MWI\Accounts\Jan")
' fill the contents of Label1 with information about the subject
Label1.Caption = "Attributes for " + NDSObj.ShortName
' list the contents of all attributes in the array List1
For Each Entry In NDSObj.GetFieldValue("", "", True)
List1.AddItem (Entry)
Next
End Sub
LDAP
• But…LDAP is where it’s at these days
• The ActiveX Control for LDAP is NWIDir
• Similar to NWDir
NWEntries
NWEntry
Open a Project, Standard EXE
Right mouse click
NWIDir Control Properties
Right mouse click
Set the Initial LDAP Namespace Instance
Press Enter
Simple LDAP Search Engine
Form Layout
Toolbar
Add the NWDir Control
Form Layout
Toolbar
TextBox, Text1
Form Layout
Toolbar
Label, Label1
Caption = “Server address and search base”
Form Layout
Toolbar
OptionButton, Option1
Form Layout
Toolbar
OptionButton, Option2
Form Layout
Toolbar
Label, Label2
Caption = “Long Names”
Let’s label the options
Form Layout
Toolbar
Label, Label2
Caption = “Short Names”
Form Layout
Toolbar
ListBox, List1
Form Layout
Toolbar
CommandButton, Command1
Caption = “&Browse”
Form Layout
Toolbar
CommandButton, Command2
Caption = “E&xit”
Last Asthetic Move…
Walking-N-Man.bmp
Now for the Code
• First we’ll fill Text1 with
the default LDAP
Namespace
• We’ll make Option1 the
default Option
• Next, we’ll fill List1 after
pressing the Browse
button
• Lastly, we’ll provide an
Exit button
Now for the Code
• Double click inside the
form, making sure not
to double-click on one
of the controls placed
on the page
The Code (Form_Load)
• The main form is easy enough
Private Sub Form_Load()
Option1 = True
Text1.Text = NWIDir1.FullName
End Sub
• Option1 is made default by making it “True”
• Assigning a value to Text1 is accomplished by specifying
the FullName property of the control (NWIDir)
Remember that each copy of the control placed on the page
will be an instance, in this case instance one is NWIDir1
The Code—Command1_Click
Private Sub Command1_Click()
List1.Clear
NWIDir1.FullName = Text1.Text
Set LDAPEntry = NWIDir1.FindEntry(Text1.Text)
Set LDAPEntries = LDAPEntry.Entries
For Each Entry In LDAPEntries
If Option1 Then
List1.AddItem (Entry.FullName)
Else
List1.AddItem (Entry.ShortName)
End If
Next
End Sub
The Code—Command1_Click
(cont.)
• When the Browse button is clicked, we first clear
the list, List1
Otherwise
each subsequent click would fill the list
with new contents, making it larger and larger
• Next we assign the context with the value of
Text1
It
may seem redundant to do this here but by doing
so, we give the user the opportunity to change the
value of Text1—to indicate a LDAP repository and
searchbase different from the default
The Code—Command1_Click
(cont.)
• Next we focus on a specific LDAP search base by setting
the value of LDAPEntry
This method is commonly used to indicate a beginning container
• We also set LDAPEntries to the property of LDAPEntry—
Entries which indicates that we are interested in the
collection of “things” at the context “LDAPEntry” which
was set from Text1.Text
• It may seem convoluted now but it will make perfect
sense after you’ve done it a few times
The Code—Command1_Click
(cont.)
• Finally, we fill the ListBox with the “things” we
have found in the collection LDAPEntry.Entries
• The last thing to do is to provide an exit
To
do this simply place “End” on the CommandButton
Click
Private Sub Command2_Click()
End
End Sub
The Code from Form1
Short and Long Options
Conclusion
• There are millions of lines of code to be written
with the Novell Controls for ActiveX
• It’s easy (and fun)
• Attend the hands-on session DCB104
eDirectory Programming with Visual Basic and ActiveX