Ejemplo n.º 1
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            //var userManager = context.OwinContext.GetUserManager<ApplicationUserManager>();
            //var user = await userManager.FindByEmailAsync(context.UserName);
            //if (user == null)
            //{
            //    context.SetError("invalid_grant", "The user name or password is incorrect.");
            //    return;
            //}
            //else
            //{
            //    var result = userManager.PasswordHasher.VerifyHashedPassword(user.PasswordHash, context.Password);
            //    if (!(result == PasswordVerificationResult.Success))
            //    {
            //        context.SetError("invalid_grant", "The user name or password is incorrect.");
            //        return;
            //    }
            //}
            //if (user == null)
            //{
            //    context.SetError("invalid_grant", "The user name or password is incorrect.");
            //    return;
            //}
            //ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager);
            //ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager);
            //AuthenticationProperties properties = CreateProperties(user.UserName);
            //AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
            //context.Validated(ticket);
            //context.Request.Context.Authentication.SignIn(cookiesIdentity);


            var    provider = Membership.Provider;
            string name     = provider.ApplicationName; // Get the application name here

            if (Membership.ValidateUser(context.UserName, context.Password))
            {
                var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>();

                var             mmuser = Membership.GetUser(context.UserName);
                List <Claim>    claims = GetClaimsByUser(mmuser);
                ApplicationUser user   = new ApplicationUser();
                user.UserName = mmuser.UserName;
                user.Id       = mmuser.ProviderUserKey.ToString();
                if (user == null)
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect.");
                    return;
                }
                var claimsIdentity = new DemoIdentity(claims,
                                                      DefaultAuthenticationTypes.ApplicationCookie);
                AuthenticationProperties properties = CreateProperties(user.UserName);
                AuthenticationTicket     ticket     = new AuthenticationTicket(claimsIdentity, properties);
                context.Validated(ticket);
            }
            else
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.");
                return;
            }
        }
Ejemplo n.º 2
0
        private void SignIn(List <Claim> claims, OAuthAuthorizationEndpointResponseContext HttpContext)//Mind!!! This is System.Security.Claims not WIF claims
        {
            var claimsIdentity = new DemoIdentity(claims,
                                                  DefaultAuthenticationTypes.ApplicationCookie);

            LoggingHelper.AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
            LoggingHelper.AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                IsPersistent = false
            }, claimsIdentity);
        }
        private void SignIn(List <Claim> claims)//Mind!!! This is System.Security.Claims not WIF claims
        {
            var claimsIdentity = new DemoIdentity(claims,
                                                  DefaultAuthenticationTypes.ApplicationCookie);

            //This uses OWIN authentication

            LoggingHelper.AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
            LoggingHelper.AuthenticationManager.SignIn(new AuthenticationProperties()
            {
                IsPersistent = false
            }, claimsIdentity);

            HttpContext.User = new DemoPrincipal(LoggingHelper.AuthenticationManager.AuthenticationResponseGrant.Principal);
        }
