Question:You are writing code for user authentication and authorization. The username, password, and roles are stored in your application data store.
You need to establish a user security context that will be used for authorization checks such as IsInRole. You write the following code segment to authorize the user.
If TestPassword(UserName, Password) = False Then
Throw New Exception("Could not authenticate user")
End If
Dim RolesArray() As String = LookUpUserRoles(UserName)
You need to complete this code so that it establishes the user security context.
Which code segment should you use?

 

A Dim objID As New WindowsIdentity(UserName)
Dim objUser As New WindowsPrincipal(objID)
Thread.CurrentPrincipal = objUser 

B Dim objID As New GenericIdentity(UserName)
Dim objUser As New GenericPrincipal(objID, RolesArray) Thread.CurrentPrincipal = objUser 

C Dim objToken As IntPtr = IntPtr.Zero
objToken = LogonUserUsingInterop(UserName, EncryptedPassword) Dim objContext As WindowsImpersonationContext = _
WindowsIdentity.Impersonate(objToken) 

D Dim objNT As New NTAccount(UserName)
Dim objID As New GenericIdentity(objNT.Value)
Dim objUser As New GenericPrincipal(objID, RolesArray) Thread.CurrentPrincipal = objUser 

+ Answer
+ Report
Total Preview: 1095

Copyright © 2024. Powered by Intellect Software Ltd