Spring Security-WebSecurityConfigurerAdapter
10962 단어 Spring-Boot
WebSecurity ConfigurerAdapter 에서 proctected void configure (AuthenticationManager Builder auth) 를 재 작성 하여 Inmemory, LDAP, JDBC 방식 의 인증 을 실현 하 는 동시에 SpringBoot 는 기본 Login 인터페이스 (DefaultLoginPageConfigurer < > () 를 제공 합 니 다.
HttpSecurity
WebSecurity ConfigurerAdapter 에서 protected void configure (HttpSecurity http) 재 작성 을 통 해 CORS 를 구현 하고 로그 인 / 로그아웃 인터페이스 를 사용자 정의 합 니 다. 인증 등 사용자 정의 설정 기능 이 기본 으로 지정 되 어 있 는 지 여부 입 니 다.
http
.authorizeRequests().anyRequest().authenticated() // request
.and()
.formLogin() // login
.and()
.httpBasic(); // Basic
CORS
영문 전 칭;CORS (Cross - Origin Resource Sharing) 는 원본 자원 을 넘 어 공유 하고 신뢰 하 는 웹 사이트 에 대한 크로스 도 메 인 접근 권한 을 제공 합 니 다. 어떤 크로스 도 메 인 요청 이 Spring Security 5 의 기본 적 인 유효 CORS 를 유연 하 게 지정 하여 안전 한 외부 방문 허용 을 실현 할 수 있 습 니 다.참조Security-CORS
Spring MVC 에서 도 CORS 의 크로스 도 메 인 설정 참조 가 제공 되 었 습 니 다.MVC-CORS
CSRF
참조SpringSecurity-CSRF
Login / Logout
자신의 로그 인 인터페이스 와 로그 인 성공 후의 점프 페이지 를 사용자 정의 합 니 다.참조FreeMaker 또는 Thymeleaf 2. X 시 리 즈 를 사용 하면 절차;
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
spring.thymeleaf.prefix: classpath:/templates/
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
<script src="https://cdn.bootcss.com/jquery/2.1.0/jquery.min.js">script>
<script type="text/javascript">
function crosRequest(){
$.ajax({
url:'http://localhost:1234/sendmessage',
type:'get',
dataType:'json',
success:function(data){
console.log(data);
}
});
}
script>
head>
<body>
<button onclick="crosRequest()">crosRequestbutton>
body>
html>
@Controller
public class sampleController {
@RequestMapping("/hello")
public String getHello(HashMap<String, Object> map) {
map.put("hello", "Welcom Page.");
return "/test";
}
}
http://localhost:xxxx/hello
WebSecurity ConfigurerAdapter 에서 proctected void configure (WebSecurity http) 를 다시 써 서 지정 한 경로 의 접근 제어 기본 빈 장 치 를 실현 합 니 다.
@Override
public void configure(WebSecurity http) throws Exception {
// Remove monitoring path from SpringSecurity。
http.ignoring().antMatchers("/api/**");
}