Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

huncozyboy
Copy link
Member

미완성 PR입니다 :(

Copy link
Member

@hyxklee hyxklee left a 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);
Copy link
Member

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());

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 모든 경로가 permitAll()로 열려있는거 같아요! 요구사항에 맞게 사용자 인증이 필요한 요청에는 인증이 요구되게 변경해주시면 좋을 거 같아요!

Copy link
Member Author

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())
);
Copy link
Member

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;

Copy link
Member

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 {
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional로 반환을 받는 것도 좋아요!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants