Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonar "Credentials should not be hard-coded" Error

Tags:

java

sonarqube

In my application I have a ApplicationConstants.java class that serve for String Constants used in the application. I have public static final String PASSWORD = "password" as one of the constant. Sonar throws an error for that as below. Kindly let me know if there is a way to handle the same.

Sonar error: Description Assignee Resource New issue Credentials should not be hard-coded : Remove this hard-coded password. EnrollmentConstant.java false

like image 954
n n Avatar asked Oct 21 '16 12:10

n n


2 Answers

You should move the password to configuration.

like image 142
Danil Gaponov Avatar answered Oct 20 '22 03:10

Danil Gaponov


you should either extract it to properties file. Here you can read how to do it

You can also put it on application server as a system property and expect it to be present on production machine (Wildfly server for example) and then read it using System.getProperty(key). This complicates deployment a little bit, but production password will not be present in project.

If you use Spring you can load value to bean using @Value annotation. Here you can read how to do this.

like image 27
T.G Avatar answered Oct 20 '22 04:10

T.G