Exemplo n.º 1
0
        /*protected override void ValidateConnectionString(string connectionString, SqlProduct sqlProduct)
         * {
         * ValidateConnectionString(connectionString, sqlProduct) ;
         * }*/

        protected virtual ConnectionParameter ValidateConnection(string dbConnectionString, string duradosUserId, bool usesSsh = false, bool usesSsl = false, string sshRemoteHost = null, string sshUser = null, string sshPassword = null, string sshPrivateKey = null, int sshPort = 0, bool integratedSecurity = false)
        {
            /*** dbConnectionString example postgres://qvsrwdpkmcundl:Xq9Rv48RqvPjDJVlSJAXwqUZBB@ec2-54-204-31-13.compute-1.amazonaws.com:5432/d35mshek2k9rg1
             * string serverName = "ec2-54-204-31-13.compute-1.amazonaws.com";
             * string catalog = "d35mshek2k9rg1";
             * string userName = "******";
             * string password = "******";
             */
            ConnectionParameter oConnectionParameter = new ConnectionParameter();

            oConnectionParameter = ConnectionBuilder.GetConnectionParam(dbConnectionString);

            string     serverName = oConnectionParameter.serverName;
            string     catalog    = oConnectionParameter.catalog;
            string     dbUserName = oConnectionParameter.dbUsername;
            string     dbPassword = oConnectionParameter.dbPassword;
            int        port       = oConnectionParameter.port;
            SqlProduct productId  = oConnectionParameter.productId;

            if (productId == SqlProduct.Postgre)
            {
                usesSsl = true;
            }
            ValidateConnectionString(integratedSecurity, serverName, catalog, dbUserName, dbPassword, usesSsh, usesSsl, duradosUserId, productId, sshRemoteHost, sshUser, sshPassword, sshPrivateKey, sshPort, port);

            return(oConnectionParameter);
        }
Exemplo n.º 2
0
        public static ConnectionParameter GetConnectionParam(string connectionString)
        {
            ConnectionParameter oConnectionParameter = new ConnectionParameter();

            try
            {
                /* <db type>://<username>:<password>@<database server host>:<port>/<database name>
                 * "{\"db\":\"SqlAzure://*****:*****@.\\\\SQL2012:0/durados_AppSys_1214\",\"resource_id\":\"307\",\"app_name\":\"backand-qatest\",\"token\":\"backand\",\"expires\":1398783079238}";*/

                /***Product Name and convertion into Product Id (DB)*/
                String[] oArgs = connectionString.Split(':');
                string   sProd = oArgs[0].ToLower();
                if (sProd == "oracle")
                {
                    oConnectionParameter.productId = SqlProduct.Oracle;
                }
                if (sProd == "postgres")
                {
                    oConnectionParameter.productId = SqlProduct.Postgre;
                    oConnectionParameter.ssl       = true;
                }
                else if (sProd == "mysql")
                {
                    oConnectionParameter.productId = SqlProduct.MySql;
                }
                else if (sProd == "sqlazure")
                {
                    oConnectionParameter.productId = SqlProduct.SqlAzure;
                }
                else if (sProd == "sqlserver")
                {
                    oConnectionParameter.productId = SqlProduct.SqlServer;
                }


                /***User Name, <username>
                 * oArgs[1] = //itay
                 */
                oConnectionParameter.dbUsername = oArgs[1].Substring(2, oArgs[1].Length - 2);

                /** Password and Server name, <password>@<database server host>
                 * oArgs[2] = Back2013@.\\\\SQL2012
                 */
                String[] oPassAndServer = oArgs[2].Split('@');

                oConnectionParameter.dbPassword = oPassAndServer[0];/**<password>*/
                string serverName = oPassAndServer[1];

                if (oArgs.Length == 4)                            /**Connection string contains port*/
                {
                    oConnectionParameter.serverName = serverName; /**<database server host>*/

                    /** Port and Catalog, <port>/<database name>
                     * oArgs[3] = 0/durados_AppSys_1214
                     */
                    String[] oPortAndCatalog = oArgs[3].Split('/');
                    oConnectionParameter.port    = Convert.ToInt32(oPortAndCatalog[0]);
                    oConnectionParameter.catalog = oPortAndCatalog[1];
                }
                else/**If connection string doesn't contain port*/
                {
                    /** serverName = <database server host>/<database name>*/

                    String[] oServerAndCatalog = serverName.Split('/');
                    oConnectionParameter.port       = 0;
                    oConnectionParameter.serverName = oServerAndCatalog[0];
                    oConnectionParameter.catalog    = oServerAndCatalog[1];
                }
            }
            catch (Exception)
            {
                new ArgumentNullException("Invalid Argument");
            }

            return(oConnectionParameter);
        }
