public Guid CreateSession(string connection, string username, string password, int authMechanism, int protocolVersion) { Guid sessionId = Guid.NewGuid (); var identity = new PSIdentity ("", true, username, null); var principal = new PSPrincipal (identity, WindowsIdentity.GetCurrent ()); var sender = new PSSenderInfo (principal, connection); var session = ServerRemoteSession.CreateServerRemoteSession (sender, null, new WSManServerSessionTransportManager()); lock (_lock) { _sessions.Add (sessionId, session); } return sessionId; }
public Guid CreateSession () { var username = System.Threading.Thread.CurrentPrincipal.Identity.Name; string connection = OperationContext.Current.Host.Description.Endpoints[0].Address.Uri.ToString (); var identity = new PSIdentity ("", true, username, null); var principal = new PSPrincipal (identity, WindowsIdentity.GetCurrent ()); var sender = new PSSenderInfo (principal, connection); var session = ServerRemoteSession.CreateServerRemoteSession (sender, null, sessionTransportManager); lock (_lock) { _sessions.Add (session.InstanceId, session); } return session.InstanceId; }
/// <summary> /// Constructs PSPrincipal using PSIdentity and a WindowsIdentity /// </summary> /// <param name="identity"> /// An instance of PSIdentity /// </param> /// <param name="windowsIdentity"> /// An instance of WindowsIdentity, if psIdentity represents a windows user. This can be /// null. /// </param> public PSPrincipal(PSIdentity identity, WindowsIdentity windowsIdentity) { Identity = identity; WindowsIdentity = windowsIdentity; }
/// <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; }
public PSPrincipal(PSIdentity identity, System.Security.Principal.WindowsIdentity windowsIdentity) { this.psIdentity = identity; this.windowsIdentity = windowsIdentity; }
internal PSPrincipal(PSIdentity psIdentity, WindowsIdentity windowsIdentity) { this.psIdentity = psIdentity; this.windowsIdentity = windowsIdentity; }