Security and modernization improvements#1257
Closed
renechoi wants to merge 1 commit intoOpenFeign:masterfrom
renechoi:security/fix-hardcoded-credentials-and-deprecated-reflection
Closed
Security and modernization improvements#1257renechoi wants to merge 1 commit intoOpenFeign:masterfrom renechoi:security/fix-hardcoded-credentials-and-deprecated-reflection
renechoi wants to merge 1 commit intoOpenFeign:masterfrom
renechoi:security/fix-hardcoded-credentials-and-deprecated-reflection
Conversation
- Replace hardcoded database credentials with system properties in test files - Replace deprecated Class.newInstance() with Class.getDeclaredConstructor().newInstance() - Improve security by allowing credential configuration via environment variables - Modernize reflection API usage to use non-deprecated methods 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This pull request addresses two critical issues identified during a comprehensive security and modernization audit of the QueryDSL codebase:
Class.newInstance(), which has been deprecated since Java 9.These changes significantly enhance the security posture and maintainability of the code while ensuring full backward compatibility.
🔒 Security Enhancement: Externalize Credentials
The Problem
Hardcoded database credentials within test classes posed several risks:
The Solution
All hardcoded credentials have been replaced with a system property-based configuration, falling back to the original default values if no properties are set.
Before:
After:
Benefits
Configuration Examples
Credentials can now be supplied via JVM system properties:
-Dmysql.username=testuser -Dmysql.password=testpass-Dpostgresql.username=pguser -Dpostgresql.password=pgpass-Dsqlserver.username=sa -Dsqlserver.password=SecurePassword123☕ Code Modernization: Update Reflection API
The Problem
The use of
Class.newInstance()is outdated and has several drawbacks:InstantiationExceptionandIllegalAccessException, hiding the underlying cause of failure.The Solution
All calls have been updated to the modern reflection API,
getDeclaredConstructor().newInstance(), which resolves these issues.Before:
After:
Improvements
NoSuchMethodExceptionandInvocationTargetException.📂 Files Modified
Test Connection Classes
querydsl-sql/src/test/java/com/querydsl/sql/Connections.javaquerydsl-r2dbc/src/test/java/com/querydsl/r2dbc/Connections.javaCore Reflection Usage
querydsl-core/src/main/java/com/querydsl/core/types/QBean.javacreate()method with proper exception handling and mapping.querydsl-jpa/src/main/java/com/querydsl/jpa/HQLTemplates.javaquerydsl-jpa/src/main/java/com/querydsl/jpa/EclipseLinkTemplates.javaquerydsl-r2dbc/src/main/java/com/querydsl/r2dbc/JavaTypeMapping.java✅ Verification & Compatibility
Testing
Backward Compatibility
This change is 100% backward compatible:
Migration Path
To use secure, externalized credentials:
mvn test -Dmysql.username=dev_user -Dmysql.password=dev_pass-Dflags to the VM options of your test runner configuration.