-
Notifications
You must be signed in to change notification settings - Fork 15
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
[BE] 이지훈 로그인 #9
base: main
Are you sure you want to change the base?
[BE] 이지훈 로그인 #9
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.
구현하느라 고생하셨어요!
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken( | ||
userDetails, null, userDetails.getAuthorities()); | ||
usernamePasswordAuthenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); | ||
SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken); |
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.
UsernamePasswordAuthenticationToken을 이용해서 유저 인증을 하는 로직을 필터가 아니라 서비스 단에서 Login() 메소드안에 구현해보는건 어떨까요?
http.authorizeHttpRequests((authorize) -> authorize. | ||
requestMatchers("/**").permitAll() | ||
.anyRequest().permitAll()); | ||
|
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.
현재 모든 경로가 permitAll()로 열려있는거 같아요! 요구사항에 맞게 사용자 인증이 필요한 요청에는 인증이 요구되게 변경해주시면 좋을 거 같아요!
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.
2024-05-30 20:58 경로 login, register 사용자 허용 수정했습니다 !
try { | ||
authenticationManager.authenticate( | ||
new UsernamePasswordAuthenticationToken(authRequest.getUsername(), authRequest.getPassword()) | ||
); |
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 jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
|
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.
Lombok의 어노테이션을 사용하면 코드가 간략해져서 추천 드려요!
@@ -0,0 +1,2 @@ | |||
package dto;public class Registerrequest { |
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.
DTO명을 request와 response로 작성하신건 좋은 거 같아요!
import java.util.Optional; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
Optional<User> findByUsername(String username); |
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.
Optional로 반환을 받는 것도 좋아요!
미완성 PR입니다 :(