示例#1
0
        /// <summary>
        /// Will retrieve the USERNAME from ...
        /// </summary>
        /// <returns></returns>
        public static string GetUsername()
        {
            //TODO: get App user login from somewhere TBD if call is from a client,
            // and get user from security context of service if call is from service
            //... use CurrentUserHelper here?
            string strUser;
            //when the request enters the WCF ServiceHost HttpContext gets nulled and all impersonation is undone.
            //WCF does take care for OperationContext which Provides access to the execution context
            //to make less changes to existing WCFExtension
            //this method will rely on OperationContext or ServiceSecurityContext
            //if security mode = None, i.e. SecurityContext = null - WindowsIdentity
            CurrentUserHelper userHelper = null;

            if (OperationContext.Current != null)
            {
                userHelper = new CurrentUserHelper(OperationContext.Current.ServiceSecurityContext);
            }
            else if (ServiceSecurityContext.Current != null)
            {
                userHelper = new CurrentUserHelper(ServiceSecurityContext.Current);
            }
            else
            {
                userHelper = new CurrentUserHelper();
            }

            strUser = userHelper.ToString();

            return(strUser);
        }
示例#2
0
        public static void SetupThreadActiveProperty(ServiceSecurityContext Context)
        {
            //The ServiceSecurityContext contains the UserName at this point so an active property is not required
            //the property can be set directly
            //Setup Active Properties
            string Username = new CurrentUserHelper(Context).ToString();

            log4net.LogicalThreadContext.Properties["username"] = Username;
        }