Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var result = Request["result"];

            if (result.Length % 4 == 0)
            {
                result = SignHandler.Base64Decode(result);
            }
            if ("ok" == result.ToLower())
            {
                try
                {
                    String friendlyName = ConfigurationManager.AppSettings.Get("logonto");

                    if (friendlyName == null || "".Equals(friendlyName.Trim()))
                    {
                        throw new ConfigurationException("Fejl: Logonto / friendlyname mangler, eller er tom i konfigurationen");
                    }

                    string signature = SignHandler.Base64Decode(Request["signature"]);
                    CertificateAndStatus certificateAndStatus = LogonHandler.ValidateAndExtractCertificateAndStatus(signature, Challenge(), friendlyName);
                    if (certificateAndStatus.Certificate is PocesCertificate)
                    {
                        CertificateStatus status = certificateAndStatus.CertificateStatus;
                        if (status == CertificateStatus.Valid)
                        {
                            Session.Add(KeyPid, ((PocesCertificate)certificateAndStatus.Certificate).Pid);
                            if (Session[Global.CurrentUser] == null)
                            {
                                var randomUserName = ChallengeGenerator.GenerateChallenge();
                                Session.Add(Global.CurrentUser, randomUserName);
                            }

                            if (!Roles.IsUserInRole((string)Session[Global.CurrentUser], "poces"))
                            {
                                Roles.AddUserToRole((string)Session[Global.CurrentUser], "poces");
                            }
                            FormsAuthentication.RedirectFromLoginPage((string)Session[Global.CurrentUser], false);
                        }
                        else
                        {
                            Session.Add("errorText", "Certifikatet er " + ErrorHandler.GetCertificateStatusText(status));
                        }
                    }
                    else
                    {
                        Session.Add("notPoces", true);
                    }
                }
                catch (NonOcesCertificateException)
                {
                    Session.Add("errorText", "Ikke et OCES-certifikat");
                }
                catch (Exception ex)
                {
                    Session.Add("errorText", "Ukendt server-fejl: " + ex.Message);
                }
            }
            else
            {
                Session.Add("errorText", ErrorHandler.GetErrorText(result));
            }
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var result = Request["result"];

            if (result.Length % 4 == 0)
            {
                result = SignHandler.Base64Decode(result);
            }
            if ("ok" == result.ToLower())
            {
                try
                {
                    String logonto = ConfigurationManager.AppSettings["logonto"];
                    if (logonto == null || "".Equals(logonto.Trim()))
                    {
                        throw new ConfigurationErrorsException("Error - logonto parameter from configuration is missing or empty");
                    }
                    string signature = SignHandler.Base64Decode(Request["signature"]);
                    CertificateAndStatus certificateAndStatus = LogonHandler.ValidateAndExtractCertificateAndStatus(signature, Challenge(), logonto);
                    if (certificateAndStatus.Certificate is PocesCertificate || certificateAndStatus.Certificate is MocesCertificate)
                    {
                        CertificateStatus status = certificateAndStatus.CertificateStatus;
                        if (status == CertificateStatus.Valid)
                        {
                            SetAttributesForMocesOrPoces(certificateAndStatus.Certificate);

                            if (Session[Global.CurrentUser] == null)
                            {
                                var randomUserName = ChallengeGenerator.GenerateChallenge();
                                Session.Add(Global.CurrentUser, randomUserName);
                            }
                            if (!Roles.IsUserInRole((string)Session[Global.CurrentUser], "nemid"))
                            {
                                Roles.AddUserToRole((string)Session[Global.CurrentUser], "nemid");
                            }
                            FormsAuthentication.RedirectFromLoginPage((string)Session[Global.CurrentUser], false);
                        }
                        else
                        {
                            Session.Add("errorText", "Certifikatet er " + ErrorHandler.GetCertificateStatusText(status));
                        }
                    }
                    else
                    {
                        Session.Add("notPocesOrMoces", true);
                    }
                }
                catch (NonOcesCertificateException)
                {
                    Session.Add("errorText", "Ikke et OCES-certifikat");
                }
                catch (Exception)
                {
                    Session.Add("errorText", "Ukendt server-fejl");
                }
            }
            else
            {
                Session.Add("errorText", ErrorHandler.GetErrorText(result));
            }
        }