#1
This guide shows how to secure Derby database connections in a Spring Boot application using authentication and SSL configuration.

1. Add Dependencies

In pom.xml:
<dependency>
  <groupId>org.apache.derby</groupId>
  <artifactId>derby</artifactId>
  <scope>runtime</scope>
</dependency>

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

2. Enable Authentication in Derby

Start Derby with authentication enabled:
java -Dderby.connection.requireAuthentication=true \
     -Dderby.user.appuser=apppass \
     -jar $DERBY_HOME/lib/derbyrun.jar server start
This enforces username/password for connections.

3. Configure Spring Boot Credentials

In application.properties:
spring.datasource.url=jdbc:derby://localhost:1527/secureDB;create=true
spring.datasource.driver-class-name=org.apache.derby.jdbc.ClientDriver
spring.datasource.username=appuser
spring.datasource.password=apppass
spring.jpa.hibernate.ddl-auto=update

4. Enable SSL Connections

Start Derby with SSL:
java -Dderby.drda.sslMode=peerAuthentication \
     -Djavax.net.ssl.keyStore=keystore.jks \
     -Djavax.net.ssl.keyStorePassword=changeit \
     -jar $DERBY_HOME/lib/derbyrun.jar server start
Update Spring Boot to connect via SSL:
spring.datasource.url=jdbc:derby://localhost:1527/secureDB;ssl=basic

5. Use Encrypted Properties

Instead of storing passwords in plain text, use environment variables:
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PASS}
Run with:
export DB_USER=appuser
export DB_PASS=apppass
mvn spring-boot:run

6. Test Secure Connection

Spring Boot will now connect to Derby only with valid credentials and SSL enabled, protecting data during transmission.

image quote pre code