Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
696cb5f
Merge pull request #9 from PotatoField/develop
junyoung6215 Aug 5, 2024
5d3b4eb
feat: 불필요한 폴더 삭제
jeongminuk Aug 5, 2024
92fabb6
구조 오류 수정
jeongminuk Aug 5, 2024
661b1c0
Merge pull request #10 from PotatoField/minuk
jeongminuk Aug 5, 2024
f65d90e
feat : 2nd
junyoung6215 Aug 5, 2024
f3a676a
session added ver
junyoung6215 Aug 8, 2024
dc0a5a6
hahahah
junyoung6215 Aug 12, 2024
18d5311
post version -01
jeongminuk Aug 12, 2024
cd474f2
test
pepcsy Aug 12, 2024
7d0d0dd
test!
pepcsy Aug 12, 2024
aa271a6
Merge pull request #13 from PotatoField/dev_sy
pepcsy Aug 12, 2024
f9445bd
test!!!
pepcsy Aug 12, 2024
ff57d60
Merge pull request #16 from PotatoField/dev_sh
hwi-hwi-hwi Aug 12, 2024
86356b4
0812회의
junyoung6215 Aug 12, 2024
a455f3b
구조 올려~~~
jeongminuk Aug 12, 2024
2d1e06d
feat
hwi-hwi-hwi Aug 12, 2024
a5c259c
Merge pull request #17 from PotatoField/dev_sh
hwi-hwi-hwi Aug 12, 2024
9a7ecc5
Merge branch 'main' of https://github.com/PotatoField/back into minuk
jeongminuk Aug 12, 2024
454702a
Merge pull request #18 from PotatoField/minuk
jeongminuk Aug 12, 2024
88f4664
test
pepcsy Aug 12, 2024
1dfdeb2
Merge branch 'main' of https://github.com/PotatoField/back into dev_sy
pepcsy Aug 12, 2024
63f01ef
editttt
hwi-hwi-hwi Aug 12, 2024
bcec363
Merge pull request #19 from PotatoField/dev_sy
pepcsy Aug 12, 2024
d0a7b03
help
hwi-hwi-hwi Aug 12, 2024
3cb7294
Merge pull request #20 from PotatoField/dev_sh
hwi-hwi-hwi Aug 12, 2024
66217a4
end
hwi-hwi-hwi Aug 12, 2024
9475399
Merge pull request #21 from PotatoField/dev_sh
hwi-hwi-hwi Aug 12, 2024
4f67bc2
post,like one to many
pepcsy Aug 12, 2024
6ff2b0c
Merge branch 'main' of https://github.com/PotatoField/back into dev_sy
pepcsy Aug 12, 2024
204abaa
병합이 안됨
junyoung6215 Aug 13, 2024
68a1f78
권준영 0813 수정본
junyoung6215 Aug 13, 2024
ac0236a
Merge pull request #11 from PotatoField/dev_junyoung
junyoung6215 Aug 13, 2024
39f16a6
0816 회의전 수정본
junyoung6215 Aug 15, 2024
5b1c572
오류수정
pepcsy Aug 15, 2024
f133890
...
pepcsy Aug 15, 2024
2e7b7a4
Merge pull request #22 from PotatoField/dev_sy
pepcsy Aug 15, 2024
456169c
edit
hwi-hwi-hwi Aug 15, 2024
317fdc7
난 몰라요
jeongminuk Aug 16, 2024
20da65a
update postimagerepository
jeongminuk Aug 16, 2024
9ca1e2e
회의중
junyoung6215 Aug 16, 2024
4f3a70a
Merge pull request #24 from PotatoField/dev_junyoung
junyoung6215 Aug 16, 2024
4fb9144
Merge branch 'main' of https://github.com/PotatoField/back into dev_sh
hwi-hwi-hwi Aug 16, 2024
9b6c0bd
create post update
jeongminuk Aug 16, 2024
3d0b242
Merge pull request #25 from PotatoField/minuk
jeongminuk Aug 16, 2024
339aa79
h2 콘솔 아직 미해결
hwi-hwi-hwi Aug 16, 2024
cd2a3bd
Merge pull request #23 from PotatoField/dev_sh
hwi-hwi-hwi Aug 16, 2024
9fef7ef
feat: like -> likes
pepcsy Aug 16, 2024
7c6caf1
Merge branch 'main' of https://github.com/PotatoField/back into dev_sy
pepcsy Aug 16, 2024
14feec3
Merge pull request #26 from PotatoField/dev_sy
pepcsy Aug 16, 2024
18688f1
feat: post 관련 에러 주석처리
hwi-hwi-hwi Aug 16, 2024
7b0039b
Merge pull request #27 from PotatoField/dev_sh
hwi-hwi-hwi Aug 16, 2024
9db2fe3
pull용 commit 01
jeongminuk Aug 16, 2024
4967277
revised ver using JWT token
junyoung6215 Aug 16, 2024
be9b139
Merge pull request #28 from PotatoField/dev_junyoung
junyoung6215 Aug 16, 2024
14ef307
feat
hwi-hwi-hwi Aug 16, 2024
2a18fc3
에러 수정:
jeongminuk Aug 16, 2024
6ec6b76
likescontroller 수정
pepcsy Aug 16, 2024
7c0429c
오류수정
jeongminuk Aug 16, 2024
6e53eb8
feat: h2 해결
hwi-hwi-hwi Aug 16, 2024
3b69f20
Merge pull request #29 from PotatoField/dev_sh
hwi-hwi-hwi Aug 16, 2024
3bc5054
revised ver completed JWT
junyoung6215 Aug 16, 2024
5ec5e33
Merge pull request #30 from PotatoField/dev_junyoung
junyoung6215 Aug 16, 2024
04a29bb
Merge branch 'main' of https://github.com/PotatoField/back into dev_sy
pepcsy Aug 16, 2024
70ec475
post renew
jeongminuk Aug 16, 2024
84db683
post renew2
jeongminuk Aug 16, 2024
896e16b
8월16일 마무리
jeongminuk Aug 16, 2024
0c400f8
마무리2
jeongminuk Aug 16, 2024
b6adb82
Merge pull request #31 from PotatoField/minuk
jeongminuk Aug 16, 2024
38f178c
revised ver 0819 study
junyoung6215 Aug 19, 2024
913897a
Merge pull request #32 from PotatoField/dev_junyoung
junyoung6215 Aug 19, 2024
a929bd1
edit_08_19_Mon
hwi-hwi-hwi Aug 19, 2024
1ef9ffb
edit
hwi-hwi-hwi Aug 19, 2024
a8f6477
Merge pull request #33 from PotatoField/dev_sh
hwi-hwi-hwi Aug 19, 2024
17d65c9
8/22 2nd
jeongminuk Aug 22, 2024
d6c50b2
item-edit
hwi-hwi-hwi Aug 22, 2024
42be15c
Merge pull request #34 from PotatoField/dev_sh
hwi-hwi-hwi Aug 22, 2024
114efd5
back into dev_sy
pepcsy Aug 23, 2024
a6d02a6
check_1
jeongminuk Aug 23, 2024
4987b98
0825 revised ver
junyoung6215 Aug 25, 2024
8cbaf1f
Merge pull request #35 from PotatoField/dev_junyoung
junyoung6215 Aug 25, 2024
875b536
오류 수정중
jeongminuk Aug 25, 2024
dcaa169
오류수정중2
jeongminuk Aug 25, 2024
94850f5
오류수정3
jeongminuk Aug 25, 2024
ecfa53e
오류수정4
jeongminuk Aug 25, 2024
1e6950f
Merge pull request #36 from PotatoField/minuk
jeongminuk Aug 25, 2024
4f11c4f
Merge branch 'main' of https://github.com/PotatoField/back into dev_sy
pepcsy Sep 4, 2024
b5b59c5
좋아요 ê°개수 조회 기능 추가
pepcsy Sep 10, 2024
5da944e
Merge pull request #37 from PotatoField/dev_sy
pepcsy Sep 19, 2024
dd55b7a
comment add
junyoung6215 Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules/potato-field.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions potato-field/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.2'
id 'org.springframework.boot' version '3.3.2' // 버전 변경
id 'io.spring.dependency-management' version '1.1.6'
}

