Ejemplo n.º 1
0
        private void CheckForNewServices(DbBase ctx, String configPath)
        {
            
            string[] confFiles = Directory.GetFiles(configPath, "*.conf");

            foreach (string file in confFiles)
            {

                try
                {
                    CASPluginConfig cfg = new CASPluginConfig();
                    try
                    {
                        cfg.LoadFromXML(new FileInfo(file));
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Error parsing config file '" + file + "'", ex);
                    }

                    
                    Uri svc = CASPluginService.Normalize(cfg.Service);

                    //Verifica se o contexto é novo
                    if (ctx.ExecuteScalar<Int64>("select count(*) from [CAS_Context] where [Name] = '" + cfg.Context + "'") == 0)
                    {
                        //Adiciona
                        ctx.ExecuteNonQuery("INSERT INTO [CAS_Context] ([Name],[Host]) VALUES ('" + cfg.Context + "','" + Environment.MachineName + "');");
                    }


                    //Verifica se o serviço é novo
                    if (ctx.ExecuteScalar<Int64>("select count(*) from [CAS_Service] where [Uri] = '" + svc.AbsoluteUri + "'") == 0)
                    {

                        //Adiciona o serviço
                        ctx.ExecuteNonQuery("INSERT INTO [CAS_Service] ([Context_Name],[Uri],[Plugin_Assembly],[Permit_Password_Recover],[External_Password_Recover],[Password_RecoverUri],[Permit_Change_Password],[Admin]) VALUES ('" + cfg.Context + "','" + svc.AbsoluteUri + "','" + cfg.PluginAssembly + "'," + (cfg.PermitPasswordRecover ? 1 : 0) + "," + (cfg.ExternalPasswordRecover ? 1 : 0) + ",'" + cfg.PasswordRecoverUri + "'," + (cfg.PermitChangePassword ? 1 : 0) + ",'" + cfg.Admin + "');");
                        
                    }
                    else
                    {
                        //Atualiza o serviço
                        ctx.ExecuteNonQuery("update [CAS_Service] set [Context_Name] = '" + cfg.Context + "', [Plugin_Assembly] = '" + cfg.PluginAssembly + "',[Permit_Password_Recover] = " + (cfg.PermitPasswordRecover ? 1 : 0) + ",[External_Password_Recover] = " + (cfg.ExternalPasswordRecover ? 1 : 0) + ",[Password_RecoverUri] = '" + cfg.PasswordRecoverUri + "',[Permit_Change_Password] = " + (cfg.PermitChangePassword ? 1 : 0) + ",[Admin] = '" + cfg.Admin + "' where [Uri] = '" + svc.AbsoluteUri + "'");

                        //Apaga as propriedades
                        ctx.ExecuteNonQuery("delete from [CAS_Service_Attributes] where [Service_Uri] = '" + svc.AbsoluteUri + "'");
                    }

                    //Adiciona as propriedades
                    foreach(String key in cfg.Attributes.Keys)
                        ctx.ExecuteNonQuery("INSERT INTO [CAS_Service_Attributes] ([Service_Uri],[Key],[Value]) VALUES ('" + svc.AbsoluteUri + "','" + key + "','" + (cfg.Attributes[key] is DateTime ? ((DateTime)cfg.Attributes[key]).ToString("o") : cfg.Attributes[key].ToString()) + "');");


                }
                catch(Exception ex) {
                    throw ex;
                }
            }

        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String html  = "";
            String error = "";

            html += "<div id=\"recover_container\"><form id=\"serviceRecover\" name=\"serviceRecover\" method=\"post\"><div class=\"login_form\">";

            Uri svc = null;

            try
            {
                svc = new Uri(Request.QueryString["service"]);
            }
            catch { }

            using (DbBase db = DbBase.InstanceFromConfig(ConfigurationManager.ConnectionStrings["CASDatabase"]))
            {
                CASConnectorBase connector = CASUtils.GetService(db, this, svc);

                if ((connector == null) || (connector is EmptyPlugin))
                {
                    //Serviço não informado ou não encontrado
                    html += "    <ul>";
                    html += "        <li><div class=\"error-box\">" + MessageResource.GetMessage("service_invalid_uri") + "</div>";
                    html += "    </ul>";
                }
                else if ((connector.State != null) && (connector.State is CASPluginService) && !(((CASPluginService)connector.State).Config.PermitPasswordRecover))
                {
                    CASPluginService p = (CASPluginService)connector.State;

                    //Serviço não informado ou não encontrado
                    html += "    <ul>";
                    html += "        <li><div class=\"error-box\">" + MessageResource.GetMessage("service_not_permit_recover_pwd") + (!String.IsNullOrEmpty(p.Config.Admin) ? "<br /><br />" + p.Config.Admin : "") + "</div>";
                    html += "    </ul>";
                }
                else
                {
                    //Caso a recuperação de senha seja externa, redireciona
                    if ((connector.State is CASPluginService) && (((CASPluginService)connector.State).Config.ExternalPasswordRecover) && (((CASPluginService)connector.State).Config.PasswordRecoverUri != null))
                    {
                        Response.Redirect(((CASPluginService)connector.State).Config.PasswordRecoverUri.AbsoluteUri, false);
                        return;
                    }

                    Session["recover_service"] = svc.AbsoluteUri;

                    if (Request.HttpMethod == "POST")
                    {
                        try
                        {
                            CASUserInfo user = connector.FindUser(Request["username"]);
                            user.Service = connector.Service;
                            if ((user.Success) && (user.Emails != null) && (user.Emails.Count > 0))
                            {
                                user.NewCode();
                                Session["user_info"] = user;

                                Response.Redirect("/cas/recover/step1/", false);
                                return;
                            }
                            else if ((user.Emails == null) || (user.Emails.Count == 0))
                            {
                                error = MessageResource.GetMessage("user_email_list");
                            }
                            else
                            {
                                error = user.ErrorText;
                            }
                        }
                        catch (Exception ex)
                        {
                            Tools.Tool.notifyException(ex);
                            error = MessageResource.GetMessage("internal_error");
                        }
                    }

                    html += "    <input type=\"hidden\" name=\"do\" value=\"recover1\" />";
                    html += "    <ul>";
                    html += "        <li>";
                    html += "            <p style=\"width:270px;padding:0 0 20px 0;color:#000;\">" + MessageResource.GetMessage("login_recover_message") + "</p>";
                    html += "        </li>";
                    html += "        <li>";
                    html += "            <span class=\"inputWrap\">";
                    //html += "			    <span id=\"ph_userLogin\" class=\"noSel\" style=\"position: absolute; z-index: 1; top: 13px; left: 53px; color: rgb(204, 204, 204); display: block;\">" + MessageResource.GetMessage("login_user_name") + "</span>";
                    html += "			    <input type=\"text\" id=\"username\" tabindex=\"1\" name=\"username\" value=\"\" style=\"\"  placeholder=\""+ MessageResource.GetMessage("login_user_name") + "\" onfocus=\"$('#userLogin').addClass('focus');\" onblur=\"$('#userLogin').removeClass('focus');\" />";
                    html += "			    <span id=\"ph_usernameIcon\" onclick=\"$('#userLogin').focus();\"></span>";
                    html += "            </span>";
                    html += "        </li>";
                    if (error != "")
                    {
                        html += "        <li><div class=\"error-box\">" + error + "</div>";
                    }
                    html += "        <li>";
                    html += "            <span class=\"forgot\"> <a href=\"" + svc.AbsoluteUri + "\">" + MessageResource.GetMessage("cancel") + "</a> " + MessageResource.GetMessage("or") + " </span>";
                    html += "            <button tabindex=\"4\" id=\"submitBtn\" class=\"action button floatright\">" + MessageResource.GetMessage("login_recover_btn_recover") + "</button>";
                    html += "        </li>";
                    html += "    </ul>     ";
                }

                html += "</div>";
                html += "</form>";
                html += "</div>";
            }

            holderContent.Controls.Add(new LiteralControl(html));
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String html  = "";
            String error = "";

            html += "<div id=\"recover_container\"><form id=\"pwdChange\" name=\"pwdChange\" method=\"post\"><div class=\"login_form\">";

            if ((Session["cas_ticket"] == null) || !(Session["cas_ticket"] is CASTicketResult))
            {
                //Serviço não informado ou não encontrado
                html += "    <ul>";
                html += "        <li><div class=\"error-box\">" + MessageResource.GetMessage("invalid_session") + "</div>";
                html += "    </ul>";
            }
            else
            {
                CASTicketResult ticket = (CASTicketResult)Session["cas_ticket"];
                using (DbBase db = DbBase.InstanceFromConfig(ConfigurationManager.ConnectionStrings["CASDatabase"]))
                {
                    CASConnectorBase connector = CASUtils.GetService(db, this, ticket.Service);

                    if ((connector == null) || (connector is EmptyPlugin))
                    {
                        //Serviço não informado ou não encontrado
                        html += "    <ul>";
                        html += "        <li><div class=\"error-box\">" + MessageResource.GetMessage("service_invalid_uri") + "</div>";
                        html += "    </ul>";
                    }
                    else if ((connector.State != null) && (connector.State is CASPluginService) && !(((CASPluginService)connector.State).Config.PermitChangePassword))
                    {
                        CASPluginService p = (CASPluginService)connector.State;
                        //Serviço não informado ou não encontrado
                        html += "    <ul>";
                        html += "        <li><div class=\"error-box\">" + MessageResource.GetMessage("service_not_permit_change_pwd") + (!String.IsNullOrEmpty(p.Config.Admin) ? "<br /><br />" + p.Config.Admin : "") + "</div>";
                        html += "    </ul>";
                    }
                    else
                    {
                        if (Request.HttpMethod == "POST")
                        {
                            try
                            {
                                String password  = Tools.Tool.TrataInjection(Request["password"]);
                                String password2 = Request["password2"];
                                if ((password == null) || (password == ""))
                                {
                                    error = MessageResource.GetMessage("type_password");
                                }
                                else if ((password2 == null) || (password2 == ""))
                                {
                                    error = MessageResource.GetMessage("type_password_confirm");
                                }
                                else if (password != password2)
                                {
                                    error = MessageResource.GetMessage("password_not_equal");
                                }
                                else
                                {
                                    CASChangePasswordResult res = connector.ChangePassword(ticket, password);
                                    if (res.Success)
                                    {
                                        connector.SaveTicket(ticket);

                                        CASUtils.AddCoockie(this, ticket);

                                        Session["user_info"] = new CASUserInfo(ticket);

                                        Response.Redirect(Session["ApplicationVirtualPath"] + "cas/passwordchanged/", false);
                                        return;
                                    }
                                    else
                                    {
                                        if (res.ErrorText == null)
                                        {
                                            throw new Exception("");
                                        }

                                        error = res.ErrorText;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Tools.Tool.notifyException(ex);
                                error = MessageResource.GetMessage("internal_error");
                            }
                        }

                        html += "    <ul>";
                        html += "        <li>";
                        html += "            <p style=\"width:270px;padding:0 0 20px 0;color:#000;\">" + MessageResource.GetMessage("password_expired_text") + "</p>";
                        html += "        </li>";
                        html += "    <li>";
                        html += "        <span class=\"inputWrap\">";
                        html += "			<input type=\"password\" id=\"password\" tabindex=\"1\" name=\"password\" value=\"\" style=\"\"  placeholder=\""+ MessageResource.GetMessage("new_password") + "\" onkeyup=\"cas.passwordStrength('#password');\" onfocus=\"$('#password').addClass('focus');\" onblur=\"$('#password').removeClass('focus');\" />";
                        html += "			<span id=\"ph_passwordIcon\" onclick=\"$('#password').focus();\"></span>";
                        html += "        </span>";
                        html += "    </li>";
                        html += "    <li>";
                        html += "        <span class=\"inputWrap\">";
                        html += "			<input type=\"password\" id=\"password2\" tabindex=\"1\" name=\"password2\" value=\"\" style=\"\" placeholder=\""+ MessageResource.GetMessage("new_password_confirm") + "\" onfocus=\"$('#password2').addClass('focus');\" onblur=\"$('#password2').removeClass('focus');\" />";
                        html += "			<span id=\"ph_passwordIcon\" onclick=\"$('#password2').focus();\"></span>";
                        html += "        </span>";
                        html += "    </li>";
                        html += "    <li>";
                        html += "        <div id=\"passwordStrength\"><span>" + MessageResource.GetMessage("password_strength") + ": " + MessageResource.GetMessage("unknow") + "</span><div class=\"bar\"></div></div>";
                        html += "    </li>";

                        if (error != "")
                        {
                            html += "        <li><div class=\"error-box\">" + error + "</div>";
                        }

                        html += "        <li>";
                        html += "           <span class=\"forgot\"> <a href=\"" + Session["ApplicationVirtualPath"] + "cas/login/?service=" + HttpUtility.UrlEncode(connector.Service.AbsoluteUri) + "\">" + MessageResource.GetMessage("cancel") + "</a> </span>";
                        html += "           <button tabindex=\"4\" id=\"submitBtn\" class=\"action button floatright\">" + MessageResource.GetMessage("change_password") + "</button>";
                        html += "        </li>";
                        html += "    </ul>";
                    }
                }

                html += "</div>";
                html += "</form>";
                html += "</div>";
            }
            holderContent.Controls.Add(new LiteralControl(html));
        }
Ejemplo n.º 4
0
        public static List <CASPluginService> GetPlugins2(String configPath, String assemblyPath, out String outLog)
        {
            List <CASPluginService> ret = new List <CASPluginService>();
            StringBuilder           log = new StringBuilder();

            outLog = "";
            try
            {
                log.AppendLine("Starting GetPlugins2");

                log.AppendLine("configPath exists? " + Directory.Exists(configPath));
                log.AppendLine("assemblyPath exists? " + Directory.Exists(assemblyPath));

                if (!Directory.Exists(configPath) || !Directory.Exists(assemblyPath))
                {
                    return(ret);
                }

                string[] confFiles = Directory.GetFiles(configPath, "*.conf");

                log.AppendLine("confFiles.Length = " + confFiles.Length);

                foreach (string file in confFiles)
                {
                    try
                    {
                        log.AppendLine("1");
                        CASPluginConfig cfg = new CASPluginConfig();
                        try
                        {
                            cfg.LoadFromXML(new FileInfo(file));
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("Error parsing config file '" + file + "'", ex);
                        }


                        log.AppendLine("2");
                        if (!String.IsNullOrEmpty(cfg.PluginAssembly))
                        {
                            log.AppendLine("3");
                            FileInfo asmFile = new FileInfo(Path.Combine(assemblyPath, cfg.PluginAssembly));
                            if (asmFile.Exists)
                            {
                                log.AppendLine("4");
                                Assembly assembly = Assembly.LoadFile(asmFile.FullName);

                                log.AppendLine("5");
                                CASPluginService newItem = new CASPluginService();
                                newItem.Config = cfg;

                                log.AppendLine("6");
                                Type[] classes = assembly.GetTypes();

                                log.AppendLine("7");
                                foreach (Type type in assembly.GetTypes())
                                {
                                    log.AppendLine("8");
                                    if (!type.IsClass || type.IsNotPublic)
                                    {
                                        continue;
                                    }

                                    log.AppendLine("9");
                                    if (type.BaseType.Equals(typeof(CASConnectorBase))) //Primeiro nível
                                    {
                                        newItem.Plugin = type;

                                        /*object obj = Activator.CreateInstance(type);
                                         * CASConnectorBase t = (CASConnectorBase)obj;
                                         * newItem.Plugin = t;*/
                                    }
                                    else if ((type.BaseType.BaseType != null) && type.BaseType.BaseType.Equals(typeof(CASConnectorBase))) //Segundo nível
                                    {
                                        newItem.Plugin = type;

                                        /*
                                         * object obj = Activator.CreateInstance(type);
                                         * CASConnectorBase t = (CASConnectorBase)obj;
                                         * newItem.Plugin = t;*/
                                    }
                                }

                                log.AppendLine("10");
                                if (newItem.Plugin != null)
                                {
                                    ret.Add(newItem);
                                }

                                log.AppendLine("11");
                                log.AppendLine("Config file '" + file + "' loaded as " + newItem.Config.Service);
                            }
                            else
                            {
                                log.AppendLine("Erro on load config file '" + file + "': Assembly file not exists (" + asmFile.FullName + ")");
                                cfg = null;
                            }
                        }
                        else
                        {
                            log.AppendLine("Erro on load config file '" + file + "': Parameter PluginAssembly is empty");
                            cfg = null;
                        }
                    }
                    catch (Exception ex) {
                        log.AppendLine("Erro on load config file '" + file + "': " + ex.Message);
                    }
                    finally
                    {
                    }

                    log.AppendLine("");
                }
            }
            finally
            {
                outLog = log.ToString();
                log.Clear();
                log = null;
            }

            return(ret);
        }