Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Webservice in / on Domino Directory

Posted on 2008-11-04
4
Medium Priority
?
569 Views
Last Modified: 2013-11-17
I created with docu from others a webservice on a Domino Directory.
I copied and made sofar 3 meths and was wondering if someone allready made more which i may use.
( in code i can lookup someone, get some info about this user and get the groups of which a user is owner which all works well)

2nd point is authentication.
If i set on the DB Default to No Access i need to authenticate. Can i solve this by a general user in webconfig or username password in encrypted code ?
How can/should  i do this ?

Option Public
Option Declare
Option Base 1
 
Notes Objects
Dim db As NotesDatabase
Dim s As NotesSession
Dim userView As NotesView
Dim userDoc As NotesDocument
'Other objects
Dim i As Integer
Const errorStr = "ERROR"
'The following class defines an array of strings
'that will be returned by the function GetUserList
 
Class UserList
	Public users() As String
End Class
 
'zon play
Class GroupOwnerList
	Public Groups() As String
End Class
 
'The following class defines the user details we will be returning with detailed lookup
Class UserInfo
	Public FirstName As String
	Public LastName As String
	Public FullName As String
	Public EmailAddress As String
	Public OfficePhone As String
	Public MobilePhone As String
End Class
 
Class DomDirLookup
	Sub New
'Initialize our Notes session object
		Set s = New NotesSession
'Then get a handle to the current database
		Set db = s.CurrentDatabase
	End Sub
	
	Function GetUserList(searchStr As String) As UserList
'Local Notes objects used within this function
		Dim tmpName As NotesName
		Dim ve As NotesViewEntry
		Dim vec As NotesViewEntryCollection
		
'Put something out to the console so we know we're running
		Print "Starting GetUserList"
'Make a new user list for our result set
		Set GetUserList = New UserList
'Populate the list with a default value
		Redim GetUserList.Users(1)
		GetUserList.Users(1) = "Error retrieving user list"
'Open the view we're going to lookup against
		Set userView = db.GetView("($VIMPeopleByLastName)")
		If Not userView Is Nothing Then
'Do we have a search string?
			If Len(Trim(searchStr)) > 0 Then
'See if we can find any users by the search string
				Set vec = userView.GetAllEntriesByKey(searchStr)
			Else
'Otherwise get all documents
				Set vec = userView.AllEntries
			End If
'Now, if we have any entries - put them into the array
			If vec.Count > 0 Then
'Redimension the array to the size of the result set
				Redim GetUserList.Users(vec.count)
'Process all of the entries in the View Entry
'Collection
				For i = 1 To vec.Count
					Set ve = vec.GetNthEntry(i)
					If Not ve Is Nothing Then
						Set userDoc = ve.Document
						If Not userDoc Is Nothing Then
							Set tmpName = New _
							NotesName(userDoc.FullName(0))
							GetUserList.Users(i) = _
							tmpName.Common
						Else
							GetUserList.Users(i) = errorStr
						End If
					Else
						GetUserList.Users(i) = errorStr
					End If
				Next
			Else
				GetUserList.Users(1) = "No users found matching search criteria"
			End If
		End If
		Print "Leaving GetUserList"
	End Function
	Function GetUserDetails(searchStr As String) As UserInfo
'Put something out to the console so we know we're running
		Print "Starting GetUserDetails"
'Make a new user list for our result set
		Set GetUserDetails = New UserInfo
'Initialize our default return value
		GetUserDetails.FullName = "Unable to locate specified user" 
'Do we have a search string?
		If Len(Trim(searchStr)) > 0 Then
'Open the view we're going to lookup against
'this is a different view because we're searching against
'the full name where above we're using last name
			Set userView = db.GetView("($VIMPeople)")
'Make sure we have the view
			If Not userView Is Nothing Then
'Try to get the user document using abbreviated full
'name as a key This should work because the view is
'sorted that way.
				Set userDoc = userView.GetDocumentByKey(searchStr)
				If Not userDoc Is Nothing Then
'Populate the result fields
					GetUserDetails.FullName = userDoc.FullName(0)
					GetUserDetails.LastName = userDoc.LastName(0)
					GetUserDetails.FirstName = userDoc.FirstName(0)
					GetUserDetails.EmailAddress = _
					userDoc.InternetAddress(0)
					GetUserDetails.OfficePhone = _
					userDoc.OfficePhoneNumber(0)
					GetUserDetails.MobilePhone = _
					userDoc.MobilePhoneNumber(0)
				End If
			End If
		Else
			Print "No user name provided, exiting"
		End If
		Print "Leaving GetUserDetails"
	End Function
	
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	' zon play get groups of which user is owner
'////////////////////////////////////////////////////////////////////////////////////////////////
	Function GetGroupOwnerList(searchStr As String) As GroupOwnerList
