如何通过身份验证所需的Spring-boot安全性 [英] How to get past the Authentication Required Spring-boot Security
问题描述
我输入的密码是root,它会不断弹出。我怎么能抑制它或摆脱它。我正在使用弹簧靴和弹簧安全。
I have put in the password which is "root" and it keeps popping back up. How can I suppress this or get rid of it. I am using spring boot and spring security.
application.properties
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: /
如果重要的话,我正在使用intellij 14.
I am using intellij 14 if that matters.
----更新1 -----
----Update 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");
}
}
推荐答案
以下是问题
(1).loginPage(/ index)我说我的登录页面是索引,但是我只想使用spring的默认登录页面。
(1) .loginPage("/index") was saying my login page was at index, however I just wanted to use spring's default login page.
(2)必须将安全包移到demo包中(主要包)。感谢@Sanjay的建议。我尝试使用@ComponantScan,但无法使用它。
(2) had to to move the security package inside the demo package (the main package). Thanks to @Sanjay for suggesting that. I tried to use @ComponantScan but it could not get it to work.
这篇关于如何通过身份验证所需的Spring-boot安全性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!