4

I've special characters such as " (doublequotes), @, ~, !, %, &, }, ] in the datasource password field. When I run my springboot app and when it attempts to connect to the database I run into -

com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "problem accessing trust store"
Caused by: java.security.KeyStoreException: problem accessing trust store
Caused by: java.io.IOException: Keystore was tampered with, or password was incorrect
Caused by: java.security.UnrecoverableKeyException: Password verification failed

My questions are :
(1) Is there a way to view what password is Spring using to attempt the connection?
(2) Do I need to escape any of the special characters in the password in the application.properties?

I was able to connect to the database using a standalone java program but I had to escape the double quotes in the password. I'm using Springboot-2.0.4, Flyway-5.2.4, jdk 1.8 and MS-SQL server on the backend.

Thanks.

linuxNoob
  • 600
  • 2
  • 14
  • 30

1 Answers1

9

application.properties: No escaping is required for your specified characters.

If you use e.g. a backslash, you'd need to escape it with another backslash, like so: C:\\Development\\mydir

application.yml: Surround value with " and escape embedded " like this \"

Note: application.yml is outside question from OP. Use either application.properties or application.yml, not both.

Tested and verified with this entry in application.properties

myapp.entry-with-special-characters=@~!%&=""

And tested again with this entry in application.yml

myapp:
  entry-with-special-characters: "@~!%&=\"\""

Output value to console like this (put code inside e.g. class annotated with @SpringBootApplication, will run when application starts)

@Bean
public CommandLineRunner propertiesTest(@Value("${myapp.entry-with-special-characters}") String myVal) {
    return args -> System.out.printf("Test-output for StackOverflow: %s\n", myVal);
}

With Flyway, try this instead

/**
 * Override default flyway initializer to do nothing
 */
@Bean
FlywayMigrationInitializer flywayInitializer(Flyway flyway, @Value("${myapp.entry-with-special-characters}") String myVal) {
    System.out.printf("Test-output for StackOverflow: %s\n", myVal);
    return new FlywayMigrationInitializer(flyway, (f) ->{} );
}

Spring Boot: Hibernate and Flyway boot order

enter image description here

Answer to the question

Is there a way to view what password is Spring using to attempt the connection?

can be to replace the key myapp.entry-with-special-characters in the above bean with relevant key from application.properties. Please keep in mind that passwords are secrets.

Environment used during testing:

  • Spring Boot 2.4.1
  • JDK 14.0.2
  • Windows 10 Home
Roar S.
  • 8,103
  • 1
  • 15
  • 37