'Local Notes objects used within this function
		Dim tmpName As NotesName
		Dim ve As NotesViewEntry
		Dim vec As NotesViewEntryCollection
		
'Put something out to the console so we know we're running
		Print "Starting GroupOwnerList"
'Make a new user list for our result set
		Set GetGroupOwnerList = New GroupOwnerList
'Populate the list with a default value
		Redim getGroupOwnerList.groups(1)
		GetGroupOwnerList.groups(1) = "Error retrieving user list"
'Open the view we're going to lookup against
		Set userView = db.GetView("Admin Views\Groups\by Owners")
		If Not userView Is Nothing Then
'Do we have a search string?
			If Len(Trim(searchStr)) > 0 Then
'See if we can find any users by the search string
				Set vec = userView.GetAllEntriesByKey(searchStr)
			Else
'Otherwise get all documents
				Set vec = userView.AllEntries
			End If
'Now, if we have any entries - put them into the array
			If vec.Count > 0 Then
'Redimension the array to the size of the result set
				Redim GetGroupOwnerList.Groups(vec.count)
'Process all of the entries in the View Entry Collection
				For i = 1 To vec.Count
					Set ve = vec.GetNthEntry(i)
					If Not ve Is Nothing Then
						Set userDoc = ve.Document
						If Not userDoc Is Nothing Then
							GetGroupOwnerList.Groups(i) =userDoc.Listname(0)
						Else
							GetGroupOwnerList.Groups(i) = errorStr
						End If
					Else
						GetGroupOwnerList.Groups(i) = errorStr
					End If
				Next
			Else
				GetGroupOwnerList.Groups(1) = "No users found matching search criteria"
			End If
		End If
		Print "Leaving GetGroupOwnerList.Groups"
	End Function
End Class

Open in new window

0
Comment
Question by:RonaldZaal
  • 2
  • 2
4 Comments
 
LVL 22

Expert Comment

by:mbonaci
ID: 22875520
Which services do you need, besides the one you posted?

The webservices consumer is authenticated just like any other Domino web user, so to handle unauthenticated web access to your db add Anonymous entry in the ACL and assign the appropriate access.


Hope this helps,
Mb¤
0
 
LVL 5

Author Comment

by:RonaldZaal
ID: 22875834
Thanks for speed Mb,
Services like,
 request in which groups a user resides
 request which users are in group X
 request as much as possible info from a person doc
Stuff like that and maybe more  

Anonymous is indeed a solution, but suppose the admins don't want that unknown person in the ACL, would there be another way ?
0
 
LVL 22

Accepted Solution

by:
mbonaci earned 2000 total points
ID: 22893416
For all users you want authenticated, you should put them in the ACL.
Make sure they have set Internet password in their person doc in server's names.nsf.

Here are the functions that you'll implement in your code, as web services:
Function GetAllValidGroupsForUser(username As String, server As String, maxdepth As Integer) As Variant
%REM
	This function gets all the groups that a user can belong to.
	This is a RECURSIVE function, so be careful when modifying it.
	MAXDEPTH is used to regulate how far down in group levels it can go.
	If checking ACL groups, 6 is the limit, for mail groups its 20 -- but this can change with Domino versions in the future.
	This sample code is distributed freely with only one obligation. 
	You must distribute this code as a whole, including these comments, if you distribute it or re-use it at all.
	For help, please contact
	andrewp@thenorth.com
	Andrew Pollack
	Northern Collaborative Technologies
