internal static PSSenderInfo RehydratePSSenderInfo(PSObject pso) { PSObject propertyValue = GetPropertyValue <PSObject>(GetPropertyValue <PSObject>(pso, "UserInfo"), "Identity"); PSObject obj4 = GetPropertyValue <PSObject>(propertyValue, "CertificateDetails"); PSCertificateDetails cert = (obj4 == null) ? null : new PSCertificateDetails(GetPropertyValue <string>(obj4, "Subject"), GetPropertyValue <string>(obj4, "IssuerName"), GetPropertyValue <string>(obj4, "IssuerThumbprint")); PSIdentity identity = new PSIdentity(GetPropertyValue <string>(propertyValue, "AuthenticationType"), GetPropertyValue <bool>(propertyValue, "IsAuthenticated"), GetPropertyValue <string>(propertyValue, "Name"), cert); return(new PSSenderInfo(new PSPrincipal(identity, WindowsIdentity.GetCurrent()), GetPropertyValue <string>(pso, "ConnectionString")) { ClientTimeZone = TimeZone.CurrentTimeZone, ApplicationArguments = GetPropertyValue <PSPrimitiveDictionary>(pso, "ApplicationArguments") }); }
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 InitialSessionState Create(UserContext userContext, string membershipId) { InitialSessionState initialSessionState; using (OperationTracerWithTimeout operationTracerWithTimeout = new OperationTracerWithTimeout(new Action <string>(TraceHelper.Current.PSSessionCallStart), new Action <string>(TraceHelper.Current.PSSessionCallEnd), "InitialSessionState", new Action <string>(TraceHelper.Current.PSSessionMethodExceededTimeLimit), 30)) { PSCertificateDetails pSCertificateDetail = null; if (userContext.ClientCertificate != null) { pSCertificateDetail = new PSCertificateDetails(userContext.ClientCertificate.Subject, userContext.ClientCertificate.Issuer, userContext.ClientCertificate.Thumbprint); } PSIdentity pSIdentity = new PSIdentity(userContext.AuthenticationType, userContext.IsAuthenticated, userContext.Name, pSCertificateDetail); PSPrincipal pSPrincipal = new PSPrincipal(pSIdentity, userContext.GetIdentity() as WindowsIdentity); PSSenderInfo pSSenderInfo = new PSSenderInfo(pSPrincipal, DataServiceController.Current.GetCurrentResourceUri().ToString()); try { InitialSessionState initialSessionState1 = this.sessionConfiguration.GetInitialSessionState(pSSenderInfo); if (initialSessionState1 != null) { TraceHelper.Current.GetInitialSessionStateRequestSucceeded(userContext.Name); initialSessionState1.Trace(); initialSessionState = initialSessionState1; } else { object[] objArray = new object[2]; objArray[0] = "PSSessionState.GetInitialSessionState"; objArray[1] = "null"; throw new InvalidOperationException(ExceptionHelpers.GetExceptionMessage(Resources.MethodReturnedInvalidOutput, objArray)); } } catch (Exception exception1) { Exception exception = exception1; TraceHelper.Current.GetInitialSessionStateRequestFailed(userContext.Name, exception.Message); if (!exception.IsSevereException()) { throw new CustomModuleInvocationFailedException(this.sessionConfiguration.GetType().AssemblyQualifiedName, "GetInitialState", exception); } else { throw; } } } return(initialSessionState); }
/// <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); }