Ejemplo n.º 4
0
        public TestsFile ParseTestsFile(string testsFile)
        {
            TestsFile result = new TestsFile();
            using (var fs = File.OpenRead(testsFile))
            {
                using (var br = new BinaryReader(fs))
                {
                    TestsFileHeader header = new TestsFileHeader();
                    header.RecSizeLabel = ConvertToString(br.ReadBytes(8));
                    header.RecSize = br.ReadInt32();
                    header.Unknown = br.ReadInt32();
                    result.Header = header;

                    result.Tests = new List<TestProperties>();
                    while (fs.Length > fs.Position)
                    {
                        var test = new TestProperties();
                        using (var ms = new MemoryStream(br.ReadBytes(header.RecSize)))
                        {
                            using (var br1 = new BinaryReader(ms))
                            {
                                // 读取TestIdentity
                                var identity = new TestIdentity();
                                // identity.Name = ConvertToString(br1.ReadBytes(21));
                                identity.Name = ConvertToGBString(br1.ReadBytes(21));
                                identity.Instrument = ConvertToString(br1.ReadBytes(11));
                                identity.GelSize = br1.ReadInt16();
                                identity.StainType = br1.ReadInt16();
                                test.Identity = identity;

                                // 
                                test.bIFE = br1.ReadBoolean();
                                test.Units = ConvertToString(br1.ReadBytes(11));
                                test.TotalUnits = ConvertToString(br1.ReadBytes(11));
                                test.AutoEditOptions = br1.ReadByte();
                                test.Precision = br1.ReadInt16();
                                test.UnitsFullScale = br1.ReadInt16();
                                test.ImageContrast = br1.ReadInt16();

                                // 读取DemoIdentity
                                var demos = new List<DemoIdentity>();
                                for (int i = 0; i < 10; i++)
                                {
                                    DemoIdentity d = new DemoIdentity();
                                    d.Label = ConvertToString(br1.ReadBytes(21));
                                    d.Type = br1.ReadByte();
                                    d.ASTMField = br1.ReadByte();
                                    demos.Add(d);
                                }
                                test.Demo = demos;

                                // 读取RangeSet
                                var rs = new List<Range>();
                                for (int i = 0; i < 9; i++)
                                {
                                    Range r = new Range();
                                    r.Sex = ConvertToString(br1.ReadBytes(2));
                                    r.Type = br1.ReadByte();
                                    r.AgeLow = br1.ReadByte();
                                    r.AgeLowUnits = br1.ReadByte();
                                    r.AgeHigh = br1.ReadByte();
                                    r.AgeHighUnits = br1.ReadByte();
                                    rs.Add(r);
                                }
                                test.RangeSet = rs;

                                br1.ReadByte();

                                // 读取Ratio
                                var ratios = new List<Ratio>();
                                for (int i = 0; i < 2; i++)
                                {
                                    Ratio r = new Ratio();
                                    r.Label = Encoding.ASCII.GetString(br1.ReadBytes(12));
                                    r.dRange = new List<KeyValuePair<double, double>>();
                                    for (int j = 0; j < 9; j++)
                                    {
                                        KeyValuePair<double, double> t = new KeyValuePair<double, double>(br1.ReadDouble(), br1.ReadDouble());
                                        r.dRange.Add(t);
                                    }
                                    ratios.Add(r);
                                }
                                test.Ratio = ratios;

                                // 读取Fraction
                                var fractions = new List<Fraction>();
                                for (int i = 0; i < 10 + 1; i++)
                                {
                                    Fraction f = new Fraction();
                                    f.Label = ConvertToString(br1.ReadBytes(13));
                                    f.Ratio = new List<byte>();
                                    f.Ratio.Add(br1.ReadByte());
                                    f.Ratio.Add(br1.ReadByte());
                                    f.bIstd = br1.ReadBoolean();
                                    f.dPctRange = new List<KeyValuePair<double, double>>();
                                    for (int j = 0; j < 9; j++)
                                    {
                                        KeyValuePair<double, double> t = new KeyValuePair<double, double>(br1.ReadDouble(), br1.ReadDouble());
                                        f.dPctRange.Add(t);
                                    }
                                    f.dUnitsRange = new List<KeyValuePair<double, double>>();
                                    for (int j = 0; j < 9; j++)
                                    {
                                        KeyValuePair<double, double> t = new KeyValuePair<double, double>(br1.ReadDouble(), br1.ReadDouble());
                                        f.dUnitsRange.Add(t);
                                    }
                                    fractions.Add(f);
                                }
                                test.Fraction = fractions;

                                // 不读取了
                                //test.RstrctBandLabel = ConvertToString(br1.ReadBytes(18));
                                //test.Reserved = Encoding.ASCII.GetString(br1.ReadBytes(2));
                                //test.Options = br1.ReadByte();
                            }
                        }
                        result.Tests.Add(test);
                    }
                }
            }
            return result;
        }