当我通过 Spring Boot 部署 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
?
我认为您的类路径上有 Spring Security,然后 Spring Security 会自动配置默认用户和生成的密码
请查看您的 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 security 你可以看看Spring Boot 安全示例 https://github.com/spring-projects/spring-boot/blob/master/spring-boot-samples/spring-boot-sample-secure
Spring Boot 中有解释参考文档 in the Security http://docs.spring.io/spring-boot/docs/1.4.0.RELEASE/reference/htmlsingle/#boot-features-security部分,它表示:
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)