Author Message
PeterTomovic
Joined: Jun 13, 2014
Messages: 66
Offline
Hi,

Our AAOD application uses connectivity to DB MSSQL, and it works fine.

Is there way how to store DB username/password directly on the application Tomcat server, not in the app. directory ($APP_HOME/WEB-INF/web.xml) ?

AAOD application stores DB username/password in exported war file (web.xml).

Versions
AAOD: 7.2.1.05.02
Tomcat: 8.5.23
Java: 1.8

thank you
Peter
WilsonYu
Joined: Nov 6, 2013
Messages: 3950
Offline
If you blank out the username in the web.xml, whatever you specify in Tomcat context should be used instead.
PeterTomovic
Joined: Jun 13, 2014
Messages: 66
Offline
I tried both: empty username and empty username|password -> negative result:

Login failed for user ''.

TOMCAT_HOME/conf/context.xml

<Context>

<Resource auth="Container"
driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"
factory="org.apache.tomcat.dbcp.dbcp2.cpdsadapter.DriverAdapterCPDS"
name="jdbc/VP_MSSQL_PRICPDS"
type="org.apache.tomcat.dbcp.dbcp2.cpdsadapter.DriverAdapterCPDS"
username="sa"
password="saSA10_"
url="jdbc:sqlserver://12.0.0.101\SQLSERVER;databaseName=VPDM;"/>
<Resource auth="Container"
dataSourceName="java:/comp/env/jdbc/VP_MSSQL_PRICPDS"
defaultMaxActive="10"
defaultMaxIdle="5"
defaultMaxWait="10000"
factory="org.apache.tomcat.dbcp.dbcp2.datasources.PerUserPoolDataSourceFactory"
logAbandoned="true" name="jdbc/VP_MSSQL_PRI"
removeAbandoned="true"
removeAbandonedTimeout="300"
testOnBorrow="false"
type="org.apache.tomcat.dbcp.dbcp2.datasources.PerUserPoolDataSource"
validationQuery="select 1 from AnyTable"/>

</Context>


1. empty username in the app. web.xml

APP_HOME/WEB-INF/web.xml

<context-param>
<param-name>dd.ds.VP_MSSQL_PRI</param-name>
<param-value>|p077P6Ug0xM=|com.microsoft.sqlserver.jdbc.SQLServerDriver</param-value>
<description>Datasource information</description>
</context-param>


trace.log

22/08/2019 20:16:46:240 DEBUG - A121EC95EFA26FF14C886865CC872BE5:/APP_TST_TOMCAT_DB : Executing DB statement : [INSERT INTO dbo.tab1 ( col1 ) VALUES ( ? )]
22/08/2019 20:16:46:375 ERROR - A121EC95EFA26FF14C886865CC872BE5:/APP_TST_TOMCAT_DB : channel:unknown |
EXCEPTION>
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user ''. ClientConnectionId:4821d084-f0d2-4d8e-8500-c25bb8e4fd4e
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)



2. empty both: username and password in the app. web.xml:

<context-param>
<param-name>dd.ds.VP_MSSQL_PRI</param-name>
<param-value>||com.microsoft.sqlserver.jdbc.SQLServerDriver</param-value>
<description>Datasource information</description>
</context-param>

trace.log:

22/08/2019 20:26:57:633 DEBUG - A121EC95EFA26FF14C886865CC872BE5:/APP_TST_TOMCAT_DB : Executing DB statement : [INSERT INTO dbo.tab1 ( col1 ) VALUES ( ? )]
22/08/2019 20:26:57:820 ERROR - A121EC95EFA26FF14C886865CC872BE5:/APP_TST_TOMCAT_DB : channel:unknown |
EXCEPTION>
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user ''. ClientConnectionId:84da0d3e-ac69-471d-8255-a0e05d3cefc5
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:254)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:84)
WilsonYu
Joined: Nov 6, 2013
Messages: 3950
Offline
You need to define the Resource similar the following:

<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxTotal="100" maxIdle="30" maxWaitMillis="10000"
username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest"/>

Please refer to the Tomcat doc:

https://tomcat.apache.org/tomcat-8.5-doc/jndi-datasource-examples-howto.html

Comment out the ones defined by OD.
PeterTomovic
Joined: Jun 13, 2014
Messages: 66
Offline
Thank you Wilson, it is working fine.

Peter
Go to:   
Mobile view