분류 전체보기 439

[프로젝트] 인터셉터로 에러 처리 시 파일 리턴하기

인터셉터를 이용해 /s가 붙은 주소의 요청을 받으면 인증 체크를 손쉽게 했었다. // CustomApiException package site.metacoding.everytimeclone.handler.ex; public class CustomApiException extends RuntimeException { public CustomApiException(String message) { super(message); } } // CustomException package site.metacoding.everytimeclone.handler.ex; public class CustomException extends RuntimeException { public CustomException(String m..

[프로젝트] JPA 페이징 + 검색기능 구현 (fetch)

https://github.com/jaewon2336/jpa-paging-search GitHub - jaewon2336/jpa-paging-search Contribute to jaewon2336/jpa-paging-search development by creating an account on GitHub. github.com 1. 글 목록을 뿌리기 위한 간단한 화면 구현 mustache 템플릿 엔진 사용 Everytime Home logout 검색 번호 제목 내용 작성일 새글쓰기 이전 다음 2. 엔티티 생성 테스트를 위한 엔티티이기 때문에 자세한 설정은 하지 않았다. package site.metacoding.pagingsearch.domain; import java.time.LocalDateTim..

블로그-V3. 시큐리티 로그인 프로세스

1. 스프링 시큐리티는 /login (POST) 주소로 요청이 들어오면 로그인 프로세스가 자동 진행된다. /login은 정해진 주소이고, GET 요청은 안 받아준다!! 2. 스프링 시큐리티는 /login 요청이 올 때 Body를 확인하는데, x-www-form-urlencoded만 확인한다. 즉, Json 테이터는 받지 않는다! 3. 1번과 2번을 BasicAuthenticationFilter가 진행하여 클라이언트의 요청을 받아 x-www-form-urlencoded 타입을 파싱 해주는데 두 가지 키 값만 체킹 한다. username과 password!! 우리 DB에서 username을 user, password를 pw라고 지정해주면 시큐리티가 인식하지 못한다. 이때 변경하고 싶다면 SecurityCon..

Spring/Tistory 2022.04.13

블로그-V3. 시큐리티 필터

시큐리티 설정 파일에 의해 /s 주소가 앞에 붙은 요청은 모두 로그인 화면으로 이동하게 된다. package site.metacoding.blogv3.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springfram..

Spring/Tistory 2022.04.12

블로그-V3. 시큐리티 암호 해시화

유효성 검사라는 부가적인 로직을 처리했으니 핵심 로직을 처리해준다. @PostMapping("/join") public String join(@Valid JoinReqDto joinReqDto, BindingResult bindingResult) { // 회원가입 로직에서 유효성 검사 코드는 부가적인 코드!! -> AOP if (bindingResult.hasErrors() == true) { // 하나라도 오류가 있다면 true Map errorMap = new HashMap(); for (FieldError fe : bindingResult.getFieldErrors()) { // System.out.println(fe.getField()); // 어느 변수에서 오류가 났는지 알려줌 // System..

Spring/Tistory 2022.04.11

블로그-V3. Validation검사, Exception 처리

Validation이라는 라이브러리를 사용해 유효성 검사를 해주자. Blog-V2에서 if로 직접 null 체크했던 과정을 Validation 라이브러리가 해주는 것이다. 아주 간편하다. 체크 후 오류가 있는지 없는지 확인하는 건 따로 해줘야 한다. 나중에 해보자. @PostMapping("/join") public String join(@Valid JoinReqDto joinReqDto, BindingResult bindingResult) { System.out.println(bindingResult.hasErrors()); // 하나라도 오류가 있다면 true return "redirect:login-form"; } 실행 시에 @Valid가 붙어있는 JoinReqDto를 확인해보고, 자신의 어노테이션..

Spring/Tistory 2022.04.11

블로그-V3. 빌더 패턴

이제 시큐리티 사용해서 회원가입 기능을 만들어보자 1. 프론트에서 막아준다. maxlength, required!! form 태그로 요청할 수 있는데 굳이 ajax를 사용할 필요 없다! form 태그로 요청하면 타입은 x-www-form-urlencoded!! 회원가입할 때 컨트롤러에서 받을 값은 3개(username, password, email), 유저 오브젝트로는 3개 값만 받을 수 없으니까 Dto를 만들어준다. 회원가입을 할 때 서버 입장에서 필요한 건 요청받는 Dto이다. 이름을 joinReqDto라고 만들자. Req는 Request의 약자이다. Dto에서 엔티티로 변환하는 방법을 알아보자. 1. 생성자로 만들어서 넣는 방법 -> 인수를 넣어주는 순서가 중요! public class JoinRe..

Spring/Tistory 2022.04.11

블로그-V3. drawer

https://git.blivesta.com/drawer/ Drawer Flexible drawer menu using jQuery, iScroll and CSS. git.blivesta.com 제이쿼리 링크는 이미 있으니까 구분해서 지워주자. css링크는 제일 밑에 있는 링크가 우선시 되기 때문에 내 css 링크를 제일 아래 적어주자. 문서에 나와있는 사용법을 참고해 테스트를 먼저 해준다음 블로그로 가져가자. toggle navigation Brand Nav1 Nav2 [출처] https://cafe.naver.com/metacoding 메타코딩 : 네이버 카페 코린이들의 궁금증 cafe.naver.com 메타 코딩 유튜브 https://www.youtube.com/c/%EB%A9%94%ED%83%80..

Spring/Tistory 2022.04.11

블로그-V3. css 분리

부트스트랩 4 버전을 사용할 것이다. 5는 리액트를 위해 만들어진 것이다. 공통적인 css는 따로 빼주고 색깔 관련 css도 따로 빼주는 게 보기 좋다. css 파일에 @import가 가능해서 연결할 수 있다. 이제 헤더에는 styles.css 링크만 붙여주면 되겠다. 위젯 단위로 디자인 클래스를 만들고 컴포넌트로 묶어서 클래스로 만들자. 이미 만들어둔 클래스를 다른 파일에서 재사용이 안된다. 그래서 나온 게 SASS(Syntactically Awesome Style Sheets)!! 지금은 재사용할 수 없으니까 다시 지정해줘야 한다. 대신 컴포넌트로 묶어서 한방에 지정해주자. 해당 컴포넌트가 재사용이 되는지 잘 생각하고 재사용이 되면 위젯 여러 개를 컴포넌트에 하나로 만들어주고, 재사용되지 않으면 위젯..

Spring/Tistory 2022.04.11