New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
7주차 과제 - Spring Security 인가(Authorization) 구현하기 #74
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오래간만입니다!
app/src/main/java/com/codesoom/assignment/config/SecurityJavaConfig.java
Outdated
Show resolved
Hide resolved
app/src/main/java/com/codesoom/assignment/controllers/ProductController.java
Outdated
Show resolved
Hide resolved
app/src/main/java/com/codesoom/assignment/filters/AuthenticationErrorFilter.java
Outdated
Show resolved
Hide resolved
app/src/test/java/com/codesoom/assignment/controllers/UserControllerTest.java
Outdated
Show resolved
Hide resolved
app/src/test/java/com/codesoom/assignment/controllers/UserControllerTest.java
Outdated
Show resolved
Hide resolved
app/src/main/java/com/codesoom/assignment/controllers/ControllerErrorAdvice.java
Outdated
Show resolved
Hide resolved
app/src/test/java/com/codesoom/assignment/controllers/UserControllerTest.java
Outdated
Show resolved
Hide resolved
app/src/main/java/com/codesoom/assignment/filters/JwtAuthenticationFilter.java
Outdated
Show resolved
Hide resolved
app/src/test/java/com/codesoom/assignment/controllers/ProductControllerTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
잘 해나가고 계신 것 같습니다. 화이팅!
import java.io.IOException; | ||
import java.util.Set; | ||
|
||
public class JwtAuthenticationFilter extends BasicAuthenticationFilter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 클래스의 용도와 기능을 JavaDoc으로 작성해 주세요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d803878
이렇게 작성해 봤습니다 ㅎㅎ
현재 과제에서는 Bearer
scheme과 JWT를 사용하고 있는데 BasicAuthenticationFilter클래스를 확장하고 있습니다
요약하면 이 필터는 인증 체계가 Basic 이고 Base64로 인코딩된 username:password 토큰이 있는
Authorization 의 HTTP 요청 헤더가 있는 모든 요청을 처리합니다.
BasicAuthenticationFilter클래스를 확장하기 보단 다른 필터를 찾아 확장하거나 구현하는게 맞는걸까요??
이해하기로는 Authorization scheme은 인증 체계를 알려주기만 하는거라고 이해했습니다 ㅎㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
설명이 필요 이상으로 자세한 것 같아요. 이 클래스의 "책임"만 간단하게 작성해 보세요.
|
||
private static List<GrantedAuthority> authorities() { | ||
List<GrantedAuthority> authorities = new ArrayList<>(); | ||
// TODO : userId에 따라서 권한을 따로 부여 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 TODO는 언제 실행할 예정인가요? 아니면 이미 끝난 작업인가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어떻게 적용해야 할지 몰라서 스프링 문서 뒤져가면서 찾고 있었습니다!
계속 작업 중 입니다 !! 9e54f15
제가 생각하는 흐름은
userId -1
을 관리자로 지정- User 엔티티에 enum
role
필드 추가 - 사용자 생성 시 기본 사용자는
USER
로 저장 - JWT 페이로드에
userId
와role
정보를 같이 인코딩 - 사용자 또는 상품 도메인 접근 시 JWT에 담겨 있는
role
정보를 확인해서 인가가 가능한지 구분
일단 이렇게 생각하고 3번까지 작업된 것 같습니다
시큐리티 설정에 문제가 있는지 401이 반환돼서 확인 작업 중에 있습니다!!
@Nested | ||
@DisplayName("식별자에 해당하는 사용자가 존재하고 인증을 통과한다면") | ||
class Context_ExistedIdAndValidToken{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용자가 존재하는 상황을 Context_ExistedIdAndValidToken
에서 명시해 주세요. 이 컨텍스트가 표현하고자 하는 것을 이 컨텍스트에서 코딩하는 것입니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Describe_Context_It
을 무의식적으로 작성한 것 같네요 ㅠㅠ
문맥별로 더 쪼개보니 반대 상황이 더 잘보이는 것 같습니다 ㅎㅎ
ef37c86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트가 한결 보기 좋습니다. 그러고보니 벌써 금요일이군요.
import java.io.IOException; | ||
import java.util.Set; | ||
|
||
public class JwtAuthenticationFilter extends BasicAuthenticationFilter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
설명이 필요 이상으로 자세한 것 같아요. 이 클래스의 "책임"만 간단하게 작성해 보세요.
이번 주 과제는 조금 아쉽게 끝나는 것 같네요 ㅠ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
한 주간 고생 많으셨습니다!
public User updateUser(Long id, UserModificationData modificationData) { | ||
public User updateUser(Long id, UserModificationData modificationData , Long userId) throws AccessDeniedException { | ||
if(!Objects.equals(id, userId)){ | ||
throw new AccessDeniedException("자원 접근이 거부되었습니다."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
만약 여러 나라의 언어로 서비스를 한다면 어떻게 대응하면 좋을지에 대해서 생각해 보세요.
class Context_ValidToken{ | ||
|
||
@Nested | ||
@DisplayName("사용자 권한이라면") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
관리자 권한이 아닌 경우
로 표현할 수도 있겠습니다.
TODO
로그인이 필요없는 API
POST /session
POST /users
GET /products
GET /products/{id}
로그인이 필요한 API
POST /products
PATCH /products/{id}
DELETE /products/{id}
POST /users/{id}
DELETE /users/{id}
스프링 시큐리티를 처음 접해봐서 중요한 포인트나 키워드를 던져주신다면 열심히 조사해보겠습니다!
한 주간 잘 부탁드립니다!!