-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce KeyStoreDAO and database based keystore persistence manager implementation #4130
base: 4.10.x
Are you sure you want to change the base?
Conversation
b7ac1d7
to
de35a45
Compare
PR builder started |
PR builder completed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/12159509316
private static final KeyStoreDAO keyStoreDAO = new KeyStoreDAO(); | ||
|
||
/** | ||
* Add the key store to the database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets avoid duplicating method comments
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class JDBCKeyStorePersistenceManager implements KeyStorePersistenceManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets add a class comment
@@ -458,6 +458,10 @@ | |||
<!-- Keystore type (JKS/PKCS12 etc.)--> | |||
<Type>PKCS12</Type> | |||
</TenantKeyStore> | |||
<KeyStores> | |||
<!-- Keystore file location--> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<!-- Keystore file location-->
-> <!-- Keystore storage type-->
CREATE TABLE KEY_STORE ( | ||
ID INTEGER DEFAULT NEXTVAL('KEY_STORE_PK_SEQ'), | ||
NAME VARCHAR(255) NOT NULL, | ||
TYPE VARCHAR(255), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need 255 characters here?
NAME VARCHAR(255) NOT NULL, | ||
TYPE VARCHAR(255), | ||
PROVIDER VARCHAR(255), | ||
PASSWORD VARCHAR(1000), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Length of the password going to be depend on the key size.
return defaultPolicyPersistenceManager; | ||
} | ||
} | ||
return defaultPolicyPersistenceManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a (debug) log..
public static final String CONTENT = "CONTENT"; | ||
public static final String TENANT_ID = "TENANT_ID"; | ||
public static final String PUB_CERT_ID = "PUB_CERT_ID"; | ||
public static final String CREATED_AT = "CREATED_AT"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets use the VERSION -> CREATED_AT -> UPDATED_AT order for the consistency.
} | ||
|
||
public static final String ADD_KEY_STORE = "INSERT INTO KEY_STORE (NAME, TYPE, PROVIDER, PASSWORD, " + | ||
"PRIVATE_KEY_ALIAS, PRIVATE_KEY_PASS, CONTENT, PUB_CERT_ID, TENANT_ID, CREATED_AT, UPDATED_AT," + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets use the VERSION -> CREATED_AT -> UPDATED_AT order for the consistency.
"VERSION) VALUES (:NAME;, :TYPE;, :PROVIDER;, :PASSWORD;, :PRIVATE_KEY_ALIAS;, :PRIVATE_KEY_PASS;, " + | ||
":CONTENT;, :PUB_CERT_ID;, :TENANT_ID;, :CREATED_AT;, :UPDATED_AT;, :VERSION;);"; | ||
public static final String GET_KEY_STORE_BY_NAME = | ||
"SELECT * FROM KEY_STORE WHERE NAME = :NAME; AND TENANT_ID = :TENANT_ID;"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets avoid using select *
*/ | ||
public void addKeystore(KeyStoreModel keyStoreModel) { | ||
|
||
try (Connection connection = DatabaseUtil.getDBConnection(dataSource)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets use NamedJdbcTemplate
Purpose
Part of: wso2/product-is#21206
Details
This pull request introduces several significant changes to the codebase, primarily focusing on enhancing the key store management functionalities by adding a new persistence manager that utilizes a database for storing key stores. The most important changes include updating dependencies, modifying the
CarbonCoreDataHolder
class, adding a newJDBCKeyStorePersistenceManager
class, and creating a factory for the key store persistence manager.Enhancements to key store management:
core/org.wso2.carbon.core/pom.xml
: Added a new dependency fororg.wso2.carbon.database.utils
to support database operations for key store management. [1] [2]Updates to
CarbonCoreDataHolder
:core/org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/internal/CarbonCoreDataHolder.java
: Introduced a newDataSource
field with getter and initialization methods to manage database connections. [1] [2] [3]New
JDBCKeyStorePersistenceManager
class:core/org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/keystore/persistence/JDBCKeyStorePersistenceManager.java
: Implemented a new class for managing key stores in a database, including methods for adding, retrieving, updating, and deleting key stores.Creation of a factory for key store persistence manager:
core/org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/keystore/persistence/KeyStorePersistenceManagerFactory.java
: Added a factory class to provide the appropriate key store persistence manager based on the configuration.Addition of constants for persistence manager:
core/org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/keystore/persistence/PersistenceManagerConstants.java
: Defined constants for database-related values and SQL queries used in key store management.