본문 바로가기
반응형

프로그래밍/Spring71

BCrypt알고리즘 해시로 만든 암호 BCrypt알고리즘 해시로 만든 암호 BCrypt암호 생성 방법. BCrypt알고리즘은 난수를 사용하므로 항상 다른 결과가 나온다. GenPassword.javaimport org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; public class GenPassword {public static void main(String[] args) {System.out.printf(new BCryptPasswordEncoder().encode("demo")); }} 하나의 프로젝트에 main() 메서드가 여러개 있으면 mvn spring-boot:run명령을 실행할 때 플러그인이 어떤 main() 메서드를 실행해야 할지 판단할 수 없게 된다. 따라.. 2019. 4. 25.
@AuthenticationPrincipal userDetail를 사용하는 예제 @AuthenticationPrincipal userDetail를 사용하는 예제 로그인 상태에서 사용자 정보를 사용하는 예제이다. RequestMapping에서부터 간단한 이용 방법을 보자. ...@RequestMapping(value = "create", method = RequestMethod.POST) String create(@Validated CustomerForm from, BindingResult result, Model model, @AuthenticationPrincipal LoginUserDetails userDetails) {if (result.hasErrors()) {return list(model)}Customer customer = new Customer(); BeanUtils... 2019. 4. 25.
WebSecurity configure WebSecurity configure 몇 주전 오만상을 쓰며 만들던 스프링 시큐리어티로 웹 로그인 기능에 대해 어제 비로소 감을 조금 잡았다. 아직 완전한건 아니지만... 짬짬히 조금씩 각 부분별로 정리를 해서 포스팅을 올릴 생각이다. @EnableWebMvcSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter {@Override public void configure(WebSecurity web) throws Exception {web.ignoring().antMatchers("/css/**", "/images/**");}...} 오버라이드된 configure는 (WebSecurity) 메서드를 오버라이드해서 특정 요청에 .. 2019. 4. 25.
@RequestMapping의 params @RequestMapping의 params 참 다양한 속성들을 지니고 있는 @RequestMapping 애너테이션이다. URL의 파라미터 매칭까지 가능하도록 다음과 같이 사용할 수 있다. @RequestMapping(value="edit", params="goToTop") public String goToTop() { return "redirect:/customers"; } 요청 파라미터에 goToTop이 포함되어 있으면 목록 표시 화면으로 리다이렉트하는 메서드를 준비한다. 2019. 4. 23.
@ModelAttribute와 @Validated를 이용한 Form요소 전달 예제 @ModelAttribute와 @Validated를 이용한 Form요소 전달 예제 예전에는 Request.Get, Request.Post를 통해 html의 폼 요소를 일일이 받아서 변수에 담아 개발을 하던 시절이 있었다. 엄청난 노가다성 코딩이 필수불가 사항이었던 시절인데 요즘 스프링을 하면서 참 좋아진 세상이란걸 느끼고 있다. 다양한 애너테이션을 통해 효율적인 프로그래밍이 가능해졌기 때문이다. @ModelAttribute를 이용한 폼 요소 처리 예제를 정리해본다. @ModelAttribute CustomerForm setUpForm() {return new CustomerForm();} @RequestMapping(method = RequestMethod.GET) public String list(Mo.. 2019. 4. 19.
스프링 MVC Location 헤더에 리소스URI 설정 예제 스프링 MVC Location 헤더에 리소스URI 설정 예제 본 예제는 JpaRepository를 사용해서 save()메서드 후 추가된 사용자에 대한 id를 반환해서 추가된 사용자 정보가 제대로 들어갔는지 확인하는 페이지로 이동할 URI를 만들어주기 위한 예제인데 자바의 URI와 UriComponentBuilder를 이용해서 HttpHeaders에 추가하는 예제이다. @RestController @RequestMapping("api/customers") public class CustomerRestController {...@RequestMapping(method = RequestMethod.POST) ResponseEntitypostCustomers(@RequestBody Customer custome.. 2019. 4. 19.
반응형