Example #1
0
 /// <summary>
 /// Constructor used to construct a PSIdentity object
 /// </summary>
 /// <param name="authType">
 /// Type of authentication used to authenticate this user.
 /// For a WSMan service authenticated user this will be one of the following:
 ///  WSMAN_DEFAULT_AUTHENTICATION
 ///  WSMAN_NO_AUTHENTICATION
 ///  WSMAN_AUTH_DIGEST
 ///  WSMAN_AUTH_NEGOTIATE
 ///  WSMAN_AUTH_BASIC
 ///  WSMAN_AUTH_KERBEROS
 ///  WSMAN_AUTH_CLIENT_CERTIFICATE
 ///  WSMAN_AUTH_LIVEID
 /// </param>
 /// <param name="isAuthenticated">
 /// true if this user is authenticated.
 /// </param>
 /// <param name="userName">
 /// Name of the user
 /// </param>
 /// <param name="cert">
 /// Certificate details if Certificate authentication is used.
 /// </param>
 public PSIdentity(string authType, bool isAuthenticated, string userName, PSCertificateDetails cert)
 {
     AuthenticationType = authType;
     IsAuthenticated    = isAuthenticated;
     Name = userName;
     CertificateDetails = cert;
 }
Example #2
0
 public PSIdentity(string authType, bool isAuthenticated, string userName, PSCertificateDetails cert)
 {
     this.authenticationType = authType;
     this.isAuthenticated = isAuthenticated;
     this.userName = userName;
     this.certDetails = cert;
 }
Example #3
0
 public PSIdentity(string authType, bool isAuthenticated, string userName, PSCertificateDetails cert)
 {
     this.authenticationType = authType;
     this.isAuthenticated    = isAuthenticated;
     this.userName           = userName;
     this.certDetails        = cert;
 }
Example #4
0
        /// <summary>
        /// used to create PSPrincipal object from senderDetails struct.
        /// </summary>
        /// <param name="senderDetails"></param>
        /// <returns></returns>
        private PSSenderInfo GetPSSenderInfo(
            WSManNativeApi.WSManSenderDetails senderDetails)
        {
            // senderDetails will not be null.
            Dbg.Assert(null != senderDetails, "senderDetails cannot be null");

            // Construct PSIdentity
            PSCertificateDetails psCertDetails = null;
            // Construct Certificate Details
            if (null != senderDetails.certificateDetails)
            {
                psCertDetails = new PSCertificateDetails(
                    senderDetails.certificateDetails.subject,
                    senderDetails.certificateDetails.issuerName,
                    senderDetails.certificateDetails.issuerThumbprint);
            }

            // Construct PSPrincipal
            PSIdentity psIdentity = new PSIdentity(senderDetails.authenticationMechanism, true, senderDetails.senderName, psCertDetails);

            // For Virtual and RunAs accounts WSMan specifies the client token via an environment variable and
            // senderDetails.clientToken should not be used.
            IntPtr clientToken = GetRunAsClientToken();
            clientToken = (clientToken != IntPtr.Zero) ? clientToken : senderDetails.clientToken;
            WindowsIdentity windowsIdentity = null;
            if (clientToken != IntPtr.Zero)
            {
                try
                {
                    windowsIdentity = new WindowsIdentity(clientToken, senderDetails.authenticationMechanism);
                }
                // Suppress exceptions..So windowsIdentity = null in these cases
                catch (ArgumentException)
                {
                    // userToken is 0.
                    // -or-
                    // userToken is duplicated and invalid for impersonation.
                }
                catch (System.Security.SecurityException)
                {
                    // The caller does not have the correct permissions. 
                    // -or-
                    // A Win32 error occurred.
                }
            }

            PSPrincipal userPrincipal = new PSPrincipal(psIdentity, windowsIdentity);
            PSSenderInfo result = new PSSenderInfo(userPrincipal, senderDetails.httpUrl);
            return result;
        }
Example #5
0
 /// <summary>
 /// Constructor used to construct a PSIdentity object
 /// </summary>
 /// <param name="authType">
 /// Type of authentication used to authenticate this user.
 /// For a WSMan service authenticated user this will be one of the following:
 ///  WSMAN_DEFAULT_AUTHENTICATION
 ///  WSMAN_NO_AUTHENTICATION 
 ///  WSMAN_AUTH_DIGEST           
 ///  WSMAN_AUTH_NEGOTIATE 
 ///  WSMAN_AUTH_BASIC
 ///  WSMAN_AUTH_KERBEROS
 ///  WSMAN_AUTH_CLIENT_CERTIFICATE
 ///  WSMAN_AUTH_LIVEID
 /// </param>
 /// <param name="isAuthenticated">
 /// true if this user is authenticated.
 /// </param>
 /// <param name="userName">
 /// Name of the user
 /// </param>
 /// <param name="cert">
 /// Certificate details if Certificate authentication is used.
 /// </param>
 public PSIdentity(string authType, bool isAuthenticated, string userName, PSCertificateDetails cert)
 {
     AuthenticationType = authType;
     IsAuthenticated = isAuthenticated;
     Name = userName;
     CertificateDetails = cert;
 }