⭐️ login 인증과 그 후 Request 요청에 따른 검증은 다름!!!
1. login 인증이 되면 인증이 되었다는 토큰을 받음
2. 그 토큰을 client 에서 가지고 있다가, 요청이 들어오면
3. 토큰과 함께 들어온 request 요청을 그때 비교 검증을 함.
4. 검증 완료가 되면 Security Context 에 Authentication 을 저장함.
@Component
UserDetatilService 에 안 달면. 자동으로 inmemory 를 씀. 안에 구현되어 있는 user 를 사용함.
Authentication 으로 검증하는 로직을 만들기.
DB로 접근하지 않고, Authentication 으로 로직을 만들 수 잇음.
Authentication 은 principal 과 authorities 를 가지고 있음.
1. Authentication 을 받아서 get principal > Email 이니까.
2. 이걸로 member 를 가지고 와서
3. 이 멤버가 board 의 member 와 같은지 확인.
4. 아니면 exception 코드 던지기.
// 내가 만든 질문이 맞나요?? 검증.
member.getEmail().equals(authentication.getPrincipal())
// 너는 admin 이니? 검증.
authentication.getAuthorities().contains(new SimpleGrantedAuthority("ROLE_ADMIN"))
'Project > Coffee Board' 카테고리의 다른 글
[Coffee Board] 게시판 구현 4 - 비밀글 공개글 (0) | 2024.07.19 |
---|---|
[Coffee Board] 게시판 구현 2 - 좋아요(Like) 기능 (1) | 2024.07.17 |
[Coffee Board] 게시판 구현 1 - @Mapper (0) | 2024.07.17 |