static public ClaimsPrincipal Convert( v1ClaimsPrincipal v1ClaimsPrincipal )
        {
            ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal();
            foreach ( v1ClaimsIdentity v1claimsIdentity in v1ClaimsPrincipal.Identities )
            {
                claimsPrincipal.AddIdentity( Convert( v1claimsIdentity ) );
            }

            return claimsPrincipal;
        }
        static public ClaimsPrincipal Convert(v1ClaimsPrincipal v1ClaimsPrincipal)
        {
            ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal();

            foreach (v1ClaimsIdentity v1claimsIdentity in v1ClaimsPrincipal.Identities)
            {
                claimsPrincipal.AddIdentity(Convert(v1claimsIdentity));
            }

            return(claimsPrincipal);
        }
Exemple #3
0
        public async Task <ActionResult> Index(LoginViewModel model) //Login
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            var result = await repository.login(model);

            if (result.resultCode == 200 && !User.Identity.IsAuthenticated)
            {
                SessionAuthenticationModule sam       = (SessionAuthenticationModule)this.HttpContext.ApplicationInstance.Modules["SessionAuthenticationModule"];
                IClaimsPrincipal            principal = new Microsoft.IdentityModel.Claims.ClaimsPrincipal(new GenericPrincipal(new GenericIdentity(model.Email), null));

                List <User> user = new List <User>();
                user.Add(new Models.User {
                    Email = "*****@*****.**", Date = DateTime.Now
                });
                user.Add(new Models.User {
                    Email = "*****@*****.**", Date = DateTime.Now
                });
                user.Add(new Models.User {
                    Email = "*****@*****.**", Date = DateTime.Now
                });
                user.Add(new Models.User {
                    Email = "*****@*****.**", Date = DateTime.Now
                });
                string dummy = JsonConvert.SerializeObject(user);
                principal.Identities[0].Claims.Add(new Microsoft.IdentityModel.Claims.Claim(Microsoft.IdentityModel.Claims.ClaimTypes.Email, model.Email));
                principal.Identities[0].Claims.Add(new Microsoft.IdentityModel.Claims.Claim(Microsoft.IdentityModel.Claims.ClaimTypes.UserData, dummy));
                principal.Identities[0].Claims.Add(new Microsoft.IdentityModel.Claims.Claim(Microsoft.IdentityModel.Claims.ClaimTypes.Role, "Admin"));

                principal.Identities[0].Claims.Add(new Microsoft.IdentityModel.Claims.Claim("custom", "freecodespot custom claims"));

                var token = sam.CreateSessionSecurityToken(principal, null, DateTime.Now, DateTime.Now.AddMinutes(20), false);
                sam.WriteSessionTokenToCookie(token);

                //FormsAuthentication.SetAuthCookie(model.Email, false);

                return(RedirectToAction("Index", "Home", result.Data)); //redirect to login form
            }
            else if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("", result.message);
            }

            return(View());
        }
Exemple #4
0
        public RequestInformation(ILDAPCPConfiguration currentConfiguration, RequestType currentRequestType, List <AttributeHelper> processedAttributes, string input, SPClaim incomingEntity, Uri context, string[] entityTypes, string hierarchyNodeID, int maxCount)
        {
            this.CurrentConfiguration = currentConfiguration;
            this.RequestType          = currentRequestType;
            this.OriginalInput        = input;
            this.IncomingEntity       = incomingEntity;
            this.Context         = context;
            this.EntityTypes     = entityTypes;
            this.HierarchyNodeID = hierarchyNodeID;
            this.MaxCount        = maxCount;

            HttpContext httpctx = HttpContext.Current;

            if (httpctx != null)
            {
                WIF3_5.ClaimsPrincipal cp = httpctx.User as WIF3_5.ClaimsPrincipal;
                // cp is typically null in central administration
                if (cp != null)
                {
                    this.UserInHttpContext = SPClaimProviderManager.Local.DecodeClaimFromFormsSuffix(cp.Identity.Name);
                }
            }

            if (currentRequestType == RequestType.Validation)
            {
                this.InitializeValidation(processedAttributes);
            }
            else if (currentRequestType == RequestType.Search)
            {
                this.InitializeSearch(processedAttributes);
            }
            else if (currentRequestType == RequestType.Augmentation)
            {
                this.InitializeAugmentation(processedAttributes);
            }
        }
Exemple #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Username"] != null)
        {
            // Session["Username"] = null;
        }
        if (!IsPostBack)
        {
            try
            {
                string LoginType = System.Configuration.ConfigurationManager.AppSettings["SSOLogin"].ToString();

                if (LoginType.ToLower() == "false")
                {
                    Div_UserLogin.Visible = true;
                    Div_SSOBody.Visible   = false;
                }
                else
                {
                    //SSO
                    Microsoft.IdentityModel.Claims.ClaimsPrincipal claimsPrincipal = Thread.CurrentPrincipal as Microsoft.IdentityModel.Claims.ClaimsPrincipal;
                    if (claimsPrincipal != null && claimsPrincipal.Identity.IsAuthenticated)
                    {
                        IClaimsIdentity claimsIdentity = claimsPrincipal.Identity as IClaimsIdentity;
                        if (claimsIdentity != null)
                        {
                            if (claimsIdentity.Claims.Count > 0)
                            {
                                lbl_PF.Text   = claimsIdentity.Claims[0].Value.Split('@')[0];
                                lbl_name.Text = claimsIdentity.Claims[5].Value;

                                if (strAdmin == "1")
                                {
                                    //Production Server
                                    lbl_code.Text   = "0" + claimsIdentity.Claims[17].Value;
                                    lbl_Mobile.Text = claimsIdentity.Claims[27].Value;
                                    lbl_Email.Text  = claimsIdentity.Claims[28].Value;
                                }
                                else
                                {
                                    //UAT Server
                                    lbl_code.Text   = "0" + claimsIdentity.Claims[11].Value;
                                    lbl_Mobile.Text = claimsIdentity.Claims[20].Value;
                                    lbl_Email.Text  = claimsIdentity.Claims[21].Value;
                                }

                                btn_login.Enabled = true;
                            }
                        }
                        else
                        {
                            btn_login.Enabled = false;
                            lbl_error.Visible = true;
                            lbl_error.Text    = "User claimsIdentity details not found";
                        }
                    }
                    else
                    {
                        string User = System.Configuration.ConfigurationManager.AppSettings["TestUser"].ToString();

                        if (User == "1")
                        {
                            Div_UserLogin.Visible = false;
                            Div_SSOBody.Visible   = true;
                            btn_login.Enabled     = false;
                            lbl_error.Visible     = true;
                            lbl_error.Text        = "User details not found";
                            lbl_PF.Text           = "LIP3";
                            lbl_name.Text         = "S";
                            lbl_code.Text         = "016516";
                            lbl_Mobile.Text       = "9999999993";
                            lbl_Email.Text        = "*****@*****.**";
                            btn_login.Enabled     = true;
                        }
                        else
                        {
                            lbl_error.Visible = true;
                            lbl_error.Text    = "User details not found";
                            lbl_PF.Text       = "LIP4";
                            lbl_name.Text     = "T";
                            lbl_code.Text     = "000024";
                            lbl_Mobile.Text   = "8888888888";
                            lbl_Email.Text    = "*****@*****.**";
                            btn_login.Enabled = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                btn_login.Enabled = false;
                lbl_error.Visible = true;
                lbl_error.Text    = "catch error : - " + ex.Message;
            }
        }
    }