Dre*_*208 18 intellij-idea spring-security spring-boot
我输入了"root"密码,它不断弹出.我怎么能抑制它或摆脱它.我正在使用弹簧靴和弹簧安全.
application.properties
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/springbootpractice
spring.datasource.username=root
spring.jpa.database = MYSQL
spring.jpa.show-sql = true
# Hibernate
hibernate.dialect: org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql: true
hibernate.hbm2ddl.auto: update
entitymanager.packagesToScan: /
Run Code Online (Sandbox Code Playgroud)
如果重要的话,我正在使用intellij 14.
----更新1 -----
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/index").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/index")
.permitAll()
.and()
.logout()
.permitAll();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/index").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/index")
.permitAll()
.and()
.logout()
.permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
}
Run Code Online (Sandbox Code Playgroud)
ACV*_*ACV 31
该类必须位于所有其他包的父包中:
WebSecurityConfig.同样在application.properties集合中:
security.basic.enabled=false
Run Code Online (Sandbox Code Playgroud)
B.M*_*.W. 18
ACV的答案可能是通过添加security.basic.enabled=false通常位于src/main/resources文件夹下的application.properties文件来完全关闭身份验证的最简单方法.
当您运行spring应用程序时,通常会打印一大堆日志记录,人们通常不会阅读.密码实际上是在启动时生成并打印到屏幕上的.用户名很简单user.如果您正在使用浏览器进行测试,并且可能只需要输入一次并将其缓存,那么一旦完成,您应该安全地登录,而无需每次都进行身份验证.(但是,每次重新启动应用程序时,都会生成一个新密码)
如果要自定义用户名和密码,请将以下属性添加到application.properties:
security.user.name=myuser
security.user.password=mypassword
Run Code Online (Sandbox Code Playgroud)
以下是您使用自己的用户名和密码的样子
参考:
这是问题所在
(1) .loginPage("/index") 说我的登录页面位于索引处,但是我只想使用 spring 的默认登录页面。
(2) 必须将安全包移至演示包(主包)内。感谢@Sanjay 的建议。我尝试使用@ComponantScan,但它无法使其工作。
| 归档时间: |
|
| 查看次数: |
18384 次 |
| 最近记录: |