private static bool ValidateUserByCallingLogin(string username, string password, bool rememberMe, string serviceUri,
                                                       bool useWFCService, ref CookieContainer cookies,
                                                       string connectionString, string connectionStringProvider)
        {
            if (useWFCService)
            {
                throw new NotImplementedException();

//                 CustomBinding binding = ProxyHelper.GetBinding();
//                 ChannelFactory<LoginService> channelFactory = new ChannelFactory<LoginService>(binding, new EndpointAddress(serviceUri)); //(@"http://localhost/AuthSvc/service.svc"));
//                 LoginService clientService = channelFactory.CreateChannel();
//                 using (new OperationContextScope((IContextChannel)clientService)) {
//                     ProxyHelper.AddCookiesToWCF(cookies, serviceUri, username, connectionString, connectionStringProvider);
//                     bool validated = clientService.Login(username, password, string.Empty, rememberMe);
//                     ProxyHelper.GetCookiesFromWCF(cookies, serviceUri, username, connectionString, connectionStringProvider);
//                     return validated;
//                 }
            }
            else
            {
                serviceUri = serviceUri + "/Login";
                string [] paramNames  = new string [] { "userName", "password", "createPersistentCookie" };
                object [] paramValues = new object [] { username, password, rememberMe };
                object    o           = ProxyHelper.CreateWebRequestAndGetResponse(serviceUri,
                                                                                   ref cookies,
                                                                                   username,
                                                                                   connectionString,
                                                                                   connectionStringProvider,
                                                                                   paramNames,
                                                                                   paramValues,
                                                                                   typeof(bool));
                return((o != null) && (o is bool) && ((bool)o) == true);
            }
        }
        private bool ValidateByCallingIsLoggedIn(string username, ref CookieContainer cookies)
        {
            if (_UsingWFCService)
            {
                throw new NotImplementedException();

//                 CustomBinding binding = ProxyHelper.GetBinding();
//                 ChannelFactory<LoginService> channelFactory = new ChannelFactory<LoginService>(binding, new EndpointAddress(GetServiceUri()));
//                 LoginService clientService = channelFactory.CreateChannel();
//                 using (new OperationContextScope((IContextChannel)clientService)) {
//                     ProxyHelper.AddCookiesToWCF(cookies, GetServiceUri(), username, _ConnectionString, _ConnectionStringProvider);
//                     bool validated = clientService.IsLoggedIn();
//                     ProxyHelper.GetCookiesFromWCF(cookies, GetServiceUri(), username, _ConnectionString, _ConnectionStringProvider);
//                     return validated;
//                 }
            }
            else
            {
                object o = ProxyHelper.CreateWebRequestAndGetResponse(GetServiceUri() + "/IsLoggedIn",
                                                                      ref cookies,
                                                                      username,
                                                                      _ConnectionString,
                                                                      _ConnectionStringProvider,
                                                                      null, null,
                                                                      typeof(bool));
                return((o != null) && (o is bool) && ((bool)o) == true);
            }
        }
        public static SettingsPropertyCollection GetPropertyMetadata(string serviceUri)
        {
            CookieContainer            cookies = null;
            IIdentity                  id      = Thread.CurrentPrincipal.Identity;
            SettingsPropertyCollection retColl = new SettingsPropertyCollection();


            if (id is ClientFormsIdentity)
            {
                cookies = ((ClientFormsIdentity)id).AuthenticationCookies;
            }

            if (serviceUri.EndsWith(".svc", StringComparison.OrdinalIgnoreCase))
            {
                throw new NotImplementedException();

//                 CustomBinding                    binding        = ProxyHelper.GetBinding();
//                 ChannelFactory<ProfileService>   channelFactory = new ChannelFactory<ProfileService>(binding, new EndpointAddress(serviceUri));
//                 ProfilePropertyMetadata[]        props          = null;
//                 ProfileService                   clientService  = channelFactory.CreateChannel();

//                 using (new OperationContextScope((IContextChannel)clientService)) {
//                     ProxyHelper.AddCookiesToWCF(cookies, serviceUri, id.Name, null, null);
//                     props = clientService.GetPropertiesMetadata();
//                     ProxyHelper.GetCookiesFromWCF(cookies, serviceUri, id.Name, null, null);
//                 }
//                 if (props == null)
//                     return retColl;

//                 for(int iter=0; iter<props.Length; iter++) {
//                     AddToColl(props[iter], retColl, id.IsAuthenticated);
//                 }
            }
            else
            {
                object o = ProxyHelper.CreateWebRequestAndGetResponse(serviceUri + "/GetPropertiesMetadata",
                                                                      ref cookies,
                                                                      id.Name,
                                                                      null,
                                                                      null,
                                                                      null,
                                                                      null,
                                                                      typeof(Collection <ProfilePropertyMetadata>));

                Collection <ProfilePropertyMetadata> props2 = (Collection <ProfilePropertyMetadata>)o;
                if (props2 != null)
                {
                    foreach (ProfilePropertyMetadata p in props2)
                    {
                        AddToColl(p, retColl, id.IsAuthenticated);
                    }
                }
            }
            return(retColl);
        }
        private Collection <string> SetPropertyValuesWebCore(SettingsPropertyValueCollection values, bool cacheIsMoreFresh)
        {
            Dictionary <string, object> propertyValues = new Dictionary <string, object>();
            Collection <string>         errorList      = null;

            foreach (SettingsPropertyValue value in values)
            {
                if (cacheIsMoreFresh || value.IsDirty)
                {
                    propertyValues.Add(value.Property.Name, value.PropertyValue);
                }
            }

            CookieContainer cookies = null;
            IIdentity       id      = Thread.CurrentPrincipal.Identity;

            if (id is ClientFormsIdentity)
            {
                cookies = ((ClientFormsIdentity)id).AuthenticationCookies;
            }


            if (_UsingWFCService)
            {
                throw new NotImplementedException();

//                 CustomBinding                    binding           = ProxyHelper.GetBinding();
//                 ChannelFactory<ProfileService>   channelFactory    = new ChannelFactory<ProfileService>(binding, new EndpointAddress(GetServiceUri()));
//                 ProfileService                   clientService     = channelFactory.CreateChannel();
//                 using (new OperationContextScope((IContextChannel)clientService)) {
//                     ProxyHelper.AddCookiesToWCF(cookies, GetServiceUri(), id.Name, GetConnectionString(), _ConnectionStringProvider);
//                     errorList = clientService.SetPropertiesForCurrentUser(propertyValues, id.IsAuthenticated && (id is ClientFormsIdentity));
//                     ProxyHelper.GetCookiesFromWCF(cookies, GetServiceUri(), id.Name, GetConnectionString(), _ConnectionStringProvider);
//                 }
            }
            else
            {
                // Collection<string> SetPropertiesForCurrentUser(IDictionary<string, object> values, bool authenticatedUserOnly)
                string [] paramNames  = new string [] { "values", "authenticatedUserOnly" };
                object [] paramValues = new object [] { propertyValues, id.IsAuthenticated&& (id is ClientFormsIdentity) };

                object o = ProxyHelper.CreateWebRequestAndGetResponse(GetServiceUri() + "/SetPropertiesForCurrentUser",
                                                                      ref cookies,
                                                                      id.Name,
                                                                      _ConnectionString,
                                                                      _ConnectionStringProvider,
                                                                      paramNames,
                                                                      paramValues,
                                                                      typeof(Collection <string>));
                errorList = (Collection <string>)o;
            }
            SetIsCacheMoreFresh(false);
            return(errorList);
        }
