Question:
You are developing an application that runs by using the credentials of the end user. Only users who are members of the Administrator group get permission to run the application. You write the following security code to protect sensitive data within the application.
Dim blnAdmin As Boolean = False
Dim objRole As WindowsBuiltlnRole =
WindowsBuiltInRole.Administrator
If blnAdmin = False Then
Throw New Exception("User not permitted")
End If
You need to add a code segment to this security code to ensure that the application throws an exception if a user is not a member of the Administrator group.
Which code segment should you use?
A Dim objUser As UindowsPrincipal =
DirectCast(Thread.CurrentPrincipal, WindowsPrincipal) blnAdmin = objUser.IsInRole(objRole)B Dim objUser As GenericPrincipal =
DirectCast(Thread.CurrentPrincipal, GenericPrincipal) blnAdmin = objUser.IsInRole(objRole.ToString)C Dim objUSer As Windowsldentity =
DirectCast(Thread.CurrentPrincipal.Identity, Windowsldentity) blnAdmin = objUSer.Name.EndsUith ("Administrator")D Dim objUser As WindowsIdentity = WindowsIdentity.GetCurrent For Each objGroup As IdentityReference In objUser.Groups Dim objAccount As NTAccount =
DirectCast(objGroup.Translate(
Type.GetType("NTAccount")),NTAccount)
blnAdmin = objGroup.Value.Equals(objRole)
Next
+ AnswerA
+ Report