Exemplo n.º 1
0
        /// <summary>
        /// Disconnects the user from the LDAP server
        /// </summary>
        private void Disconnect()
        {
            try
            {
                if (dataAccessor != null && this.state == PawnSecState.CONNECTED)
                {
                    this.dataAccessor.DisconnectDbConnection(KEY);
                    this.state = PawnSecState.DISCONNECTED;

                    /*if(UpdateConnectionInfo(false))
                     * {
                     *  this.pawnSecLogger.logMessage(LogLevel.INFO, this, "Application successfully disconnected from PAWNSEC.");
                     * }
                     * else
                     * {
                     *  this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "Application failed to disconnect from PAWNSEC.");
                     * }*/
                }
            }
            catch (Exception eX)
            {
                this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "Exception thrown when disconnecting from PAWNSEC: " + eX.Message);
            }
            finally
            {
                this.state = PawnSecState.DISCONNECTED;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reconnects with the database
        /// </summary>
        public void Reconnect()
        {
            this.pawnSecLogger.logMessage(
                LogLevel.DEBUG,
                this,
                "Reconnect()...");
            // check to see if connection is already established
            if (this.state == PawnSecState.CONNECTED)
            {
                this.pawnSecLogger.logMessage(LogLevel.WARN,
                                              this, "- Already connected");
                return;
            }

            // establish connection to database
            try
            {
                if (this.dataAccessor != null)
                {
                    this.dataAccessor.ReconnectDbConnection(KEY);
                }
                else
                {
                    this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "- PawnSec Oracle data accessor is null.  Cannot interact with the database. Exiting!");
                }

                if (this.dataAccessor != null && this.dataAccessor.Initialized)
                {
                    this.state = PawnSecState.CONNECTED;
                    this.pawnSecLogger.logMessage(LogLevel.INFO, this, "- PawnSec Oracle data accessor reconnected successfully.");
                }
                else
                {
                    this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "- PawnSec Oracle data accessor is not initialized.  Cannot interact with the database. Exiting!");
                    this.Close();
                    return;
                }
            }
            catch (Exception eX)
            {
                this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "- Could not reconnect to the PawnSec database: {0}", eX.Message);
                this.Disconnect();
            }
            finally
            {
                if (this.state == PawnSecState.DISCONNECTED)
                {
                    this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "- Still disconneted from database.");
                    this.pawnSecLogger.Dispose();
                }
            }
        }
Exemplo n.º 3
0
 public void InitializeConnection(
     OracleDataAccessor dA,
     Credentials dACred)
 {
     this.dataAccessor           = dA;
     this.state                  = PawnSecState.CONNECTED;
     this.dbHost                 = dACred.DBHost;
     this.dbPort                 = dACred.DBPort;
     this.dbService              = dACred.DBService;
     this.dbSchema               = dACred.DBSchema;
     this.dbUser                 = dACred.UserName;
     this.dbPassword             = dACred.PassWord;
     this.dataAccessor.AuxLogger = this.pawnSecLogger;
 }
