SPRING(34)
-
SPRING SEQURITY - Form Login 인증 흐름, AuthenticationFilter
로그인 요청을 한다. AuthenticationFilter가 요청을 받아, RequestMatcher를 생성해 요청 정보가 매칭되는지 확인한다. 요청정보가 매칭된다면 인증객체(Authentication)을 생성한다. AuthenticationManager에게 인증 객체를 이용해 인증 요청을 하고 AuthenticationManager는 AuthenticationProvider에게 인증 요청을 위임한다. AuthenticationProvider는 인증 객체를 분석하여 username, password를 보고 인증 성공 여부를 판단한다. 인증이 성공되면 AuthenticationManager는 인증객체를 새로 생성한다. 이 때, 인증객체는 사용자 정보와, 권한 정보를 가진다. 해당 인증객체를 Security..
2021.04.15 -
SPRING SEQURITY - Form Login 인증 API
사용 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 package io.security.basicsecurity; 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.WebSecurityConfig..
2021.04.15 -
Spring MVC - RedirectAttributes
RedirectAttributes 리다이렉트를 사용할 때 사용된다. PRG(Post/Redirect/Get)을 이용할 때, 화면을 재사용할 수 있다. 사용 예제 1 2 3 4 5 6 7 @PostMapping("/add") public String addItemV6(Item item, RedirectAttributes redirectAttributes) { Item savedItem = itemRepository.save(item); redirectAttributes.addAttribute("itemId", savedItem.getId()); redirectAttributes.addAttribute("status", true); return "redirect:/basic/items/{itemId}"; }..
2021.04.14 -
Spring MVC - 정적 리소스, 뷰 템플릿 경로
정적 리소스 경로 클래스패스: /src/main/resources 스프링 부트는 클래스패스의 다음 디렉토리에 있는 정적 리소스를 제공한다 /static /public /resources /META-INF/resources 예) /src/main/resources/static/basic/hello.html 에 리소스가 존재하는 경우, http://localhost:8080/basic/hello.html을 요청하면 된다. 뷰 템플릿 경로 뷰 템플릿 경로: /src/main/resources/templates @ResponseBody가 없으면 뷰 리졸버에 의해 뷰를 찾게 된다. 컨트롤러 메서드 리턴타입을 String으로 해서 뷰 논리 이름을 리턴하거나, ModelAndView 생성자의 인자로 뷰 논리 이름을 ..
2021.04.08 -
Spring MVC - Http 메시지 바디 요청, 응답 파싱
Http Get 메서드나 Form 미디어 타입으로 파라미터가 넘어오는 방식이 아닌, Http 메시지 바디로 요청, 응답하는 방법을 알아보자. 1. InputStream(Reader), OutputStream(Writer) 1 2 3 4 5 6 @PostMapping("/request-body-string-v2") public void requestBodyStringV2(InputStream inputStream, Writer responseWriter) throws IOException { String messageBody = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8); log.info("messageBody={}", messageBod..
2021.04.08 -
Spring MVC - 요청 파라미터, @RequestParam, @ModelAttribute
요청 파라미터 Http 통신에서 요청 파라미터가 넘어오는 경우가 두 가지가 있다. 1. Get 메서드로 쿼리 파라미터가 넘어오는 경우 예) www.naver.com/exp?username=yoon&age=33 2. Html의 Form태그를 통해 Http 메시지의 바디부분으로 들어오는 경우 쿼리 파라미터와 양식이 같다. 다만 URI뒤에 붙는게 아닌, http 메시지 바디에 들어가게 된다. 요청 파라미터 조회 HttpServletRequest 서블릿처럼 HttpServletRequest를 인자로 받아 request.getParameter()를 이용해 파라미터를 조회할 수 있다. @RequestParam HttpServletRequest를 사용하지 않고 파라미터를 조회할 수 있다. 예) @RequestPara..
2021.04.07