%END REM
      ' use static variables so that you can avoid repeatedly
      ' getting a handle to the same resources.
      Static nab As notesdatabase
      Static nabview As notesview
      Static userview As notesview
      Static foundlist List As String
      Static depth As Integer
      ' since depth is a static variable, each recursive call to this
      ' function will increase its value.  We can also decrease its
      ' value so we know when we're back to the initial call.
      If depth => MAXDEPTH Then Exit Function
      depth = depth + 1
      ' check to see if we haven't already connected to the nab & views
      ' if not, connect now.
      If nab Is Nothing Then Set nab = New notesdatabase(server,"NAMES.NSF")
      If nab Is Nothing Then Exit Function
      If nabview Is Nothing Then Set nabview = nab.getview("($ServerAccess)")
      If userview Is Nothing Then Set userview = nab.getview("($Users)")
      If userview Is Nothing Then Exit Function
      If nabview Is Nothing Then Exit Function
      ' declarations
      Dim collection As notesdocumentcollection
      Dim doc As notesdocument
      Dim v As Variant
      Dim count As Integer
      Dim usercount As Integer
      Dim alreadyhandlednamevariants As Integer
      Redim usernamelist(0) As String
      Dim tempusernamelist As Variant
  ' first set the first username in the list to the current one as called
  ' keep in mind, if this is not the first call, but part of the recursion,
  ' this may be another variant of the name, or the name of a group
      usernamelist(0) = username
  ' this section will build an array of all the shortnames and name variants the user has
  ' by checking for a person record in the nab, using that to get the fullname of the user
  ' then calculating all the name variants on that (uses the function getNotesNameVariants)
      Set doc=userview.getdocumentbykey(username, True)
      If Not doc Is Nothing Then
            If doc.form(0) = "Person" Then
                  usercount = 0
                  Forall shortname In doc.fullname
                        Redim Preserve usernamelist(usercount) As String
                        usernamelist(usercount) = shortname
                        ' don't recheck variants if you've already checked the name
                        If Not alreadyhandlednamevariants = 1 Then
                              tempusernamelist = getnotesnamevariants(shortname)
                              'add all the found variants to the list of names to be checked
                              Forall tusername In tempusernamelist
                                    usercount = usercount + 1
                                    Redim Preserve usernamelist(usercount)
                                    usernamelist(usercount) = tusername
                              End Forall
                        End If
                        usercount = usercount +1
                  End Forall
            End If
      End If
      ' this is the result that will be returned at the end of the function
      Redim returnlist(0) As String
      ' here's the meat of the function
      Forall checkusername In usernamelist 'for each name variant
            If Not checkusername = "" Then ' don't check 'empty' names
                  Set collection = nabview.getalldocumentsbykey(checkusername,True) ' get any groups the name matches
                  If Not collection.count = 0 Then ' if there are any matches
                        Set doc = collection.getfirstdocument
                        While Not doc Is Nothing ' loop through all the matching groups
                              If Not doc.listname(0) = "" Then
                                    If Not Iselement(foundlist(doc.listname(0))) Then
                                          ' use this static list to avoid duplicate calls & infinite loops
                                          foundlist(doc.listname(0)) = "1"
                                          ' look! Here's the recursion! We're calling THIS function again
                                          ' with the new name variant.  It will return the list from this
                                          ' variant.  Deeper and Deeper it goes!
                                          v = getallvalidgroupsforuser(doc.listname(0), server, maxdepth)
                                          If Not Isempty(v) Then
                                                ' add the ones from the last depth to the current list,
                                                ' and prepare to return it to the one that called this one!
                                                Forall group In v
                                                      If Not group = "" Then
                                                            Redim Preserve returnlist(count) As String
                                                            returnlist(count) = group
                                                            count = count + 1
                                                      End If
                                                End Forall
                                          End If
                                          Redim Preserve returnlist(count)
                                          returnlist(count) = doc.listname(0)
                                          count = count + 1
                                    End If
                                    Set doc=collection.getnextdocument(doc)
                              End If
                        Wend
	       End If
            End If
      End Forall
      ' whew, now just return the list of all we found, plus all those found by
      ' any recursive calls we made, and the calls they made, and the calls they made, ...
      getallvalidgroupsforuser = returnlist
      depth = depth -1
      If depth = 0 Then
    ' this exit will be the last recursion, so delete the static list so we can run again if we need!
            Erase foundlist
      End If
End Function
 
 
 
 
 
Function GetAllUsersInGroup( groupname As String, Server As String, maxdepth As Integer ) As Variant
%REM
	This function gets all the users in any group, including nested subgroups.
	This is a RECURSIVE function, so be careful when modifying it.
	MAXDEPTH is used to regulate how far down in group levels it can go.
	If checking ACL groups, 6 is the limit, for mail groups its 20 -- but this can change with Domino versions in the future.
	This sample code is distributed freely with only one obligation. You must distribute this code as a whole, including these comments, if you distribute it or re-use it at all. 	For help, please contact
	andrewp@thenorth.com
	Andrew Pollack
	Northern Collaborative Technologies