Exemplo n.º 4
0
 public void Dispose()
 {
     try
     {
         this.state        = PawnSecState.DISCONNECTED;
         this.dataAccessor = null;
     }
     catch (Exception eX)
     {
         this.errorMessage = "Exception thrown while disposing accessor:" + eX.Message;
     }
     finally
     {
         this.dataAccessor = null;
         this.pawnSecLogger.Dispose();
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Parameterless Constructor to establish default assignments
        /// </summary>
        public SecurityAccessor()
        {
            this.dataAccessor = null;
            this.errorMessage = String.Empty;
            this.state        = PawnSecState.DISCONNECTED;
            this.hostInfo     = null;

            this.dbHost     = String.Empty;
            this.dbPassword = String.Empty;
            this.dbPort     = String.Empty;
            this.dbSchema   = String.Empty;
            this.dbService  = String.Empty;
            this.dbUser     = String.Empty;

            var dNow     = DateTime.Now;
            var yearStr  = dNow.Date.Year.ToString().PadLeft(4, '0');
            var monthStr = dNow.Date.Month.ToString().PadLeft(2, '0');
            var dayStr   = dNow.Date.Day.ToString().PadLeft(2, '0');
            var hrStr    = dNow.Hour.ToString().PadLeft(2, '0');
            var minStr   = dNow.Minute.ToString().PadLeft(2, '0');
            var sb       = new StringBuilder(64);
            //Determine current executable location and log directory if it exists
            string curDir = System.IO.Directory.GetCurrentDirectory();

            sb.Append(curDir + @"\logs\pawnsec_details_");
            sb.AppendFormat("{0}_{1}_{2}-{3}_{4}.log", yearStr, monthStr, dayStr, hrStr, minStr);
            this.pawnSecLogger = new TempFileLogger(sb.ToString(),
                                                    DefaultLoggerHandlers.defaultLogLevelCheckHandler,
                                                    DefaultLoggerHandlers.defaultLogLevelGenerator,
                                                    DefaultLoggerHandlers.defaultLogMessageHandler,
                                                    DefaultLoggerHandlers.defaultLogMessageFormatHandler,
                                                    DefaultLoggerHandlers.defaultDateStampGenerator);
            this.pawnSecLogger.setLogLevel(LogLevel.DEBUG);
            this.pawnSecLogger.logMessage(LogLevel.INFO, this, "PAWNSECAccessor instance constructed");

            //Clear out encrypted container
            this.encryptedConfig = null;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a connection to the PawnSec database
        /// </summary>
        /// <param name="dHost"></param>
        /// <param name="dPassword"></param>
        /// <param name="dPort"></param>
        /// <param name="dSchema"></param>
        /// <param name="dService"></param>
        /// <param name="dUser"></param>
        public void InitializeConnection(
            string dHost, string dPassword,
            string dPort, string dSchema,
            string dService, string dUser)
        {
            if (this.pawnSecLogger.IsLogDebug)
            {
                this.pawnSecLogger.logMessage(
                    LogLevel.DEBUG,
                    this,
                    "InitializeConnection({0},{1})...",
                    dHost,
                    dPort);
            }
            // check to see if connection is already established);
            if (this.state == PawnSecState.CONNECTED)
            {
                this.pawnSecLogger.logMessage(LogLevel.WARN,
                                              this, "- Already connected");
                return;
            }

            // check all inputs
            if (string.IsNullOrEmpty(dHost) ||
                string.IsNullOrEmpty(dPassword) ||
                string.IsNullOrEmpty(dPort) ||
                string.IsNullOrEmpty(dSchema) ||
                string.IsNullOrEmpty(dService) ||
                string.IsNullOrEmpty(dUser))
            {
                this.pawnSecLogger.logMessage(LogLevel.ERROR,
                                              this, "- Invalid inputs");
                return;
            }

            // assign db related class members
            this.dbHost     = dHost;
            this.dbPassword = dPassword;
            this.dbPort     = dPort;
            this.dbSchema   = dSchema;
            this.dbService  = dService;
            this.dbUser     = dUser;

            // establish connection to database
            try
            {
                this.dataAccessor = new OracleDataAccessor(
                    this.dbUser,
                    this.dbPassword,
                    this.dbHost,
                    this.dbPort,
                    this.dbService,
                    this.dbSchema,
                    FETCH_SZ_MX,
                    true,
                    true,
                    KEY
                    );
                this.dataAccessor.AuxLogger = this.pawnSecLogger;

                if (this.dataAccessor.Initialized)
                {
                    this.state = PawnSecState.CONNECTED;
                    this.pawnSecLogger.logMessage(LogLevel.INFO, this, "- PawnSec Oracle data accessor connected successfully.");
                }
                else
                {
                    this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "- PawnSec Oracle data accessor is not initialized.  Cannot interact with the database. Exiting!");
                    this.Close();
                    return;
                }
            }
            catch (Exception eX)
            {
                this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "- Could not connect to the PawnSec database: {0}", eX.Message);
                this.Disconnect();
            }
            finally
            {
                if (this.state == PawnSecState.DISCONNECTED)
                {
                    this.pawnSecLogger.logMessage(LogLevel.FATAL, this, "- Still disconneted from database.");
                    this.pawnSecLogger.Dispose();
                }
            }
        }