adTempus API
PreviousUpNext
Credential Profile Retrieval

This example demonstrates how to get or create the CredentialProfile for a user account.

Description

Instead of specifying a user ID and password directly for a job, adTempus now uses Credential Profiles. When you create a new job, you must get or create the Credential Profile for the user whose account the job will use. 

This helper class simplifies the process. Given a Windows user ID and password, you can call CredentialProfileGetter.GetCredentialProfile, which will return the existing CredentialProfile for that user, if one exists, or create and save a new CredentialProfile for the user. 

If the profile already exists, GetCredentialProfile calls ICredentialProfile.VerifyPassword to confirm that the specified password is correct. 

The method requires an existing client connection. See Creating a Client Session for an example of creating a client connection. 

 

Public Class CredentialProfileGetter


    'GetCredentialProfile gets a CredentialProfile for the specified userID.
    'GetCredentialProfile first checks to see if a CredentialProfile already exists
    'for the specified user. If so, it uses the password to obtain access to the profile
    'for the calling user.
    'If no profile exists, GetCredentialProfile creates one.
    Public Shared Function GetCredentialProfile(ByVal connection As Scheduler, ByVal userID As String, ByVal password As String) As CredentialProfile
        Dim filter As New CredentialProfileFilter(userID)
        Dim profile As CredentialProfile
        Dim objects As IADTObjects
        Dim recordCount As Int32

        objects = connection.GetObjectsWhere(filter, 0, True, recordCount)
        'there should be at most one returned
        If objects.Count > 0 Then
            profile = CType(objects(0), CredentialProfile)

            'VerifyPassword confirms that the correct password
            'has been specified, and grants the caller permission to use
            'the profile.
            If profile.VerifyPassword(password, True) Then
                'All set.
                Return profile
            Else
                'The password is incorrect
                Throw New Exception("Incorrect password specified")
                Return Nothing
            End If
        End If

        'else there is no existing CredentialProfile for the specified userID.
        'Create a new one.

        profile = CType(connection.CreateObject(ClassIDEnum.CID_CredentialProfile), CredentialProfile)
        profile.UserID = userID
        profile.SetPassword(password)
        profile.Save()
        Return profile

    End Function


    'Use in a call to IScheduler.GetObjectsWhere to get the job with the specified name.
    Private Class CredentialProfileFilter
        Implements IObjectRequestFilter
        Public UserID As String = ""
        Public Sub New(Optional ByVal name As String = "")
            UserID = name
        End Sub
        Public Function GetOrderClause() As String Implements ArcanaDevelopment.adTempus.Client.IObjectRequestFilter.GetOrderClause
            Return ""
        End Function

        Public Function GetSelectClause() As String Implements ArcanaDevelopment.adTempus.Client.IObjectRequestFilter.GetSelectClause
            Return "*"
        End Function

        Public Function GetTableName() As String Implements ArcanaDevelopment.adTempus.Client.IObjectRequestFilter.GetTableName
            Return "credentialProfile"
        End Function

        Public Function GetWhereClause() As String Implements ArcanaDevelopment.adTempus.Client.IObjectRequestFilter.GetWhereClause
            'This filter only looks at Windows logon credentials, which
            'do not have the credentialType set.
            Return "userID='" & UserID & "' and credentialType is NULL"
        End Function
    End Class

End Class
adTempus API Reference version 3.0.0.0, revised 10/30/2008