%END REM
      ' use static variables so that you can avoid repeatedly
      ' getting a handle to the same resources.
      Static nab As notesdatabase
      Static nabview As notesview
      Static groupview As notesview
      Static foundlist List As String
      Static checkedgroups List As String
      Static depth As Integer
      ' this is the list containing the results to return
      Dim returnlist List As String
      ' just a stray string variable to be used
      Dim tempstring As String
      ' set this to return the empty list, in case we have to exit due to error
      getallusersingroup = returnlist
      ' since depth is a static variable, each recursive call to this
      ' function will increase its value.  We can also decrease its
      ' value so we know when we're back to the initial call.
      If depth => maxdepth Then Exit Function  ' dont look deeper then n nested groups
      depth = depth + 1
      ' check to see if we haven't already connected to the nab & views
      ' if not, connect now.
      If nab Is Nothing Then Set nab = New notesdatabase(server,"NAMES.NSF")
      If nab Is Nothing Then Exit Function
      If nabview Is Nothing Then Set nabview = nab.getview("($ServerAccess)")
      If groupview Is Nothing Then Set groupview = nab.getview("($VIMGroups)")
      If groupview Is Nothing Then Exit Function
      If nabview Is Nothing Then Exit Function
      ' declarations
      Dim collection As notesdocumentcollection
      Dim doc, checkdoc As notesdocument
      Dim v As Variant
      Dim count As Integer
      Dim usercount As Integer
      Dim user As notesname
      ' Now we get to the meat of the function
      Set doc = groupview.getdocumentbykey(groupname, True) ' first, find the group
      If doc Is Nothing Then Exit Function ' there is no group
      Forall member In doc.members ' for each entry in the the group
            tempstring = Ucase$(member)
            ' *******************************************************
            ' make sure we haven't already checked this entry
            If Not Iselement(returnlist(tempstring)) Then
                  If Not Iselement(foundlist(tempstring)) Then
                        If Not Iselement(checkedgroups(tempstring)) Then
            ' *******************************************************
                              Set checkdoc = groupview.getdocumentbykey(tempstring, True)
                              If checkdoc Is Nothing Then
                              ' treat as a user, add them to the return and found lists
                                    foundlist(tempstring) = "1"
                                    returnlist(tempstring) = "1"
                              Else		      		    ' this is a new group to check
                              ' so we recursively call this very function with the new groupname
                                    checkedgroups(tempstring) = "1"
                                    v = GetAllUsersInGroup( tempstring, server, maxdepth )
                                    Forall newmember In v
                                          ' add the results from the recursive call to the return lists
                                          returnlist(Listtag(newmember)) = "1"
                                          foundlist(Listtag(newmember)) = "1"
                                    End Forall
                              End If
                        End If
                  End If
            End If
      End Forall
      ' whew, now just return the list of all we found, plus all those found by
      ' any recursive calls we made, and the calls they made, and the calls they made, ...
      getallusersingroup = returnlist
      depth = depth -1
      If depth = 0 Then
	' this exit will be the last recursion, so delete the static list so we can run again if we need!
            Erase foundlist
            Erase checkedgroups
      End If
End Function
 
 
 
 
Function GetUserDocumentFromNAB( userName As String, serverName As String ) As NotesDocument
		 'Mb¤, 19.08.2008
		 'The function returns the user document from server's NAB
		 Dim nab As notesdatabase
		 Dim v As notesview
 
		 'get the NAB db
		 Set nab = New notesdatabase( serverName,"NAMES.NSF" )
		 If nab Is Nothing Then Exit Function
 
		 'get the users view from NAB
		 Set v = nab.getview("($Users)")
		 If v Is Nothing Then Exit Function
 
		 Set GetUserDocumentFromNAB = v.GetDocumentByKey( userName, True )
 
End Function
 
Function IsUserPresentInNAB( userName As String, serverName As String ) As Boolean
		 'Mb¤, 19.08.2008
		 'The function returns True if user document exists in server's NAB, otherwise False
 
		 If Not GetUserDocumentFromNAB( "ReplaceWithUserName", "ReplaceWithServerName" ) Is Nothing Then IsUserPresentInNAB = True
 
End Function

Open in new window

0
 
LVL 5

Author Comment

by:RonaldZaal
ID: 22895893
many thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month21 days, 4 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question