Example #5
0
        private void GetRolesForUserCore(IIdentity identity)
        {
            // (new PermissionSet(PermissionState.Unrestricted)).Assert(); //

            CookieContainer cookies = null;

            if (identity is ClientFormsIdentity)
            {
                cookies = ((ClientFormsIdentity)identity).AuthenticationCookies;
            }

            if (_UsingWFCService)
            {
                throw new NotImplementedException();

//                 CustomBinding binding = ProxyHelper.GetBinding();
//                 ChannelFactory<RolesService> channelFactory = new ChannelFactory<RolesService>(binding, new EndpointAddress(GetServiceUri())); //(@"http://localhost/AuthSvc/service.svc"));
//                 RolesService clientService = channelFactory.CreateChannel();
//                 using (new OperationContextScope((IContextChannel)clientService)) {
//                     ProxyHelper.AddCookiesToWCF(cookies, GetServiceUri(), _CurrentUser, _ConnectionString, _ConnectionStringProvider);
//                     _Roles = clientService.GetRolesForCurrentUser();
//                     if (_Roles == null)
//                         _Roles = new string[0];
//                     ProxyHelper.GetCookiesFromWCF(cookies, GetServiceUri(), _CurrentUser, _ConnectionString, _ConnectionStringProvider);
//                 }
            }
            else
            {
                object o = ProxyHelper.CreateWebRequestAndGetResponse(GetServiceUri() + "/GetRolesForCurrentUser",
                                                                      ref cookies,
                                                                      identity.Name,
                                                                      _ConnectionString,
                                                                      _ConnectionStringProvider,
                                                                      null,
                                                                      null,
                                                                      typeof(string []));
                if (o != null)
                {
                    _Roles = (string [])o;
                }
                else
                {
                    _Roles = new string[0];
                }
            }
            _CacheExpiryDate = DateTime.UtcNow.AddMinutes(_CacheTimeout);
        }
        public void Logout()
        {
            IPrincipal p = Thread.CurrentPrincipal;

            if (p == null || !(p.Identity is ClientFormsIdentity))
            {
                return;
            }
            lock (this) {
                if (!ConnectivityStatus.IsOffline)
                {
                    CookieContainer cookies = ((ClientFormsIdentity)p.Identity).AuthenticationCookies;

                    if (_UsingWFCService)
                    {
                        throw new NotImplementedException();

//                         CustomBinding binding = ProxyHelper.GetBinding();
//                         ChannelFactory<LoginService> channelFactory = new ChannelFactory<LoginService>(binding, new EndpointAddress(GetServiceUri()));
//                         LoginService clientService = channelFactory.CreateChannel();
//                         using (new OperationContextScope((IContextChannel)clientService)) {
//                             ProxyHelper.AddCookiesToWCF(cookies, GetServiceUri(), p.Identity.Name, _ConnectionString, _ConnectionStringProvider);
//                             clientService.Logout();
//                             ProxyHelper.GetCookiesFromWCF(cookies, GetServiceUri(), p.Identity.Name, _ConnectionString, _ConnectionStringProvider);
//                         }
                    }
                    else
                    {
                        ProxyHelper.CreateWebRequestAndGetResponse(GetServiceUri() + "/Logout",
                                                                   ref cookies,
                                                                   p.Identity.Name,
                                                                   _ConnectionString,
                                                                   _ConnectionStringProvider,
                                                                   null,
                                                                   null,
                                                                   null);
                    }
                }
                SqlHelper.DeleteAllCookies(p.Identity.Name, _ConnectionString, _ConnectionStringProvider);
                Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
            }
            StoreLastUserNameInOffileStore(null);
            if (UserValidated != null)
            {
                UserValidated(this, new UserValidatedEventArgs(""));
            }
        }
        private void GetPropertyValuesFromWebCore(bool bubbleExceptionFromSvc)
        {
            string []       propertyNames = new string[_Properties.Count];
            int             iter          = 0;
            CookieContainer cookies       = null;
            IIdentity       id            = Thread.CurrentPrincipal.Identity;

            foreach (SettingsProperty setting in _Properties)
            {
                propertyNames[iter++] = setting.Name;
            }

            if (id is ClientFormsIdentity)
            {
                cookies = ((ClientFormsIdentity)id).AuthenticationCookies;
            }

            if (_UsingWFCService)
            {
                throw new NotImplementedException();

//                 CustomBinding                    binding        = ProxyHelper.GetBinding();
//                 ChannelFactory<ProfileService>   channelFactory = new ChannelFactory<ProfileService>(binding, new EndpointAddress(GetServiceUri()));
//                 ProfileService                   clientService  = channelFactory.CreateChannel();
//                 Dictionary<string, object>       propertyValues = null;


//                 using (new OperationContextScope((IContextChannel)clientService)) {
//                     ProxyHelper.AddCookiesToWCF(cookies, GetServiceUri(), id.Name, GetConnectionString(), _ConnectionStringProvider);
//                     propertyValues = clientService.GetPropertiesForCurrentUser(propertyNames, id.IsAuthenticated && (id is ClientFormsIdentity));
//                     ProxyHelper.GetCookiesFromWCF(cookies, GetServiceUri(), id.Name, GetConnectionString(), _ConnectionStringProvider);
//                 }

//                 for(iter = 0; iter<propertyNames.Length; iter++) {
//                     string name = propertyNames[iter];
//                     if (!propertyValues.ContainsKey(name))
//                         continue;
//                     SettingsProperty setting = _Properties[name];
//                     if (setting == null)
//                         continue; // Bad -- why wasn't it found?
//                     bool mustAdd = false;
//                     SettingsPropertyValue value = _PropertyValues[setting.Name];
//                     if (value == null) {
//                         value = new SettingsPropertyValue(setting);
//                         mustAdd = true;
//                     }

//                     //if ((value.SerializedValue is string) && ((string)value.SerializedValue == "(null)")) {
//                     value.PropertyValue = propertyValues[name];
//                     value.Deserialized = true;
//                     //                 } else if (setting.SerializeAs == SettingsSerializeAs.Binary)
//                     //                     value.SerializedValue = Convert.FromBase64String(propertyValues[iter]);
//                     //                 else
//                     //                     value.SerializedValue = propertyValues[iter];
//                     //                 value.Deserialized = false;
//                     value.IsDirty = false;
//                     if (mustAdd)
//                         _PropertyValues.Add(value);
//                 }
            }
            else
            {
                string [] paramNames  = new string [] { "properties", "authenticatedUserOnly" };
                object [] paramValues = new object [] { propertyNames, id.IsAuthenticated&& (id is ClientFormsIdentity) };
                object    obj         = null;
                try {
                    obj = ProxyHelper.CreateWebRequestAndGetResponse(
                        GetServiceUri() + "/GetPropertiesForCurrentUser",
                        ref cookies,
                        id.Name,
                        _ConnectionString,
                        _ConnectionStringProvider,
                        paramNames,
                        paramValues,
                        typeof(Dictionary <string, object>));
                } catch {
                    if (bubbleExceptionFromSvc)
                    {
                        throw;
                    }
                }

                if (obj != null)
                {
                    Dictionary <string, object> ret = (Dictionary <string, object>)obj;

                    foreach (KeyValuePair <string, object> de in ret)
                    {
                        SettingsProperty setting = _Properties[(string)de.Key];
                        if (setting == null)
                        {
                            continue; // Bad -- why wasn't it found?
                        }
                        bool mustAdd = false;
                        SettingsPropertyValue value = _PropertyValues[setting.Name];
                        if (value == null)
                        {
                            value   = new SettingsPropertyValue(setting);
                            mustAdd = true;
                        }

                        if (de.Value != null && !setting.PropertyType.IsAssignableFrom(de.Value.GetType()))
                        {
                            object convertedValue = null;
                            if (!ObjectConverter.TryConvertObjectToType(de.Value,
                                                                        setting.PropertyType,
                                                                        new JavaScriptSerializer(),
                                                                        out convertedValue))
                            {
                                // Failure to convert!
                                continue;
                            }
                            value.PropertyValue = convertedValue;
                        }
                        else
                        {
                            value.PropertyValue = de.Value;
                        }

                        value.Deserialized = true;
                        value.IsDirty      = false;
                        if (mustAdd)
                        {
                            _PropertyValues.Add(value);
                        }
                    }
                }
            }
        }