You are writing code for user authentication and authorization.

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 GenericIdentity(UserName)
    Dim objUser As New GenericPrincipal(objID, RolesArray)
    Thread.CurrentPrincipal = objUser
B. Dim objID As New WindowsIdentity(UserName)
    Dim objUser As New WindowsPrincipal(objID)
    Thread.CurrentPrincipal = objUser
C. Dim objNT As New NTAccount(UserName)
    Dim objID As New GenericIdentity(objNT.Value)
    Dim objUser As New GenericPrincipal(objID, RolesArray)
    Thread.CurrentPrincipal = objUser
D. Dim objToken As IntPtr = IntPtr.Zeroobj
    Token = LogonUserUsingInterop(UserName, EncryptedPassword)
    Dim objContext As WindowsImpersonationContext =
    _WindowsIdentity.Impersonate(objToken)



Answer: A
 



No comments:

Post a Comment