spring security 사용자 정의 데이터베이스 테이블 구조
3709 단어 필기 하 다.
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.authentication.AuthenticationManager;
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.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import javax.sql.DataSource;
/**
* .
*
*/
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
/**
*
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/css/**", "/js/**", "/static/fonts/**").permitAll() //
.antMatchers("/index","/").hasRole("ADMIN") //
.and()
.formLogin() // Form
.loginPage("/login").failureUrl("/login-error"); //
}
@Autowired
private DataSource dataSource;
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery("select userid,userpassword,enableflag "
+"from ftp_user where userid=?")
.authoritiesByUsernameQuery("select username, authority "
+"from authorities where username=?");
}
}
여기 dataSource 는 @ Autowired 주 해 를 추가 하여 주입 합 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Flutter 는 kotlin 프로젝트 에서 자바 방법 으로 데 이 터 를 제공 합 니 다.최근 안 드 로 이 드 프로젝트 를 쓸 때 다음 과 같은 문제 가 발생 했 습 니 다. Flutter 는 kotlin 프로젝트 에서 자바 방법 으로 데 이 터 를 제공 합 니 다. 이 수 요 는 정말 복잡 합 니 다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.