-
Notifications
You must be signed in to change notification settings - Fork 0
10주차 미션_조이 #37
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
Open
dmlwjds2
wants to merge
2
commits into
main
Choose a base branch
from
조이
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "\uC870\uC774"
Open
10주차 미션_조이 #37
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package chapters.ch10.exceptions; | ||
|
|
||
| import javax.swing.*; | ||
|
|
||
| public class DialogReader { | ||
| public String readString(String prompt) { | ||
| return JOptionPane.showInputDialog(prompt); | ||
| } | ||
|
|
||
| public int readInt(String prompt) { | ||
| int n; | ||
| String input = readString(prompt); | ||
| try { | ||
| n = Integer.parseInt(input.trim()); | ||
| } catch (NumberFormatException e) { | ||
| JOptionPane.showMessageDialog(null, e.getMessage() + " 정수가 아닙니다."); | ||
| n = readInt(prompt); // 재시도 | ||
| } | ||
| return n; | ||
| } | ||
|
|
||
| public double readDouble(String prompt) { | ||
| double n; | ||
| String input = readString(prompt); | ||
| try { | ||
| n = Double.parseDouble(input.trim()); | ||
| } catch (NumberFormatException e) { | ||
| JOptionPane.showMessageDialog(null, e.getMessage() + " 실수가 아닙니다."); | ||
| n = readDouble(prompt); // 재시도 | ||
| } | ||
| return n; | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| int n = new DialogReader().readInt("정수를 주세요. 100에서 나누어 드립니다."); | ||
| try { | ||
| String answer = "100에서 나누기 " + Integer.toString(n) + " = " + (100 / n); | ||
| JOptionPane.showMessageDialog(null, answer); | ||
| } catch (java.lang.ArithmeticException e) { | ||
| JOptionPane.showMessageDialog(null, e.getMessage() + " : 0으로 나눌 수 없습니다."); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| package umc.server.domain.member.dto.req; | ||
|
|
||
| import jakarta.validation.constraints.Email; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import org.springframework.cglib.core.Local; | ||
|
|
@@ -12,7 +14,12 @@ | |
| public class MemberReqDTO { | ||
| @Builder | ||
| public record JoinDTO( | ||
| @NotBlank | ||
| String name, | ||
| String email, | ||
| @NotBlank | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NotNull과 NotBlank의 차이를 알아두시면 데모데이때 큰 도움이 됩니다! |
||
| String password, | ||
| Gender gender, | ||
| LocalDate birth, | ||
| String address, | ||
|
|
@@ -22,6 +29,8 @@ public record JoinDTO( | |
| ){} | ||
| @Builder | ||
| public record LoginDTO( | ||
| String memberId | ||
| String memberId, | ||
| String email, | ||
| String password | ||
| ){} | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
조이/server/src/main/java/umc/server/domain/member/enums/Role.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package umc.server.domain.member.enums; | ||
|
|
||
| public enum Role { | ||
| ROLE_ADMIN,ROLE_USER; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
조이/server/src/main/java/umc/server/global/auth/CustomUserDetailsService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package umc.server.global.config; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.core.userdetails.UserDetails; | ||
| import org.springframework.security.core.userdetails.UserDetailsService; | ||
| import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
| import org.springframework.stereotype.Service; | ||
| import umc.server.domain.member.entity.Member; | ||
| import umc.server.domain.member.repository.MemberRepository; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class CustomUserDetailsService implements UserDetailsService { | ||
|
|
||
| private final MemberRepository memberRepository; | ||
|
|
||
| @Override | ||
| public UserDetails loadUserByUsername(String email) | ||
| throws UsernameNotFoundException { | ||
|
|
||
| Member member = memberRepository.findByEmail(email) | ||
| .orElseThrow(() -> | ||
| new UsernameNotFoundException("존재하지 않는 회원입니다: " + email) | ||
| ); | ||
|
|
||
| return org.springframework.security.core.userdetails.User.builder() | ||
| .username(member.getEmail()) | ||
| .password(member.getPassword()) | ||
| .roles(member.getRole().name()) // Role.USER / Role.ADMIN | ||
| .build(); | ||
| } | ||
| } |
4 changes: 4 additions & 0 deletions
4
조이/server/src/main/java/umc/server/global/auth/JwtAuthFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package umc.server.global.auth; | ||
|
|
||
| public class JwtAuthFilter { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package umc.server.global.auth; | ||
|
|
||
| public class JwtUtil { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 얘네는 왜 구현이 안되었을까용 |
||
| } | ||
4 changes: 4 additions & 0 deletions
4
조이/server/src/main/java/umc/server/global/config/AuthenticationEntryPoint.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package umc.server.global.config; | ||
|
|
||
| public class AuthenticationEntryPoint { | ||
| } |
49 changes: 49 additions & 0 deletions
49
조이/server/src/main/java/umc/server/global/config/SecurityConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package umc.server.global.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.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
| import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.security.web.SecurityFilterChain; | ||
|
|
||
| @EnableWebSecurity | ||
| @Configuration | ||
| public class SecurityConfig { | ||
|
|
||
| private final String[] allowUris = { | ||
| "/sign-up", | ||
| "/swagger-ui/**", | ||
| "/swagger-resources/**", | ||
| "/v3/api-docs/**", | ||
| }; | ||
|
|
||
| @Bean | ||
| public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
| http | ||
| .authorizeHttpRequests(requests -> requests | ||
| .requestMatchers(allowUris).permitAll() | ||
| .requestMatchers("/admin/**").hasRole("ADMIN") | ||
| .anyRequest().authenticated() | ||
| ) | ||
| .formLogin(form -> form | ||
| .defaultSuccessUrl("/swagger-ui/index.html", true) | ||
| .permitAll() | ||
| ) | ||
| .csrf(AbstractHttpConfigurer::disable) | ||
| .logout(logout -> logout | ||
| .logoutUrl("/logout") | ||
| .logoutSuccessUrl("/login?logout") | ||
| .permitAll() | ||
| ); | ||
|
|
||
| return http.build(); | ||
| } | ||
|
|
||
| @Bean | ||
| public PasswordEncoder passwordEncoder() { | ||
| return new BCryptPasswordEncoder(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ㅋㅋㅋㅋㅋ잠만 얘는 뭔가요?