Skip to content

Commit aa75851

Browse files
committed
fix: unique idp entity id
1 parent 1997889 commit aa75851

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/main/java/io/supertokens/storage/postgresql/Start.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4439,13 +4439,21 @@ public void deleteExpiredGeneratedOptions() throws StorageQueryException {
44394439

44404440
@Override
44414441
public SAMLClient createOrUpdateSAMLClient(TenantIdentifier tenantIdentifier, SAMLClient samlClient)
4442-
throws StorageQueryException {
4442+
throws StorageQueryException, io.supertokens.pluginInterface.saml.exception.DuplicateEntityIdException {
44434443
try {
44444444
return SAMLQueries.createOrUpdateSAMLClient(this, tenantIdentifier, samlClient.clientId, samlClient.clientSecret,
44454445
samlClient.ssoLoginURL, samlClient.redirectURIs.toString(), samlClient.defaultRedirectURI,
44464446
samlClient.idpEntityId, samlClient.idpSigningCertificate,
44474447
samlClient.allowIDPInitiatedLogin, samlClient.enableRequestSigning);
44484448
} catch (SQLException e) {
4449+
if (e instanceof PSQLException) {
4450+
PostgreSQLConfig config = Config.getConfig(this);
4451+
ServerErrorMessage serverMessage = ((PSQLException) e).getServerErrorMessage();
4452+
4453+
if (isUniqueConstraintError(serverMessage, config.getSAMLClientsTable(), "idp_entity_id")) {
4454+
throw new io.supertokens.pluginInterface.saml.exception.DuplicateEntityIdException();
4455+
}
4456+
}
44494457
throw new StorageQueryException(e);
44504458
}
44514459
}

src/main/java/io/supertokens/storage/postgresql/queries/SAMLQueries.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public static String getQueryToCreateSAMLClientsTable(Start start) {
5757
+ "updated_at BIGINT NOT NULL,"
5858
+ "CONSTRAINT " + Utils.getConstraintName(schema, tableName, null, "pkey")
5959
+ " PRIMARY KEY(app_id, tenant_id, client_id),"
60+
+ "CONSTRAINT " + Utils.getConstraintName(schema, tableName, "idp_entity_id", "key")
61+
+ " UNIQUE (app_id, tenant_id, idp_entity_id),"
6062
+ "CONSTRAINT " + Utils.getConstraintName(schema, tableName, "app_id", "fkey") + " "
6163
+ "FOREIGN KEY(app_id) "
6264
+ "REFERENCES " + Config.getConfig(start).getAppsTable() + " (app_id) ON DELETE CASCADE,"

0 commit comments

Comments
 (0)