Skip to content

Commit

Permalink
[Feat] spring security 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyunio committed Nov 13, 2024
1 parent 903b289 commit b167236
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
}

tasks.named('test') {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/basic/study/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.basic.study.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.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
public class SecurityConfig {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.httpBasic(AbstractHttpConfigurer::disable)
.csrf(AbstractHttpConfigurer::disable)
.cors(AbstractHttpConfigurer::disable);

return http.build();
}
}
5 changes: 4 additions & 1 deletion src/main/java/com/basic/study/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.NoSuchElementException;

@Service
@RequiredArgsConstructor
public class MemberService {
Expand All @@ -25,7 +27,8 @@ public MemberRes login(MemberReq memberReq) {
}

public MemberRes getMember(Long memberId) {
Member member = memberRepository.findById(memberId).get();
Member member = memberRepository.findById(memberId).orElseThrow(() -> new NoSuchElementException("해당 회원을 찾을 수 없습니다."));

return MemberRes.builder()
.memberId(member.getId())
.email(member.getEmail())
Expand Down

0 comments on commit b167236

Please sign in to comment.