A method and device for determining a database verification password
By obtaining the first database connection driver in the database interface, the first database connection driver is obtained and the use of a spare database verification password, which solves the problem of the application system that needs to be restarted in the existing technology to determine the database verification password, and realize the function of automatic determination of the database verification password without interruption. Ensure the stability of the transaction.
Patent Information
- Application Number
- CN202010231086.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-03-27
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2040-03-27
AI Technical Summary
In the prior art, it is necessary to determine the database verification password after the application system is restarted, resulting in damage to the transactions during the running process.
The creation request for the creation of the database interface to call the first database connection driver, obtain the first password in the first password group, and use it to create a database connection. If the creation fails, obtain the second password in the second password group for creation to ensure that no matter whether the first password is verified or not, you can obtain the correct database verification password without interrupting the operation of the application system.
In the case of the operation of the application system, the database verification password is automatically determined, avoiding the risk of transaction damage, and ensuring the high availability and stability of the financial industry application system.
Smart Images

Figure CN111414610B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database application programs in the field of financial technology (Fintech), and in particular to a method and device for determining a database verification password. Background Art
[0002] With the development of computer technology, more and more technologies are applied in the financial field. The traditional financial industry is gradually transforming to financial technology (Fintech). However, due to the security and real-time requirements of the financial industry, higher requirements are also placed on technology. In various application systems in the financial industry, it is necessary to obtain a database connection to access the database.
[0003] However, the application systems in the financial industry are extremely sensitive to customer information and financial information. For security purposes, the database password needs to be changed regularly. Although in many scenarios, the application system will create a database connection in advance and directly obtain the database connection when needed. However, the database connection generally sets a verification cycle. In some cases, such as network anomalies or exceeding the maximum survival time, when the application system needs to create or rebuild a database connection, it needs to verify the database password. The current method is to change the database verification password by manually changing the configuration file. If the database password is changed, the application system will inevitably fail to connect to the database, and further, it will cause the application system that is already running to be interrupted. Obviously, this method will cause the operation of the application system to be interrupted. The database verification password needs to be determined only after the application system is restarted, so the transaction during the operation process will be damaged. There is an urgent need for a transaction-free determination method of the database verification password. Summary of the invention
[0004] The present invention provides a method and device for determining a database verification password, which solves the problem in the prior art that the database verification password can only be determined after the application system is restarted, thereby damaging transactions in the running process.
[0005] In a first aspect, the present invention provides a method for determining a database verification password, comprising: calling a first database connection driver program through a creation request received through a database interface, the creation request including an incoming password; the incoming password is a database verification password agreed in the database interface for creating a database connection; through the first database connection driver program, obtaining a first password in a first password group and using the first password to create a database connection; the first password group includes the first password and a second password; the first password is a default database verification password for creating a database connection in the first database connection driver program; the second password is a backup database verification password for the first password; if the creation of the database connection fails, obtaining the second password through the first database connection driver program and using the second password to create a database connection.
[0006] In the above method, the creation request received through the database interface calls the first database connection driver, and the creation request includes an incoming password. Although the database verification password for creating a database connection is agreed in the database interface, the first password in the first password group is obtained through the first database connection driver and the database connection is created using the first password. That is, on the basis of following the standard interface, the incoming password is abandoned, and the first password group includes, in addition to the first password used by default, the second password of the standby database verification password of the first password, that is, the database verification password to be subsequently changed is obtained in advance, and the first password is used as the database verification password for creating a database connection. Then, when it is determined that the first password verification is wrong, it can be known that the currently used database verification password has been changed to the second password, and the second password is directly used as the database verification password for creating a database connection, thereby obtaining the second password and creating a database connection using the second password. In this process of determining the database verification password, even if the first password verification is wrong, only one database verification password verification error is required, and the application system does not need to be interrupted, and the transaction during the operation will not be damaged.
[0007] In an optional implementation, the first database connection driver is modified based on the second database connection driver; the second database connection driver is the original database connection driver corresponding to the database interface; the first database connection driver is used to create a database connection using the first password; including: calling a first database connection creation function through the first database connection driver, thereby creating a database connection using the first password; the first database connection creation function is a function that inherits and rewrites the second database connection creation function.
[0008] In the above method, the first database connection driver is modified based on the second database connection driver. Since the first database connection creation function is a rewritten function after inheriting the second database connection creation function, the database connection can be created using the first password through the rewritten first database connection creation function, and a method for creating a database connection using the first password by implementing the inherited rewritten function is provided.
[0009] In an optional implementation, the second database connection driver is a MySQL JDBC driver; the second database connection driver implements the database interface through a first implementation class; the second database connection creation function is a protected static function in the second implementation class; the first implementation class references the second database connection creation function in the second implementation class; the third implementation class in the first database connection driver inherits the second implementation class; the first database connection creation function is a function in the third implementation class; calling the first database connection creation function through the first database connection driver to create a database connection using the first password includes: calling the first database connection creation function in the third implementation class through the first database connection driver, calling the parent class static function of the first database connection creation function, that is, referencing the second database connection creation function in the second implementation class, thereby creating a database connection using the first password.
[0010] In the above method, the second database connection driver implements the database interface through the first implementation class; the second database connection creation function is a protected static function in the second implementation class; the first implementation class references the second database connection creation function in the second implementation class; although the second database connection creation function is a protected static function in the second implementation class, the first database connection creation function in the third implementation class can be called through the first database connection driver, because the third implementation class in the first database connection driver inherits the second implementation class; the first database connection creation function is a function in the third implementation class, so the parent class static function of the first database connection creation function is called, that is, the second database connection creation function in the second implementation class is referenced, thereby indirectly calling the protected second database connection creation function through inheritance and then reference, and creating a database connection using the first password.
[0011] In an optional implementation, the first database connection driver is a first Java database connection JDBC driver; the first password group is cached in the Java virtual machine JVM memory; obtaining the first password in the first password group through the first database connection driver includes: retrieving the first password in the first password group from the JVM memory by calling the first JDBC driver.
[0012] In the above method, when the first database connection driver is a first Java database connection JDBC driver, the first password group is cached in the Java virtual machine JVM memory. Since the access efficiency of the JVM memory is relatively high, the efficiency of obtaining the first password in the first password group can be improved.
[0013] In an optional implementation, before obtaining the first password in the first password group through the first database connection driver and using the first password to create a database connection, it also includes: if the first password group is not taken out from the JVM memory by calling the first JDBC driver, obtaining a password group from a password agent as the first password group; the password agent is a client agent program that obtains a password group from a password management system according to a preset period; the password management system is used to generate a password group.
[0014] In the above manner, if the first password group is not taken out from the JVM memory by calling the first JDBC driver, the password group can be obtained from the password agent as the first password group. Since the password agent is a client agent program that obtains the password group from the password management system according to a preset period, the password management system is used to generate the password group, thereby providing a method for regularly obtaining updated password groups from the JVM memory.
[0015] In an optional implementation, each password in the first password group is cached in the JVM memory in the form of an encrypted password; taking out the first password in the first password group from the JVM memory includes: obtaining a key for decrypting each password in the first password group through the first JDBC driver; decrypting the ciphertext password of the first password through the first JDBC driver according to the key of the first password in the keys of each password in the first password group, thereby obtaining a plaintext password of the first password.
[0016] Under the above method, each password in the first password group is cached in the JVM memory in the form of an encrypted password. Even if the password in the JVM memory is stolen, it is still an encrypted text. When verification is required through the first password, the key for decrypting each password in the first password group is first obtained through the first JDBC driver, and the ciphertext password of the first password is decrypted according to the key of the first password to obtain the plaintext password, thereby further increasing the security of the password.
[0017] In an optional implementation, after the creation of the database connection fails, it also includes: obtaining a second password group through the first database connection driver to replace the first password group; the second password group includes the second password and a third password; the third password is a backup database verification password for the second password.
[0018] In the above manner, after the establishment of the database connection fails, the second password group can be obtained through the first database connection driver to replace the first password group. The second password group contains a backup database verification password of the second password, which further increases the stability of the determination of the database verification password.
[0019] In an optional implementation manner, the first password group further includes a standby database verification password of a standby database verification password; wherein the fourth password is the standby database verification password of the second password.
[0020] In the above manner, the first password group also includes a standby database verification password of the standby database verification password. Even if the second password is changed subsequently, the fourth password can be used to create a database connection, thereby further increasing the stability of determining the database verification password.
[0021] In a second aspect, the present invention provides a device for determining a database verification password, comprising: a calling module, used to call a first database connection driver program through a creation request received through a database interface, the creation request including an incoming password; the incoming password is a database verification password agreed in the database interface for creating a database connection; a creation module, used to obtain a first password in a first password group through the first database connection driver program and use the first password to create a database connection; the first password group includes the first password and a second password; the first password is the default database verification password for creating a database connection in the first database connection driver program; the second password is a standby database verification password for the first password; and used to obtain the second password through the first database connection driver program and use the second password to create a database connection if the creation of the database connection fails.
[0022] In an optional implementation, the first database connection driver is modified based on the second database connection driver; the second database connection driver is the original database connection driver corresponding to the database interface; the calling module is specifically used to: call the first database connection creation function through the first database connection driver, thereby creating a database connection using the first password; the first database connection creation function is a function that is rewritten after inheriting the second database connection creation function.
[0023] In an optional implementation, the second database connection driver is a MySQL JDBC driver; the second database connection driver implements the database interface through a first implementation class; the second database connection creation function is a protected static function in the second implementation class; the first implementation class references the second database connection creation function in the second implementation class; the third implementation class in the first database connection driver inherits the second implementation class; the first database connection creation function is a function in the third implementation class; the calling module is specifically used to: call the first database connection creation function in the third implementation class through the first database connection driver, call the parent class static function of the first database connection creation function, that is, reference the second database connection creation function in the second implementation class, thereby creating a database connection using the first password.
[0024] In an optional implementation, the first database connection driver is a first Java database connection JDBC driver; the first password group is cached in the Java virtual machine JVM memory; the creation module is specifically used to: retrieve the first password in the first password group from the JVM memory by calling the first JDBC driver.
[0025] In an optional implementation, the creation module is also used to: if the first password group is not taken out from the JVM memory by calling the first JDBC driver, obtain the password group from the password agent as the first password group; the password agent is a client agent program that obtains the password group from the password management system according to a preset period; the password management system is used to generate a password group.
[0026] In an optional implementation, each password in the first password group is cached in the JVM memory in the form of an encrypted password; the creation module is specifically used to: obtain, through the first JDBC driver, a key for decrypting each password in the first password group; through the first JDBC driver, decrypt the ciphertext password of the first password according to the key of the first password in the keys of each password in the first password group, thereby obtaining the plaintext password of the first password.
[0027] In an optional implementation, the creation module is also used to: obtain a second password group through the first database connection driver to replace the first password group; the second password group includes the second password and a third password; the third password is a backup database verification password for the second password.
[0028] In an optional implementation manner, the first password group further includes a standby database verification password of a standby database verification password; wherein the fourth password is the standby database verification password of the second password.
[0029] The beneficial effects of the above-mentioned second aspect and each embodiment of the second aspect can refer to the beneficial effects of the above-mentioned first aspect and each embodiment of the first aspect, and will not be repeated here.
[0030] In a third aspect, the present invention provides a computer device, including a program or an instruction, which, when executed, is used to execute the above-mentioned first aspect and each optional method of the first aspect.
[0031] In a fourth aspect, the present invention provides a storage medium, comprising a program or an instruction, which, when executed, is used to execute the above-mentioned first aspect and each optional method of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 A schematic diagram of the steps of a method for determining a database verification password provided in an embodiment of the present application;
[0033] Figure 2 A flowchart of specific steps of a method for determining a database verification password provided in an embodiment of the present application;
[0034] Figure 3 A specific schematic diagram of a data connection driver in a method for determining a database verification password provided in an embodiment of the present application;
[0035] Figure 4 A schematic diagram of the structure of a device for determining a database verification password provided in an embodiment of the present application. DETAILED DESCRIPTION
[0036] In order to better understand the above-mentioned technical scheme, the above-mentioned technical scheme will be described in detail below in combination with the accompanying drawings and specific implementation methods of the specification. It should be understood that the embodiments of the present application and the specific features in the embodiments are detailed descriptions of the technical scheme of the present application, rather than limitations on the technical scheme of the present application. In the absence of conflict, the embodiments of the present application and the technical features in the embodiments may be combined with each other.
[0037] First, the nouns appearing in this application are listed.
[0038] Database connection pool is a technology for creating and managing a buffer pool of connections to a database. After the database connection pool is established, a request to access the database only needs to obtain a database connection from the connection pool, and then return the database connection to the connection pool after use. This can avoid the system resource overhead and time overhead of creating a new database connection each time the database is accessed. For example, common database connection pools include: c3p0, DBCP, Tomcat JDBC Pool, etc.
[0039] Java Database Connectivity (JDBC): A unified interface used in the Java language to access a database. Different databases implement this interface, called a JDBC driver, such as Oracle Jdbc driver, MySQL JDBC driver, etc.
[0040] When a financial institution (bank, insurance or securities institution) is conducting business (such as bank loan business, deposit business, etc.), various application systems need to obtain a database connection to access the database. When an application system needs to create or rebuild a database connection, it needs to verify the database password. However, the application system in the financial industry is extremely sensitive to customer information and financial information. For security purposes, the database password needs to be changed regularly.
[0041] However, the contradiction is that for the purpose of efficiency and resource control, application systems usually use database connection pool technology. For example, using database connection pool technology can prevent the resource and time overhead of creating a new database connection each time the database is accessed; by limiting the database connection in the database connection pool, database resources can be protected. But no matter what kind of database connection pool, there is a same principle: when the application system is started, when creating a database connection pool, it first assigns various parameters to the database connection pool, such as the database Internet protocol (IP) address, port, account name, password, etc.; these parameters are generally placed in the configuration file and automatically read by the database connection pool. When the application system starts, these parameters are assigned to the database connection pool, and the database connection pool then uses the above parameters to create a connection to the database. Once the database connection pool is created, the database verification password cannot be changed; there is no database connection pool in the industry that can change the database verification password online. Therefore, if the database password is changed during the operation of the application system, it will inevitably cause the application system to fail to access the database.
[0042] As mentioned above, since the application system has created the database connection when it is started, it is OK to directly use the already created database connection during the operation of the application system without creating a new database connection. So even if the database verification password is changed, there is no problem? The answer is no. This is because, in order to ensure the availability of each database connection, a verification cycle (validateInterval) is usually set for the database connection pool. In each verification, if there are the following situations, the database connection needs to be rebuilt: 1. The database connection crashes due to network anomalies or the application system itself; 2. The database connection exceeds the maximum survival time (maxAge); 3. The database connection is found to have other abnormalities during verification. Furthermore, the size of the database connection pool created when the application system is started is only an initial size (initialSize or minIdle). When the pressure of the application system increases, a new database connection still needs to be created. In other words, even if the database connection pool technology is used and the database connection is established in advance, there is still a situation of rebuilding or creating a new database connection.
[0043] It can be seen that during the operation of the application system, since the database verification password in the configuration file cannot be manually modified, the application system needs to be restarted to use a new database verification password. Obviously, this method will interrupt the operation of the application system, and the database verification password needs to be determined after the application system is restarted, so the transactions in the operation process will be damaged. This situation does not meet the needs of financial institutions such as banks and cannot ensure the efficient operation of various businesses of financial institutions.
[0044] like Figure 1 As shown, a method for determining a database verification password provided by the present invention is provided.
[0045] Step 101: calling a first database connection driver program via a creation request received through a database interface.
[0046] The create request includes an incoming password.
[0047] Step 102: Obtain a first password in a first password group through the first database connection driver and create a database connection using the first password.
[0048] Step 103: If the database connection creation fails, the second password is obtained through the first database connection driver and the database connection is created using the second password.
[0049] In step 101 to step 103, the input password is the database verification password agreed in the database interface for creating a database connection; the first password group includes the first password and the second password; the first password is the default database verification password for creating a database connection in the first database connection driver; the second password is a backup database verification password for the first password. The first password group may also be referred to as a first password pair.
[0050] It should be noted that the database interface is a unified interface provided by the first database connection driver to the outside, which is used to receive external creation requests (such as creation requests from a database connection pool). The first database connection driver must follow the unified specifications of the database interface when implementing the database interface.
[0051] In addition, in step 102, if the database connection is successfully created using the first password, it means that the database verification password has not been changed to the second password, so the first password can continue to be used when creating a database connection next time.
[0052] In the above steps, for example, the incoming password is X0, the first password is X1, and the second password is X2. Then in step 101, since the database interface of the first database connection driver needs to follow the unified specification of the database interface, the specification stipulates that the incoming password is the agreed database verification password for creating a database connection, then the incoming password X0 must be received according to this agreement. In step 102, X1 is obtained again, and X1 is used to create a database connection, thereby ignoring the received incoming password X0, and realizing the method of using the password group in this embodiment; if X1 is used to create a database connection, it may succeed or fail; if it fails, then through the first database connection driver, X2 is obtained and X2 is used to create a database connection. Since the use of X2 to create a database connection must be successful at this time, the password is automatically replaced without interrupting the system.
[0053] In an optional implementation (hereinafter referred to as implementation (1)), the first database connection driver in steps 101 to 103 may be a first Java database connection (JDBC) driver; and the Java virtual machine (JVM) is the reason why the Java language can be cross-platform, and the JVM dynamic memory allocation and recycling are relatively mature, and the first password group can be cached in the JVM memory. For example, a string type array with a length of 2 is defined to cache the password group in the local JVM. Then in step 102, the method of obtaining the first password in the first password group through the first database connection driver can be specifically:
[0054] By calling the first JDBC driver, the first password in the first password group is retrieved from the JVM memory. This method can obtain the first password more efficiently.
[0055] Based on implementation mode (1), it should be noted that before the first cipher group is taken out from the JVM memory, the first cipher group may have been stored in the JVM memory, or may not have been stored. Therefore, a possible implementation mode is:
[0056] If the first cipher group is not retrieved from the JVM memory by calling the first JDBC driver, a cipher group is obtained from a cipher proxy as the first cipher group.
[0057] The password agent is a client agent program that obtains a password group from a password management system according to a preset period; the password management system is used to generate a password group. Specifically:
[0058] Usually, in order to achieve the purpose of unified password management, there will be a password management system that is specifically used to regularly maintain the passwords of various accounts, including database verification passwords. At the same time, the password management system also provides an interface that allows each application system to obtain the latest, encrypted password group, namely, the first password and the second password, based on its own system identification (ID), key and other information. In layman's terms, the first password is the "current password"; the second password is the "next password". At any time, only one of the two database verification passwords is correct. When the password administrator needs to modify the database verification password of the specified account, first go to the database to modify the database verification password to the second password (next password). At this time, the application system will fail to connect to the database using the first password (current password) and use the second password (next password) instead. In addition, for reliability considerations, the password management system usually has a client agent program installed in the host where the application system is located, which regularly obtains and caches password information from the password management system. The application only needs to access the client agent program to obtain the password information. This client agent program is collectively referred to as a "password agent" in the present invention.
[0059] In implementation mode (1), each password in the first password group may be cached in the JVM memory in the form of a ciphertext password. Then, the specific process of taking out the first password in the first password group from the JVM memory in implementation mode (1) may be:
[0060] Through the first JDBC driver, a key for decrypting each password in the first password group is obtained; through the first JDBC driver, the ciphertext password of the first password is decrypted according to the key of the first password in the keys of each password in the first password group, so as to obtain the plaintext password of the first password.
[0061] In this way, each password in the first password group can be cached in the JVM memory in the form of a ciphertext password, and only when needed, it is decrypted by the key of the first password to obtain the plain text of the first password, which undoubtedly further increases the security of the database verification password.
[0062] After step 102, an optional implementation is as follows:
[0063] A second password group is obtained through the first database connection driver to replace the first password group; the second password group includes the second password and a third password; the third password is a backup database verification password for the second password.
[0064] Similarly, if the second password fails to be used to create a database connection in the future, the third password can be used to create a database connection. In addition, the second password group can also be obtained from the password management system through the password agent. In other words, the password manager then sets the "password pair" to "next password" and "next next password", so that the application system can successfully connect to the database in most cases using only the first password.
[0065] The specific acquisition method can refer to the acquisition process of the first password group, which will not be repeated here.
[0066] The above method of obtaining the backup database verification password of the second password is temporary acquisition and can also be obtained in advance.
[0067] It should be noted that the first password group in steps 101 to 103 may include a backup database verification password for a backup database verification password in addition to the first password and the second password; wherein the fourth password is the backup database verification password for the second password. In other words, the backup database verification password for the second password is also included in the first password group, so that the second password can be changed to the fourth password without obtaining a new password group.
[0068] It should be noted that in steps 101 to 103, whether in the application system startup process or in the application system operation process, when the database connection pool creates a database connection, several parameters (including the incoming password) can be passed in to call the first database connection driver. The present invention actually ignores the incoming password through the first database connection driver and uses the first password group provided by the password agent instead. Figure 2 , taking the scenario of a database connection pool creating a database connection (referred to as connection pool creating connection in the figure) as an example, a method for determining a database verification password provided by the present application is further introduced.
[0069] When the database connection pool creates a database connection, it will first send a creation request to the first database connection driver. When the password group contains only two database verification passwords, it can be called a password pair.
[0070] The first database connection driver will first determine whether the password pair cached in the JVM memory is empty. If it is empty, it means that the database connection pool creates a database connection for the first time when the application system is started. The password pair acquisition interface of the password agent is used to retrieve the password pair from the password agent and cache it in the JVM memory in ciphertext form.
[0071] At this point, the JVM memory must have the password pair. The first database connection driver decrypts the first database verification password in the password pair, that is, obtains the decrypted password 1.
[0072] The first database connection driver replaces the incoming password with the decrypted password 1, and then creates a database connection based on the decrypted password 1.
[0073] If the database connection is created successfully, connect to the database directly.
[0074] If the database connection creation fails, it means that the first database verification password (decryption password 1) is wrong, then the first database connection driver will decrypt the second password in the password pair, the database verification password, to get decryption password 2, and then create a database connection based on decryption password 2. Since decryption password 2 is the changed password, it will definitely pass the database verification and successfully create a database connection.
[0075] After that, the first database connection driver program asynchronously obtains the latest password pair from the password agent and refreshes the password pair in the JVM memory, so that the next time only the first password needs to be tried to succeed.
[0076] It should be noted that the method of step 101 to step 103 can be realized by transforming the connection pool, but there are various connection pool products. Even if each system uses the same type of database, the connection pools used are not the same, and the transformation workload is large. However, if the driver (such as JDBC driver) is transformed, it can be fundamentally applicable to all connection pools and all systems, so even if the connection pool is not used, and the method of directly creating a database connection or other methods similar to the connection pool is used, the present invention is still effective.
[0077] To this end, in a possible implementation manner, the first database connection driver in steps 101 to 103 may be modified based on the second database connection driver; the second database connection driver is the original database connection driver corresponding to the database interface; and the method of creating a database connection using the first password through the first database connection driver in step 102 may be as follows:
[0078] The first database connection creation function is called through the first database connection driver, thereby creating a database connection using the first password; the first database connection creation function is a function that is rewritten after inheriting the second database connection creation function.
[0079] The following example uses MySQL as the database and JDBC as the first database connection driver. Figure 3 The first database connection driver is described in detail. That is, the second database connection driver is a MySQL JDBC driver; the second database connection driver implements the database interface through the first implementation class; the second database connection creation function is a protected static function in the second implementation class; the first implementation class references the second database connection creation function in the second implementation class; the third implementation class in the first database connection driver inherits the second implementation class; the first database connection creation function is a function in the third implementation class; then in the above possible implementation, the first database connection creation function is called by the first database connection driver, thereby creating a database connection using the first password, and the specific process may be:
[0080] The first database connection creation function in the third implementation class is called through the first database connection driver, and the parent class static function of the first database connection creation function, that is, the second database connection creation function in the second implementation class, is referenced, thereby creating a database connection using the first password.
[0081] It should be noted that the methods of steps 101 to 103 and the optional methods cannot be implemented in the original second database connection driver program, and need to be modified in advance, otherwise the self-written methods of steps 101 to 103 can be written in. The above implementation is actually a bottom-level invention point. The present invention will be described by taking the second database connection driver program (MySQLJDBC driver program) as an example. Figure 3 The relationship among the JDBC interface, the first database connection driver and the second database connection driver is shown.
[0082] Specifically, the Java JDBC unified interface is a unified interface for the Java language to connect to the database. This interface indicates that any driver must create a connection to the database through the connect(String url,java.util.Properties info) method. Any database connection driver that needs to implement JDBC needs to follow this specification.
[0083] Second database connection driver (MySQL JDBC):
[0084] Take MySQL JDBC as an example. The JDBC interface in MySQL JDBC is implemented by an implementation class com.mysql.jdbc.NonRegisteringDriver (the first implementation class), which references the implementation class com.mysql.jdbc.ConnectionImpl (the second implementation class), and references the getInstance() method in com.mysql.jdbc.ConnectionImpl (the second database connection creation function) to connect to the database. Finally, the driver is exposed to users through the implementation class com.mysql.jdbc.Driver. com.mysql.jdbc.Driver also contains a self-loading code block. When the Java instance is running, com.mysql.jdbc.Driver itself is registered in the Java running instance, that is, the JVM.
[0085] First database connection driver (MySQL JDBC):
[0086] In MySQL JDBC, the getInstance() method of com.mysql.jdbc.ConnectionImpl is a protected method and can only be directly referenced by classes in the internal package com.mysql.jdbc, but not by external packages. Inheritance can be across packages, so first inherit from com.mysql.jdbc.ConnectionImpl to get a subclass, namely com.mycorp.jdbc.MySQLConnectionImpl (the third implementation class), and rewrite its static getInstance() method. Then reference the static getInstance() method of the parent class (the parent class static function) to get the first database connection creation function, thus achieving the purpose of accessing the original com.mysql.jdbc.ConnectionImpl.getInstance() method from the outside.
[0087] com.mycorp.jdbc.MySQLDriver is the driver class (the first database connection driver) that will be exposed to the application. In this method, implement Figure 1 The methods and optional methods described in the previous section. Also, when connecting to the database, use the getInstance() method of the above com.mycorp.jdbc.MySQLConnectionImpl. Similarly, write a self-loading code block to register com.mycorp.jdbc.MySQLDriver itself into the Java running instance when running.
[0088] It should be noted that there are many ways to use the modified JDBC driver. For example, in the configuration file of the connection pool, the second database connection driver class name com.mysql.jdbc.Driver can be replaced with the first database connection driver class name com.mycorp.jdbc.MySQLDriver.
[0089] For example, the connection pool configuration file is datasource.properties, in which the line that specifies the driver class name is: "datasource.driverClassName = com.mysql.jdbc.Driver";
[0090] Just change it to:
[0091] "datasource.driverClassName=com.mycorp.jdbc.MySQLDriver".
[0092] In the above optional implementation, taking the transformation of MySQL JDBC driver as an example, a method for online adaptation to database password changes is described. This transformation method is also applicable to JDBC drivers of other databases, such as Oracle, SQLServer, etc. By transforming the original second database connection driver, it ignores the incoming password and uses the first password group instead. When the first password fails, the second password is used again. One and only one of the two passwords is correct. Whenever the database password is changed, the present invention can automatically use the correct database verification password to create a connection. And there is no need to redeploy the application system or restart; no error prompts for password failure will appear during the password change process, and the transaction is completely lossless. In this way, the purpose of online and lossless adaptation to database verification password changes is achieved.
[0093] like Figure 4 As shown, the present invention provides a device for determining a database verification password, including: a calling module 401, used to call a first database connection driver program through a creation request received by a database interface, the creation request including an incoming password; the incoming password is a database verification password agreed in the database interface for creating a database connection; a creating module 402, used to obtain a first password in a first password group through the first database connection driver program and use the first password to create a database connection; the first password group includes the first password and a second password; the first password is a default database verification password for creating a database connection in the first database connection driver program; the second password is a standby database verification password for the first password; and used to obtain the second password through the first database connection driver program and use the second password to create a database connection if the creation of the database connection fails.
[0094] In an optional implementation, the first database connection driver is modified based on the second database connection driver; the second database connection driver is the original database connection driver corresponding to the database interface; the calling module 401 is specifically used to: call the first database connection creation function through the first database connection driver, thereby creating a database connection using the first password; the first database connection creation function is a function that is rewritten after inheriting the second database connection creation function.
[0095] In an optional implementation, the second database connection driver is a MySQL JDBC driver; the second database connection driver implements the database interface through the first implementation class; the second database connection creation function is a protected static function in the second implementation class; the first implementation class references the second database connection creation function in the second implementation class; the third implementation class in the first database connection driver inherits the second implementation class; the first database connection creation function is a function in the third implementation class; the calling module 401 is specifically used to: call the first database connection creation function in the third implementation class through the first database connection driver, call the parent class static function of the first database connection creation function, that is, reference the second database connection creation function in the second implementation class, thereby creating a database connection using the first password.
[0096] In an optional implementation, the first database connection driver is a first Java database connection JDBC driver; the first password group is cached in the Java virtual machine JVM memory; the creation module 402 is specifically used to: retrieve the first password in the first password group from the JVM memory by calling the first JDBC driver.
[0097] In an optional implementation, the creation module 402 is also used for: if the first password group is not retrieved from the JVM memory by calling the first JDBC driver, obtaining the password group from the password agent as the first password group; the password agent is a client agent program that obtains the password group from the password management system according to a preset period; the password management system is used to generate the password group.
[0098] In an optional implementation, each password in the first password group is cached in the JVM memory in the form of an encrypted password; the creation module 402 is specifically used to: obtain, through the first JDBC driver, a key for decrypting each password in the first password group; through the first JDBC driver, decrypt the ciphertext password of the first password according to the key of the first password in the keys of each password in the first password group, thereby obtaining the plaintext password of the first password.
[0099] In an optional implementation, the creation module 402 is also used to: obtain a second password group through the first database connection driver to replace the first password group; the second password group includes the second password and a third password; the third password is a backup database verification password for the second password.
[0100] In an optional implementation manner, the first password group further includes a standby database verification password of a standby database verification password; wherein the fourth password is the standby database verification password of the second password.
[0101] An embodiment of the present application provides a computer device, including a program or instruction, which, when executed, is used to execute a method for determining a database verification password and any optional method provided in an embodiment of the present application.
[0102] An embodiment of the present application provides a storage medium, including a program or instruction, which, when executed, is used to execute a method for determining a database verification password and any optional method provided in an embodiment of the present application.
[0103] Finally, it should be noted that: those skilled in the art should understand that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, optical storage, etc.) containing computer-usable program code.
[0104] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0105] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0106] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for determining a database verification password, characterized in that: include: Calling a first database connection driver program via a creation request received through a database interface, wherein the creation request includes an incoming password; The input password is the database verification password agreed in the database interface for creating a database connection; the first database connection driver is modified based on the second database connection driver; the second database connection driver is a MySQL JDBC driver; the second database connection driver implements the database interface through the first implementation class; the second database connection creation function is a protected static function in the second implementation class; the first implementation class references the second database connection creation function in the second implementation class; the third implementation class in the first database connection driver inherits the second implementation class; the first database connection creation function is a function in the third implementation class; Obtaining, through the first database connection driver, the first password in the first password group and using the first password to create a database connection, specifically comprising: calling, through the first database connection driver, the first database connection creation function in the third implementation class, calling the parent class static function of the first database connection creation function, that is, referencing the second database connection creation function in the second implementation class, thereby using the first password to create a database connection; the first password group includes the first password and the second password; the first password is the default database verification password for creating a database connection in the first database connection driver; the second password is a backup database verification password for the first password; If the database connection creation fails, the second password is obtained through the first database connection driver and the database connection is created using the second password.
2. The method according to claim 1, characterized in that The first database connection driver is a first JDBC driver; the first password group is cached in the Java virtual machine JVM memory; and obtaining the first password in the first password group through the first database connection driver includes: The first password in the first password group is retrieved from the JVM memory by calling the first JDBC driver.
3. The method according to claim 2, characterized in that Before obtaining the first password in the first password group through the first database connection driver and using the first password to create a database connection, the method further includes: If the first password group is not taken out from the JVM memory by calling the first JDBC driver, the password group is obtained from the password agent as the first password group; the password agent is a client agent program that obtains the password group from the password management system according to a preset period; the password management system is used to generate the password group.
4. The method according to claim 3, characterized in that Each password in the first password group is cached in the JVM memory in the form of a ciphertext password; The taking out the first password in the first password group from the JVM memory includes: Obtaining, through the first JDBC driver, a key for decrypting each cipher in the first cipher group; The ciphertext password of the first password is decrypted by the first JDBC driver according to the key of the first password in the keys of each password in the first password group, so as to obtain the plaintext password of the first password.
5. The method according to any one of claims 1 to 4, characterized in that: After the database connection creation fails, the following steps are also included: A second password group is obtained through the first database connection driver to replace the first password group; the second password group includes the second password and a third password; the third password is a backup database verification password for the second password.
6. The method according to any one of claims 1 to 4, characterized in that: The first password group also includes a standby database verification password of a standby database verification password; wherein the fourth password is the standby database verification password of the second password.
7. A device for determining a database verification password, characterized in that: include: A calling module, configured to call a first database connection driver program through a creation request received through a database interface, wherein the creation request includes an incoming password; The input password is the database verification password agreed in the database interface for creating a database connection; the first database connection driver is modified based on the second database connection driver; the second database connection driver is a MySQL JDBC driver; the second database connection driver implements the database interface through the first implementation class; the second database connection creation function is a protected static function in the second implementation class; the first implementation class references the second database connection creation function in the second implementation class; the third implementation class in the first database connection driver inherits the second implementation class; the first database connection creation function is a function in the third implementation class; A creation module is used to obtain the first password in the first password group through the first database connection driver and use the first password to create a database connection. Further, the creation module is specifically used to: call the first database connection creation function in the third implementation class through the first database connection driver, call the parent class static function of the first database connection creation function, that is, reference the second database connection creation function in the second implementation class, so as to create a database connection using the first password; the first password group includes the first password and the second password; the first password is the default database verification password for creating a database connection in the first database connection driver; the second password is a backup database verification password for the first password; and, The creation module is further configured to obtain the second password through the first database connection driver and create a database connection using the second password if the creation of the database connection fails.
8. A computer device, characterized in that: The method comprises a program or an instruction, and when the program or the instruction is executed, the method according to any one of claims 1 to 6 is performed.
9. A storage medium, characterized in that: The method comprises a program or an instruction, and when the program or the instruction is executed, the method according to any one of claims 1 to 6 is performed.
Citation Information
Patent Citations
Method and apparatus for establishing connection between JavaEE application server and database
CN105279197A