Programmatic Administration


The basic approach to single sign-on described earlier requires that every user provide credentials the first time they use a web part. Although this approach will work, you may run into some challenges. For example, enterprise applications may require users to change passwords periodically. In this case, the retrieved credentials may not work and you would have to redirect the user to the logon page. As an alternative approach, you may want to give users the ability to manage all of their credentials directly from the portal.

The Application class is the primary class used to administer SSO. This class has a number of subclasses that form collections of information contained in the data store. Table 6-5 lists the subclasses of the Application class.

Table 6-5: Subclasses of the Application Class

CLASS

DESCRIPTION

ApplicationCollection

A collection of all Enterprise Application Definitions

ApplicationInfo

A single application definition from a collection of definitions

ApplicationFieldCollection

A collection of all fields defined in an application

ApplicationField

A single field from a collection of fields

When creating any administrative tool for credentials, you will most likely want to begin by listing the available application definitions. Using the ApplicationCollection class, you can gain access to the entire collection of application definitions and display them. You can access the collection by simply creating the ApplicationCollection object. You can then enumerate the collection to retrieve the definitions. Listing 6-1 shows how to access the collection and display the results in a list box.

Listing 6-1: Listing Application Definitions
start example
 Try     'Get collection of all application definitions     Dim objCollection As New Application.ApplicationCollection     Dim objApp As Application.ApplicationInfo     For Each objApp In objCollection         'List only the individual applications, not group apps         If objApp.Type = Application.ApplicationType.Individual Then             'Create the new listing             Dim objItem As New ListItem             With objItem                 .Text = objApp.ApplicationFriendlyName                 .Value = objApp.ApplicationName             End With             'Add the new listing             lstApps.Items.Add(objItem)          End If     Next Catch x As SingleSignonException     lblMessage.Text = x.Message Catch y As Exception     lblMessage.Text = y.Message End Try 
end example
 

After the available applications are listed, users will want to select an application and enter their credentials. The ApplicationFieldCollection class provides access to all of the fields that are defined for an application. Using this class, you can label a set of text boxes with the required fields for entry. Because each application definition is limited to a maximum of five fields, creating a display where users can enter information is relatively easy to handle. Listing 6-2 shows an example of configuring five TextBox and Label controls to display the field names and a place for the user to type the credentials.

Listing 6-2: Displaying Field Information
start example
 Try     'Get the collection of fields     Dim objFields As New _ Application.ApplicationFieldCollection(lstApps.SelectedValue)     Dim objField As Application.ApplicationField     Dim i As Integer = 0     'Show fields     For Each objField In objFields         i += 1         Select Case i             Case 1                 Text1.Visible = True                 If objField.Mask = True Then                     Text1.TextMode = TextBoxMode.Password                 Else                     Text1.TextMode = TextBoxMode.SingleLine                 End If                 Label1.Visible = True                 Label1.Text = objField.Field             Case 2                 Text2.Visible = True                 If objField.Mask = True Then                     Text2.TextMode = TextBoxMode.Password                 Else                     Text2.TextMode = TextBoxMode.SingleLine                 End If                 Label2.Visible = True                 Label2.Text = objField.Field             Case 3                 Text3.Visible = True                 If objField.Mask = True Then                     Text3.TextMode = TextBoxMode.Password                 Else                     Text3.TextMode = TextBoxMode.SingleLine                 End If                  Label3.Visible = True                 Label3.Text = objField.Field             Case 4                 Text4.Visible = True                 If objField.Mask = True Then                     Text4.TextMode = TextBoxMode.Password                 Else                     Text4.TextMode = TextBoxMode.SingleLine                 End If                 Label4.Visible = True                 Label4.Text = objField.Field             Case 5                 Text5.Visible = True                 If objField.Mask = True Then                     Text5.TextMode = TextBoxMode.Password                 Else                     Text5.TextMode = TextBoxMode.SingleLine                 End If                 Label5.Visible = True                 Label5.Text = objField.Field        End Select    Next    'Show button    btnSubmit.Visible = True Catch x As SingleSignonException     lblMessage.Text = x.Message Catch y As Exception     lblMessage.Text = y.Message End Try 
end example
 

After the credentials are entered into the TextBox controls, the credentials must be updated. This is accomplished by calling the SetCredentials method of the Credentials class. This method updates the SSO data store for the current user. Listing 6-3 shows the code for updating the credentials from the data entered in the TextBox controls.

Listing 6-3: Updating Credentials
start example
 Dim strFields(4) As String strFields(0) = Text1.Text strFields(1) = Text2.Text strFields(2) = Text3.Text strFields(3) = Text4.Text strFields(4) = Text5.Text Try     Credentials.SetCredentials(Convert.ToUInt32(1), lstApps.SelectedValue, _ strFields(0), strFields(1), strFields(2), strFields(3), strFields(4))     lblMessage.Text = "Successfully added credentials." Catch x As SingleSignonException     lblMessage.Text = x.Message Catch y As Exception     lblMessage.Text = y.Message End Try 
end example
 



Microsoft SharePoint[c] Building Office 2003 Solutions
Microsoft SharePoint[c] Building Office 2003 Solutions
ISBN: 1590593383
EAN: N/A
Year: 2006
Pages: 92

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net