Expand Down Expand Up @@ -28,17 +28,24 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.session:spring-session-core'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.session:spring-session-data-redis'

// JWT 관련 의존성 (중복 제거)
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

runtimeOnly 'com.h2database:h2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

tasks.named('test') {
useJUnitPlatform()
}
}
Binary file modified potato-field/src/main/java/com/tools/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.tools.potato_field;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.lang.NonNull;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import com.tools.potato_field.member.CustomUserDetailsService;

import java.io.IOException;

@Component
public class JwtAuthenticationFilter extends OncePerRequestFilter {

private final JwtUtil jwtUtil;
private final CustomUserDetailsService customUserDetailsService;

public JwtAuthenticationFilter(JwtUtil jwtUtil, CustomUserDetailsService customUserDetailsService) {
this.jwtUtil = jwtUtil;
this.customUserDetailsService = customUserDetailsService;
}

@Override
protected void doFilterInternal(
@NonNull HttpServletRequest request,
@NonNull HttpServletResponse response,
@NonNull FilterChain filterChain
) throws ServletException, IOException {
final String authorizationHeader = request.getHeader("Authorization");

String username = null;
String jwt = null;

if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ")) {
jwt = authorizationHeader.substring(7);
username = jwtUtil.extractUsername(jwt);
}

if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
UserDetails userDetails = this.customUserDetailsService.loadUserByUsername(username);

if (jwtUtil.validateToken(jwt, userDetails)) {
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
userDetails, null, userDetails.getAuthorities());
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
}
}
filterChain.doFilter(request, response);
}


}
60 changes: 60 additions & 0 deletions potato-field/src/main/java/com/tools/potato_field/JwtUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.tools.potato_field;

