Skip to content

Commit

Permalink
Remove setup from Postgresql realm authentication
Browse files Browse the repository at this point in the history
The realm should not modify the user database but it has to be provided
and configured in advance.
However, if a file is provided it is used during the initialisation and
not during the authentication.
  • Loading branch information
fmarco76 committed Sep 25, 2024
1 parent 33a139a commit 5f645bc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
23 changes: 23 additions & 0 deletions base/est/shared/realm/postgresql/create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CREATE TABLE "users" (
"id" VARCHAR PRIMARY KEY,
"full_name" VARCHAR,
"password" VARCHAR
);

CREATE TABLE "user_certs" (
"user_id" VARCHAR NOT NULL,
"cert_id" VARCHAR NOT NULL,
"data" BYTEA,
PRIMARY KEY ("user_id", "cert_id")
);

CREATE TABLE "groups" (
"id" VARCHAR PRIMARY KEY,
"description" VARCHAR
);

CREATE TABLE "group_members" (
"group_id" VARCHAR NOT NULL,
"user_id" VARCHAR NOT NULL,
PRIMARY KEY ("group_id", "user_id")
);
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,27 @@ public void initInternal () throws LifecycleException {
if (saltLength != null) {
handler.setSaltLength(Integer.parseInt(saltLength));
}

String createFile = info.getProperty("dbcreate.file");
if (createFile != null) {
try{
connect();
setup(createFile);
} catch (Exception e) {
throw new LifecycleException("DB creation failed. Creation file: " + createFile, e);
}
}

}

/**
* This method will create the tables if they do not exist.
*/
public void setup() throws Exception {
public void setup(String createFile) throws Exception {

logger.info("Setting up PostgreSQL realm");

String filename = "/usr/share/pki/acme/realm/postgresql/create.sql";
String content = new String(Files.readAllBytes(Paths.get(filename)));
String content = new String(Files.readAllBytes(Paths.get(createFile)));

String[] stats = content.split(";");
for (String sql : stats) {
Expand Down Expand Up @@ -169,7 +179,6 @@ public void connect() throws Exception {
if (connection == null) { // create the initial connection
logger.info("Connecting to " + url);
connection = DriverManager.getConnection(url, info);
setup();
return;
}

Expand Down

0 comments on commit 5f645bc

Please sign in to comment.