Exemplo n.º 3
0
        public ActionResult app(string state)
        {
            string json = "";

            try
            {
                //this is a sample
                /**string encryptedBase64String=A9XqFaC4VY7qQeXRwBGthnXaf2bFtIaAMhaTpROibMKdGhM8NFTRIvqWjyN3S9mCPjRprQwjJ7P%2F1a6TNpQPPidE7kPx%2BGhvAEhEYV6dZN02qASI1HVvVdCooHzsFaqVixIqZSGGU8SBQu%2F2GVrPGJiMN9CyvmJBSe3YFtWzNFs0g0OjkG8K8aDmw3VqgcWalFr7CYDyU4H81rgY6DpIwdLNewAPJ5rBvchRMAOvXbgCe4DAGbFNmYEpy9I4TH8oKRMtaDoHOlvPkYKTWFGWmg%3D%3D*/

                json = Base64CryptoHelper.DecryptString(Server.UrlDecode(state).Replace(" ", "+"));/*Fix for decoding problem that causes + to be replaced with space " "*/
                if (String.IsNullOrEmpty(json))
                {
                    if (!String.IsNullOrEmpty(state))
                    {
                        json = state;
                    }
                }
            }
            catch (Exception e)
            {
                return(FailureResponse(CreateAppParameter.CODES.INVALID_SECURITY_DATA, "Security failure", 0, null, null));
            }


            if (String.IsNullOrEmpty(json))
            {
                return(FailureResponse(CreateAppParameter.CODES.INVALID_SECURITY_DATA, "Security failure", 0, null, null));
            }

            PluginArgs oArgs = new PluginArgs();

            try
            {
                JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
                oArgs = (PluginArgs)jsonSerializer.Deserialize <PluginArgs>(json);

                if (string.Compare(oArgs.token, "backand", false) != 0)
                {
                    return(FailureResponse(CreateAppParameter.CODES.INVALID_SECURITY_DATA, "Security failure", 0, null, null));
                    //Security failure due to invalid arguments, redirect to Heroku
                }
            }
            catch (Exception e)
            {
                //Security failure due to invalid arguments, redirect to Heroku
                return(FailureResponse(CreateAppParameter.CODES.INVALID_CONNECTION_DATA, "invalid ConnectionId", 0, null, null));
            }

            //pass security token then sign the user GetUsernameByUserId(uid);
            //oArgs.resource_id = "404";
            string userName = Maps.Instance.DuradosMap.Database.GetUsernameById(oArgs.resource_id);

            PlugInHelper.SignIn(userName);
            int uid = Convert.ToInt32(oArgs.resource_id);

            //oArgs.app_name += "testqa";

            int?connectionId = null;

            string appName       = oArgs.app_name;
            string pluginAppName = appName;
            bool   bAppExist     = Maps.Instance.AppExists(appName, uid).HasValue;

            if (bAppExist == true)
            {
                /**This user has this App/Console*/
                /***Validate Connection String !!! what about updatig connection string scenario?*/
                //Redirect to app (console)
                return(SuccessResponse(0, userName, appName, pluginAppName, true));
            }
            else
            {
                //DuradosController d = new DuradosController();

                bool connectionValidation = false;
                bAppExist = Maps.Instance.AppExists(appName).HasValue;
                ConnectionParameter oConnectionParameter = new ConnectionParameter();
                /**If true app exists but not for this user (resource_id)*/

                if (bAppExist == true)
                {
                    /**Create new and unique app name*/
                    appName = GenerateAppName(appName, uid);
                }

                try
                {
                    oConnectionParameter = ValidateConnection(oArgs.db, oArgs.resource_id);
                    connectionValidation = true;
                }
                catch (Exception exception)
                {
                    Map.Logger.Log(GetControllerNameForLog(this.ControllerContext), this.ControllerContext.RouteData.Values["action"].ToString(), exception.Source, exception, 3, null);
                    //Redirect dur to invalid connection string
                    return(FailureResponse(CreateAppParameter.CODES.INVALID_CONNECTION_DATA, exception.Message, 0, userName, appName));
                }

                if (connectionValidation == true)
                {
                    try
                    {
                        string     serverName = oConnectionParameter.serverName;
                        string     catalog    = oConnectionParameter.catalog;
                        string     dbUserName = oConnectionParameter.dbUsername;
                        string     dbPassword = oConnectionParameter.dbPassword;
                        int        port       = oConnectionParameter.port;
                        SqlProduct productId  = oConnectionParameter.productId;

                        connectionId = SaveConnection(serverName, catalog, dbUserName, dbPassword, oArgs.resource_id, productId, oConnectionParameter.ssl);
                    }
                    catch (Exception exception)
                    {
                        Map.Logger.Log(GetControllerNameForLog(this.ControllerContext), this.ControllerContext.RouteData.Values["action"].ToString(), exception.Source, exception, 1, "fail to save connection string");
                        //Redirect due to create connection id for retrived connection string
                        //return View("~/Views/PlugIn/Heroku/ConnectionHandler.aspx", new ConnectionHandlerParameter() { url = "" });
                        return(FailureResponse(CreateAppParameter.CODES.INVALID_CONNECTION_DATA, exception.Message, 0, userName, appName));
                    }
                }

                if (!connectionId.HasValue || connectionId == null)
                {
                    /**If not valide redirect to failure page*/
                    return(FailureResponse(CreateAppParameter.CODES.INVALID_CONNECTION_DATA, "invalid ConnectionId", 0, userName, appName));
                }
            }

            /**Redirect and Create new App send new connection id*/
            return(SuccessResponse(connectionId.Value, userName, oArgs.app_name, pluginAppName));
        }