当我通过Spring部署Spring应用程序并访问localhost:8080时,我必须进行身份验证,但是用户名和密码是什么,或者如何设置呢?我试图将它添加到我的tomcat-users文件中,但是它没有工作:
<role rolename="manager-gui"/>
<user username="admin" password="admin" roles="manager-gui"/>这是应用程序的起点:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}这就是Tomcat的依赖性:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>如何在localhost:8080上进行身份验证
发布于 2016-05-18 01:36:34
我认为类路径上有Security,然后Spring安全性自动配置为默认用户和生成的密码
请查看您的pom.xml文件,以便:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>如果您的pom中有这样的内容,那么您应该有这样的日志控制台消息:
Using default security password: ce6c3d39-8f20-4a41-8e01-803166bb99b6
在浏览器提示符中,您将导入控制台中打印的用户user和密码。
或者,如果您想配置spring安全性,可以查看Spring Boot secured example
在Security部分的Spring参考文档中对此进行了解释,它指出:
The default AuthenticationManager has a single user (‘user’ username and random password, printed at `INFO` level when the application starts up)
Using default security password: 78fa095d-3f4c-48b1-ad50-e24c31d5cf35发布于 2017-10-06 13:11:28
如果在类路径中添加了spring-security jars,如果它是spring-boot应用程序,所有http端点都将在默认情况下受到安全配置类SecurityAutoConfiguration的保护。
这会导致浏览器弹出请求凭据。
每个应用程序的密码更改都会重新启动,可以在控制台中找到。
Using default security password: 78fa095d-3f4c-48b1-ad50-e24c31d5cf35若要在缺省值前面添加您自己的应用程序安全性层,
@EnableWebSecurity
public class SecurityConfig {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
}或者,如果您只想更改密码,您可以重写默认设置,
application.xml
security.user.password=new_password
或
application.properties
spring.security.user.name=<>
spring.security.user.password=<>发布于 2019-07-20 11:57:06
重写时
spring.security.user.name=
spring.security.user.password=在application.properties,中,您不需要"绕过"username",只需使用username即可。另一点,与其存储原始密码,不如用bcrypt/scrypt加密它,并将其存储为
spring.security.user.password={bcrypt}encryptedPasswordhttps://stackoverflow.com/questions/37285016
复制相似问题