generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get a fresh database password for every new connection to postgres
- Loading branch information
Showing
3 changed files
with
47 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ain/java/gov/hhs/cdc/trustedintermediary/external/PasswordChangingPostgresDataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package gov.hhs.cdc.trustedintermediary.external; | ||
|
||
import gov.hhs.cdc.trustedintermediary.context.ApplicationContext; | ||
import gov.hhs.cdc.trustedintermediary.wrappers.Logger; | ||
import gov.hhs.cdc.trustedintermediary.wrappers.database.DatabaseCredentialsProvider; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import org.postgresql.ds.PGSimpleDataSource; | ||
|
||
public class PasswordChangingPostgresDataSource extends PGSimpleDataSource { | ||
@Override | ||
public Connection getConnection() throws SQLException { | ||
ApplicationContext.getImplementation(Logger.class) | ||
.logInfo("Establishing new connection to the database"); | ||
|
||
var latestPassword = | ||
ApplicationContext.getImplementation(DatabaseCredentialsProvider.class) | ||
.getPassword(); | ||
this.setPassword(latestPassword); | ||
|
||
return super.getConnection(); | ||
} | ||
|
||
@Override | ||
public Connection getConnection(String username, String password) throws SQLException { | ||
ApplicationContext.getImplementation(Logger.class) | ||
.logInfo("Establishing new connection to the database with a username"); | ||
|
||
var latestPassword = | ||
ApplicationContext.getImplementation(DatabaseCredentialsProvider.class) | ||
.getPassword(); | ||
this.setPassword(latestPassword); | ||
|
||
return super.getConnection(username, latestPassword); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters