private PSSenderInfo(SerializationInfo info, StreamingContext context) { if (info != null) { string source = null; try { source = info.GetValue("CliXml", typeof(string)) as string; } catch (Exception) { return; } if (source != null) { try { PSSenderInfo info2 = DeserializingTypeConverter.RehydratePSSenderInfo(PSObject.AsPSObject(PSSerializer.Deserialize(source))); this.userPrinicpal = info2.userPrinicpal; this.clientTimeZone = info2.ClientTimeZone; this.connectionString = info2.connectionString; this.applicationArguments = info2.applicationArguments; } catch (Exception) { return; } } } }
private OutOfProcessServerSessionTransportManager CreateSessionTransportManager() { WindowsIdentity current = WindowsIdentity.GetCurrent(); PSPrincipal userPrincipal = new PSPrincipal(new PSIdentity("", true, current.Name, null), current); PSSenderInfo senderInfo = new PSSenderInfo(userPrincipal, "http://localhost"); OutOfProcessServerSessionTransportManager transportManager = new OutOfProcessServerSessionTransportManager(this.originalStdOut); ServerRemoteSession.CreateServerRemoteSession(senderInfo, this._initialCommand, transportManager); return transportManager; }
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; }
public PSSenderInfo(PSPrincipal userPrincipal, string httpUrl) { UserInfo = userPrincipal; ConnectionString = httpUrl; }
/// <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; }
/// <summary> /// Gets collection of cmdlets for a user /// </summary> /// <param name="userInfo">User information</param> /// <returns>Collection of cmdlet names </returns> public List<string> GetCmdlets(PSPrincipal userInfo) { RbacGroup group = this.FindGroup(userInfo); return new List<string>(group.Cmdlets); }
/// <summary> /// Finds group for a PSPrincipal /// </summary> /// <param name="principal">PSPrincipal instance</param> /// <returns>Group associated with the identity</returns> private RbacGroup FindGroup(PSPrincipal principal) { if (principal == null) { throw new ArgumentNullException("principal"); } if (principal.Identity == null) { throw new ArgumentException("Null identity passed"); } if (principal.Identity.IsAuthenticated == false) { throw new UnauthorizedAccessException(); } PSIdentity powerShellIdentity = principal.Identity; GenericIdentity identity = new GenericIdentity(powerShellIdentity.Name, powerShellIdentity.AuthenticationType); RbacUser.RbacUserInfo userInfo = new RbacUser.RbacUserInfo(identity, powerShellIdentity.CertificateDetails); RbacUser user = this.Users.Find(item => item.UserInfo.Equals(userInfo)); if (user == null) { throw new ArgumentException("User not found: name=" + userInfo.Name + ", authentication=" + userInfo.AuthenticationType); } RbacGroup group = this.Groups.Find(item => item.Name == user.Group.Name); if (group == null) { throw new ArgumentException("group not found = " + user.Group.Name); } return group; }
/// <summary> /// Gets collection of modules for a user /// </summary> /// <param name="userInfo">User information </param> /// <returns>Collection of module names</returns> public List<string> GetModules(PSPrincipal userInfo) { RbacGroup group = this.FindGroup(userInfo); return new List<string>(group.Modules); }
public PSSenderInfo(PSPrincipal userPrincipal, string httpUrl) { this.userPrinicpal = userPrincipal; this.connectionString = httpUrl; }