Пример #1
0
        /// <summary>
        /// Validates a user to a SQL or integrated account.
        /// </summary>
        /// <param name="username">The user name.</param>
        /// <param name="password">The user password.</param>
        private void ValidateUser(string username, string password)
        {
            try
            {
                bool authResult = false;
                ConnectionStringExtensionElement[] items = ConnectionStringExtensionConfigurationManager.ConnectionStringExtensionElements();
                if (items.Count() > 0)
                {
                    // For each service host  configuration find
                    // the corresponding service type.
                    foreach (ConnectionStringExtensionElement item in items)
                    {
                        // Get the current type name
                        // and create a instance of the type.
                        Type   typeName         = Type.GetType(item.TypeName, true, true);
                        object typeNameInstance = Activator.CreateInstance(typeName);

                        if (UserNamePasswordValidatorType == null)
                        {
                            UserNamePasswordValidatorType = this;
                        }

                        if (UserNamePasswordValidatorType != null)
                        {
                            if (UserNamePasswordValidatorType.GetType().FullName.ToLower() == typeNameInstance.GetType().FullName.ToLower())
                            {
                                Type dataAccessProviderType = Type.GetType(item.DataAccessProvider, true, true);
                                ConnectionContext.ConnectionType     connectionType     = ConnectionContext.ConnectionTypeConverter.GetConnectionType(item.ConnectionType);
                                ConnectionContext.ConnectionDataType connectionDataType = ConnectionContext.ConnectionTypeConverter.GetConnectionDataType(item.ConnectionDataType);

                                // Data table containing the data.
                                DataTable dataTable = null;
                                string    sql       =
                                    "SELECT [" + item.IndicatorColumnName + "] " +
                                    "FROM [" + (String.IsNullOrEmpty(item.DatabaseOwner) ? "" : item.DatabaseOwner + "].[") + item.TableName.Replace(".", "].[") + "] " +
                                    "WHERE ([" + item.ComparerColumnName + "] = '" + username + "')";

                                sql = Nequeo.Data.DataType.DataTypeConversion.
                                      GetSqlConversionDataTypeNoContainer(connectionDataType, sql);

                                string providerName     = null;
                                string connection       = string.Empty;
                                string connectionString = string.Empty;

                                // Get the current database connection string
                                // from the configuration file through the
                                // specified configuration key.
                                using (DatabaseConnections databaseConnection = new DatabaseConnections())
                                    connection = databaseConnection.DatabaseConnection(item.ConnectionName, out providerName);

                                // If empty string is returned then
                                // value should be the connection string.
                                if (String.IsNullOrEmpty(connection))
                                {
                                    connectionString = item.ConnectionName;
                                }
                                else
                                {
                                    connectionString = connection;
                                }

                                // Create an instance of the data access provider
                                Nequeo.Data.DataType.IDataAccess dataAccess = ((Nequeo.Data.DataType.IDataAccess)Activator.CreateInstance(dataAccessProviderType));

                                // Get the connection type
                                switch (connectionType)
                                {
                                // Get the permission data from the
                                // database through the sql provider.
                                case ConnectionContext.ConnectionType.SqlConnection:
                                    dataAccess.ExecuteQuery(ref dataTable, sql,
                                                            CommandType.Text, connectionString, true, null);
                                    break;

                                // Get the permission data from the
                                // database through the oracle provider.
                                case ConnectionContext.ConnectionType.PostgreSqlConnection:
                                    dataAccess.ExecuteQuery(ref dataTable, sql,
                                                            CommandType.Text, connectionString, true, null);
                                    break;

                                // Get the permission data from the
                                // database through the oracle provider.
                                case ConnectionContext.ConnectionType.OracleClientConnection:
                                    dataAccess.ExecuteQuery(ref dataTable, sql,
                                                            CommandType.Text, connectionString, true, null);
                                    break;

                                // Get the permission data from the
                                // database through the oracle provider.
                                case ConnectionContext.ConnectionType.OleDbConnection:
                                    dataAccess.ExecuteQuery(ref dataTable, sql,
                                                            CommandType.Text, connectionString, true, null);
                                    break;

                                // Get the permission data from the
                                // database through the oracle provider.
                                case ConnectionContext.ConnectionType.OdbcConnection:
                                    dataAccess.ExecuteQuery(ref dataTable, sql,
                                                            CommandType.Text, connectionString, true, null);
                                    break;

                                // Get the permission data from the
                                // database through the oracle provider.
                                case ConnectionContext.ConnectionType.MySqlConnection:
                                    dataAccess.ExecuteQuery(ref dataTable, sql,
                                                            CommandType.Text, connectionString, true, null);
                                    break;

                                default:
                                    dataAccess.ExecuteQuery(ref dataTable, sql,
                                                            CommandType.Text, connectionString, true, null);
                                    break;
                                }

                                // Permission data exists.
                                if (dataTable != null)
                                {
                                    if (dataTable.Rows.Count > 0)
                                    {
                                        string permissionValueItem = dataTable.Rows[0][item.IndicatorColumnName].ToString();
                                        if (!String.IsNullOrEmpty(permissionValueItem))
                                        {
                                            if (password.ToLower() == permissionValueItem.ToLower())
                                            {
                                                authResult = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // If the user has been validated
                // and autharised then allow connection.
                if (!authResult)
                {
                    throw new FaultException("Unknown Username or Incorrect Password");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        public string[] UserListService()
        {
            string[] userList = null;

            try
            {
                ConnectionStringExtensionElement[] items = ConnectionStringExtensionConfigurationManager.ConnectionStringExtensionElements();
                if (items != null)
                {
                    if (items.Count() > 0)
                    {
                        // For each service host  configuration find
                        // the corresponding service type.
                        foreach (ConnectionStringExtensionElement item in items)
                        {
                            if (item.ServiceMethodName.ToLower() == "userlistservice")
                            {
                                // Get the current type name
                                // and create a instance of the type.
                                Type   typeName         = Type.GetType(item.TypeName, true, true);
                                object typeNameInstance = Activator.CreateInstance(typeName);

                                if (DynamicDataType == null)
                                {
                                    DynamicDataType = this;
                                }

                                if (DynamicDataType != null)
                                {
                                    if (DynamicDataType.GetType().FullName.ToLower() == typeNameInstance.GetType().FullName.ToLower())
                                    {
                                        Type dataAccessProviderType = Type.GetType(item.DataAccessProvider, true, true);
                                        ConnectionContext.ConnectionType     connectionType     = ConnectionContext.ConnectionTypeConverter.GetConnectionType(item.ConnectionType);
                                        ConnectionContext.ConnectionDataType connectionDataType = ConnectionContext.ConnectionTypeConverter.GetConnectionDataType(item.ConnectionDataType);

                                        // Data table containing the data.
                                        DataTable dataTable = null;
                                        string    sql       =
                                            "SELECT [" + item.IndicatorColumnName + "], [" + item.DataObjectPropertyName + "] " +
                                            "FROM [" + (String.IsNullOrEmpty(item.DatabaseOwner) ? "" : item.DatabaseOwner + "].[") + item.TableName.Replace(".", "].[") + "] ";

                                        if ((!String.IsNullOrEmpty(item.ComparerColumnName)) && (!String.IsNullOrEmpty(item.ComparerValue)))
                                        {
                                            sql += "WHERE ([" + item.ComparerColumnName + "] = '" + item.ComparerValue + "')";
                                        }

                                        sql = Nequeo.Data.DataType.DataTypeConversion.
                                              GetSqlConversionDataTypeNoContainer(connectionDataType, sql);

                                        string providerName     = null;
                                        string connection       = string.Empty;
                                        string connectionString = string.Empty;

                                        // Get the current database connection string
                                        // from the configuration file through the
                                        // specified configuration key.
                                        using (DatabaseConnections databaseConnection = new DatabaseConnections())
                                            connection = databaseConnection.DatabaseConnection(item.ConnectionName, out providerName);

                                        // If empty string is returned then
                                        // value should be the connection string.
                                        if (String.IsNullOrEmpty(connection))
                                        {
                                            connectionString = item.ConnectionName;
                                        }
                                        else
                                        {
                                            connectionString = connection;
                                        }

                                        // Create an instance of the data access provider
                                        Nequeo.Data.DataType.IDataAccess dataAccess = ((Nequeo.Data.DataType.IDataAccess)Activator.CreateInstance(dataAccessProviderType));

                                        // Get the connection type
                                        switch (connectionType)
                                        {
                                        // Get the permission data from the
                                        // database through the sql provider.
                                        case ConnectionContext.ConnectionType.SqlConnection:
                                            dataAccess.ExecuteQuery(ref dataTable, sql,
                                                                    CommandType.Text, connectionString, true, null);
                                            break;

                                        // Get the permission data from the
                                        // database through the oracle provider.
                                        case ConnectionContext.ConnectionType.PostgreSqlConnection:
                                            dataAccess.ExecuteQuery(ref dataTable, sql,
                                                                    CommandType.Text, connectionString, true, null);
                                            break;

                                        // Get the permission data from the
                                        // database through the oracle provider.
                                        case ConnectionContext.ConnectionType.OracleClientConnection:
                                            dataAccess.ExecuteQuery(ref dataTable, sql,
                                                                    CommandType.Text, connectionString, true, null);
                                            break;

                                        // Get the permission data from the
                                        // database through the oracle provider.
                                        case ConnectionContext.ConnectionType.OleDbConnection:
                                            dataAccess.ExecuteQuery(ref dataTable, sql,
                                                                    CommandType.Text, connectionString, true, null);
                                            break;

                                        // Get the permission data from the
                                        // database through the oracle provider.
                                        case ConnectionContext.ConnectionType.OdbcConnection:
                                            dataAccess.ExecuteQuery(ref dataTable, sql,
                                                                    CommandType.Text, connectionString, true, null);
                                            break;

                                        // Get the permission data from the
                                        // database through the oracle provider.
                                        case ConnectionContext.ConnectionType.MySqlConnection:
                                            dataAccess.ExecuteQuery(ref dataTable, sql,
                                                                    CommandType.Text, connectionString, true, null);
                                            break;

                                        default:
                                            dataAccess.ExecuteQuery(ref dataTable, sql,
                                                                    CommandType.Text, connectionString, true, null);
                                            break;
                                        }

                                        // Permission data exists.
                                        if (dataTable != null)
                                        {
                                            if (dataTable.Rows.Count > 0)
                                            {
                                                List <string> cols = new List <string>();
                                                foreach (DataRow row in dataTable.Rows)
                                                {
                                                    cols.Add("<a href=\"" + item.ServiceMethodRedirectionUrl + "?" + item.DataObjectPropertyName + "=" +
                                                             row[item.DataObjectPropertyName].ToString() + "\">" + row[item.IndicatorColumnName].ToString() + "</a>");
                                                }

                                                // Assign the collection.
                                                userList = cols.ToArray();
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                LogHandler.WriteTypeMessage(errorMessage, typeof(DynamicData).GetMethod("UserListService"));
            }

            // Return the list of users.
            return(userList == null ? new string[0] : userList);
        }