-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Tave100Shot/3-feat-Project-초기세팅
feat project 초기세팅 pr
- Loading branch information
Showing
7 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,22 @@ | ||
package com.api.TaveShot.domain.Member; | ||
|
||
import com.api.TaveShot.domain.base.BaseEntity; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Builder | ||
@AllArgsConstructor | ||
public class Member extends BaseEntity { | ||
|
||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/api/TaveShot/domain/Member/MemberRepository.java
This file contains 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,6 @@ | ||
package com.api.TaveShot.domain.Member; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/api/TaveShot/domain/base/BaseEntity.java
This file contains 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,23 @@ | ||
package com.api.TaveShot.domain.base; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedBy; | ||
import org.springframework.data.annotation.LastModifiedBy; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public class BaseEntity extends BaseTimeEntity{ | ||
@CreatedBy | ||
@Column(updatable = false) | ||
private String createdBy; | ||
|
||
@LastModifiedBy | ||
private String lastModifiedBy; | ||
|
||
private boolean status; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/api/TaveShot/domain/base/BaseEntityConfig.java
This file contains 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,19 @@ | ||
package com.api.TaveShot.domain.base; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.domain.AuditorAware; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
@EnableJpaAuditing | ||
@Configuration | ||
public class BaseEntityConfig { | ||
|
||
@Bean | ||
public AuditorAware<String> auditorProvider() { | ||
// TODO 지금은 UUID이지만, Security 설정 후 spring Securitycontextholder 에서 값 꺼내기 | ||
return () -> Optional.of(UUID.randomUUID().toString()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/api/TaveShot/domain/base/BaseTimeEntity.java
This file contains 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,24 @@ | ||
package com.api.TaveShot.domain.base; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public class BaseTimeEntity { | ||
|
||
@CreatedDate | ||
@Column(updatable = false) | ||
private LocalDateTime createdDate; | ||
|
||
@LastModifiedDate | ||
private LocalDateTime lastModifiedDate; | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/api/TaveShot/global/config/SecurityConfig.java
This file contains 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,50 @@ | ||
package com.api.TaveShot.global.config; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
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.CsrfConfigurer; | ||
import org.springframework.security.config.annotation.web.configurers.HttpBasicConfigurer; | ||
import org.springframework.security.config.http.SessionCreationPolicy; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
@RequiredArgsConstructor | ||
public class SecurityConfig { | ||
|
||
@Bean | ||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { | ||
http | ||
.httpBasic(HttpBasicConfigurer::disable) | ||
.csrf(CsrfConfigurer::disable) | ||
.cors(corsCustomizer -> corsCustomizer.configurationSource(request -> { | ||
CorsConfiguration cors = new CorsConfiguration(); | ||
cors.setAllowedOrigins(List.of("*", "http://localhost:3000", "http://localhost:8080")); | ||
cors.setAllowedMethods(List.of("GET", "POST", "PATCH", "DELETE")); | ||
// cookie 비활성화 | ||
cors.setAllowCredentials(false); | ||
// Authorization Header 노출 | ||
cors.addExposedHeader("Authorization"); | ||
return cors; | ||
})) | ||
.sessionManagement(configurer -> configurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) | ||
.authorizeHttpRequests(authorize -> | ||
authorize | ||
.requestMatchers( | ||
"/actuator/**" | ||
, "/swagger-ui/**" | ||
, "/api-docs/swagger-config" | ||
, "/members/login" | ||
, "/**" | ||
).permitAll() | ||
.anyRequest().permitAll()); | ||
|
||
return http.build(); | ||
} | ||
|
||
} |