How to connect from plugin (script runner) do database with current context without credentials

Rafał Żydek December 12, 2021

We have Confluence DC (2 nodes) with direct connection do database (without DS) defined in server.xml.

 

We want to from script runner (console) get current connected and read / write some information to database without providing credentials. We know that they are resources to define, but for Jira we was able to read current APP context and do the db query directly. We don't won't multiple places where password is stored. Can anyone help mi wi this? Probably the same way is implemented in every custom plugin developed for confluence, to have ability to read database.

1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 12, 2021

No, you absolutely do not want to do this.

You must not write to an Atlassian application's database, because you will break it.  Never do that.

As for how you use scripts to read a database, it's the same for every application, so do whatever it is you did for the Jira scripts that read your database.

Rafał Żydek December 12, 2021

On Jira I've use something like that, are you able to help me use the same code in Confluence?

 


import com.atlassian.core.ofbiz.CoreFactory;
import org.ofbiz.core.entity.*;
import java.sql.Connection;
import com.atlassian.jira.component.ComponentAccessor;
import groovy.sql.Sql;
GenericDelegator delegator = CoreFactory.getGenericDelegator();
String helperName = delegator.getGroupHelperName("default");
Connection conn = ConnectionFactory.getConnection(helperName);
def sql = new Sql(conn);
def rows = sql.rows('SELECT "ID", "SAVED_FILTER_ID" FROM "AO_60DB71_RAPIDVIEW"');

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events