import io.jsonwebtoken.*;
import io.jsonwebtoken.security.Keys;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import javax.crypto.SecretKey;
import java.util.Date;
import java.util.function.Function;

@Component
public class JwtUtil {

// SecretKey를 더 안전하게 생성
private final SecretKey secretKey = Keys.secretKeyFor(SignatureAlgorithm.HS512);

@Value("${jwt.expiration}")
private long expiration;

public String generateToken(String username) {
return Jwts.builder()
.setSubject(username)
.setIssuedAt(new Date(System.currentTimeMillis()))
.setExpiration(new Date(System.currentTimeMillis() + expiration))
.signWith(secretKey) // 여기서 안전한 키 사용
.compact();
}

public boolean validateToken(String token, UserDetails userDetails) {
final String username = extractUsername(token);
return (username.equals(userDetails.getUsername()) && !isTokenExpired(token));
}

public String extractUsername(String token) {
return extractClaim(token, Claims::getSubject);
}

public Date extractExpiration(String token) {
return extractClaim(token, Claims::getExpiration);
}

public <T> T extractClaim(String token, Function<Claims, T> claimsResolver) {
final Claims claims = extractAllClaims(token);
return claimsResolver.apply(claims);
}

private Claims extractAllClaims(String token) {
try {
return Jwts.parserBuilder().setSigningKey(secretKey).build().parseClaimsJws(token).getBody();
} catch (ExpiredJwtException | UnsupportedJwtException | MalformedJwtException | SignatureException | IllegalArgumentException e) {
throw new JwtException("Invalid JWT token", e);
}
}

private Boolean isTokenExpired(String token) {
return extractExpiration(token).before(new Date());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.tools.potato_field;

public class PostCategory {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication

public class PotatoFieldApplication {

public static void main(String[] args) {
SpringApplication.run(PotatoFieldApplication.class, args);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.tools.potato_field;

public class ResourceNotFoundException extends RuntimeException {
public ResourceNotFoundException() {
super();
}

public ResourceNotFoundException(String message) {
super(message);
}

public ResourceNotFoundException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,42 @@

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.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@Configuration
@EnableWebSecurity
public class SecurityConfig {

private final JwtAuthenticationFilter jwtAuthenticationFilter;

public SecurityConfig(JwtAuthenticationFilter jwtAuthenticationFilter) {
this.jwtAuthenticationFilter = jwtAuthenticationFilter;
}

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

// 기타 보안 설정...
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.disable())
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(authz -> authz
.requestMatchers("/api/members/register", "/api/members/login", "/api/**").permitAll()
.requestMatchers("/h2-console/**").permitAll()
.anyRequest().authenticated()
)
.headers(headers -> headers.frameOptions(frameOptions -> frameOptions.sameOrigin()))
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);

return http.build();
}
}
Loading