简体   繁体   English

在不知道登录名和密码的情况下连接到数据库

[英]Connection to database without knowing of login and password

My project interacts with database (executes usual CRUD operations).我的项目与数据库交互(执行通常的 CRUD 操作)。 For connection to database I wrote login and password in application.properties:为了连接到数据库,我在 application.properties 中写了登录名和密码:

spring.datasource.username=root
spring.datasource.password=root

This approach works only if I work on my desktop with my account in mysql.仅当我使用 mysql 中的帐户在桌面上工作时,此方法才有效。

I want to transfer my project to another desktop with another account in mysql.我想用 mysql 中的另一个帐户将我的项目转移到另一个桌面。 I want the person who will get my project can run my app with one click, without writing his username/password in application.properties.我希望获得我项目的人可以一键运行我的应用程序,而无需在 application.properties 中写入他的用户名/密码。

I don't know the username and password of this person.我不知道这个人的用户名和密码。 So I cann't write its to application.properties.所以我不能把它写到application.properties。

I researched this problem and found this question: Start spring-boot app without depending on username and password for Database oracle?我研究了这个问题,发现了这个问题: Start spring-boot app without依赖于数据库oracle的用户名和密码?

The author of this question wants the person will pass authentication in web.此问题的作者希望此人将通过 web 中的身份验证。 But I want there won't necessity for person to enter any data except just run the program.但我希望人们不需要输入任何数据,只需运行程序即可。

Is there any way to achieve it?有没有办法实现它?

There are ways that you can use:您可以使用以下几种方法:

  1. The user has personal credentials on the database and needs to use them.用户在数据库上有个人凭据并且需要使用它们。 Here you can either request them at runtime or have them preconfigured in some properties file.在这里,您可以在运行时请求它们,也可以在某些属性文件中预先配置它们。 But it seems you do not like any of these scenarios.但似乎你不喜欢这些场景中的任何一个。
  2. The user may have personal credentials on the application but there is an application account for the database.用户可能在应用程序上有个人凭据,但数据库有一个应用程序帐户。 In this case the user logs on to your application, which can even connect to the database to verify the credentials.在这种情况下,用户登录到您的应用程序,它甚至可以连接到数据库以验证凭据。 Or the user does not have to authenticate on the application and can use it straight away.或者用户不必在应用程序上进行身份验证并且可以立即使用它。
  3. The user has the whole application running locally on his computer - regardless whether it is a web application or a fat client.用户在他的计算机上本地运行整个应用程序 - 无论它是 web 应用程序还是胖客户端。 In this case the user can directly edit the properties file on his computer and store the credentials.在这种情况下,用户可以直接在他的计算机上编辑属性文件并存储凭据。 Or alternatively enter them on the GUI so it stores the values on his behalf.或者在 GUI 上输入它们,以便它代表他存储值。

Any more scenarios to think of?还有什么场景可以考虑?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM