从 属性 文件中保护数据库凭据的正确方法
Proper way of Securing Database credentials from a property file
I have a Database Connection class which accesses the database credentials from a property file located at src/main/resources.
**DBconfig.properties** (property file)
DB.url=jdbc:mysql://localhost:3306/studentdb
DB.username=root
DB.password=root
我的连接 class 是这样的(位于 src/main/java),
public class DBconnect {
private static String resources="DBconfig.properties";
private static Connection con = null;
private static String url = null;
private static String username = null;
private static String password = null;
public static void main(String[] args) {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Properties prop = new Properties();
try {
InputStream rs = loader.getResourceAsStream(resources);
prop.load(rs);
url = prop.getProperty("DB.url");
username = prop.getProperty("DB.username");
password = prop.getProperty("DB.password");
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url,username,password);
System.out.println("Database is Connected");
} catch (Exception e) {
System.out.println("Database is Not Connected");
e.printStackTrace();
}
}
}
我的问题是我的凭据在 属性 文件中以明文形式提供,我是否正确保护了我的凭据?它以我已经实施的方式安全吗?我需要做些什么来让它变得更好吗?,这是一个使用 weblogic 应用服务器的 Spring MVC 应用程序。谢谢
您可以使用 Jasypt,这样您就可以将它们以加密形式存储在属性文件中。
虽然它们是加密存储的,但如果您弄乱了 RAM,您可能可以访问它们(因为连接字符串有时会存储在 RAM 中)。更安全的保护自己的方法是使用数据库中的角色、过程和视图。
例如:不允许该用户创建新表,select他想要什么,只允许他检索一些视图,如果您想检查登录凭据,请使用程序...
最后,最安全的选择是使用服务器并通过服务器进行所有操作。
I have a Database Connection class which accesses the database credentials from a property file located at src/main/resources.
**DBconfig.properties** (property file)
DB.url=jdbc:mysql://localhost:3306/studentdb
DB.username=root
DB.password=root
我的连接 class 是这样的(位于 src/main/java),
public class DBconnect {
private static String resources="DBconfig.properties";
private static Connection con = null;
private static String url = null;
private static String username = null;
private static String password = null;
public static void main(String[] args) {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Properties prop = new Properties();
try {
InputStream rs = loader.getResourceAsStream(resources);
prop.load(rs);
url = prop.getProperty("DB.url");
username = prop.getProperty("DB.username");
password = prop.getProperty("DB.password");
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url,username,password);
System.out.println("Database is Connected");
} catch (Exception e) {
System.out.println("Database is Not Connected");
e.printStackTrace();
}
}
}
我的问题是我的凭据在 属性 文件中以明文形式提供,我是否正确保护了我的凭据?它以我已经实施的方式安全吗?我需要做些什么来让它变得更好吗?,这是一个使用 weblogic 应用服务器的 Spring MVC 应用程序。谢谢
您可以使用 Jasypt,这样您就可以将它们以加密形式存储在属性文件中。
虽然它们是加密存储的,但如果您弄乱了 RAM,您可能可以访问它们(因为连接字符串有时会存储在 RAM 中)。更安全的保护自己的方法是使用数据库中的角色、过程和视图。
例如:不允许该用户创建新表,select他想要什么,只允许他检索一些视图,如果您想检查登录凭据,请使用程序...
最后,最安全的选择是使用服务器并通过服务器进行所有操作。