(c) 2003 Visual Studio Magazine 
Fawcette Technical Publications

VB.NET	Check Access
Listing 1	You call the AccessCheck function on the client context to request permissions from Authorization Manager on a list of operations. The operations parameter contains the list of operation IDs for which the code requests permission.

Private Function DoCheck() As Boolean
	Dim objectname_foraudit_purpose_only As String = "acheck"
	Dim scopes() As Object = {""}
	Dim op_1 As Integer = 1
	Dim op_2 As Integer = 2
	Dim operations As Object() = New Object() {op_1, op_2}
	Dim results() As Object = _
		CType(m_IAzClientContext.AccessCheck( _
		objectname_foraudit_purpose_only, _
		scopes, operations), Object())
	For Each l_res As Object In results
		If Not CType(l_res, Integer) = 0 Then
			Return False
		End If
	Next
	Return True
End Function

VB.NET	Authenticate and Initialize
Listing 2	The Login routine authenticates the ADAM user, extracts the SID, and uses it to initialize the Authorization Manager client context.

Public Shared Function Login(ByVal p_Name As String, ByVal _
	p_PWD As String) As AdamPrincipal
	Try
		Dim l_entry As New DirectoryEntry( _
			"LDAP://" + "localhost" + ":" + _
			"1389" + "/" + "DC=MyApp,DC=SABBASOFT,DC=COM", _
			pf_makeFullDN(p_Name), p_PWD, _
			AuthenticationTypes.None)
		Dim mySearcher As New DirectorySearcher(l_entry)
		mySearcher.Filter = ("(&(objectClass=user)( _
			name=" + p_Name + "))")
		Dim l_s As SearchResult = mySearcher.FindOne
		If l_s Is Nothing Then Throw New Exception( _
			"Critical Error, Couldn't find logged user")
		Dim SID As Byte() = _
			l_s.Properties.Item("objectSID").Item(0)
		Dim sSID As String
		Dim sidPtr As IntPtr = Marshal.AllocHGlobal(SID.Length)
		Marshal.Copy(SID, 0, sidPtr, SID.Length)
		ConvertSidToStringSid(CType(sidPtr, IntPtr), sSID)
		Dim l_IAzClientContext As IAzClientContext = _ 
			m_app.InitializeClientContextFromStringSid(sSID, _ 
			tagAZ_PROP_CONSTANTS.AZ_CLIENT_CONTEXT_SKIP_GROUP)
	Catch ex As Exception
		Throw (New Exception("Login Failed"))
	End Try
End Function
