java Spring安全性java配置 Posted 2021-05-07
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java Spring安全性java配置相关的知识,希望对你有一定的参考价值。
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
super.configure(web);
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().passwordEncoder(NoOpPasswordEncoder.getInstance()).withUser("user").password("password").roles("USER");
}
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.formLogin()
.and()
.httpBasic();
}
}
import SecurityConfiguration.class in rootcontextconfig
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
public class SpringSecurityInitializer extends AbstractSecurityWebApplicationInitializer{
}
以上是关于java Spring安全性java配置的主要内容,如果未能解决你的问题,请参考以下文章
Spring 安全 Java 配置
基于 Java 注解的 Spring 安全配置
如何使用 xml 配置文件、JAVA、Spring 安全性对 LDAP 用户进行身份验证
java spring boot安全配置
Spring安全认证提供者java配置
登录 Spring 安全重定向到错误 Thymeleaf 和基于 Java 的配置