Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#18
Browse files Browse the repository at this point in the history
  • Loading branch information
Suanna01 authored Jul 30, 2023
2 parents 62dd9a9 + c46259d commit 669ddd2
Show file tree
Hide file tree
Showing 122 changed files with 3,857 additions and 600 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file removed .gradle/8.1.1/checksums/checksums.lock
Binary file not shown.
Binary file not shown.
Binary file removed .gradle/8.1.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file removed .gradle/8.1.1/fileChanges/last-build.bin
Binary file not shown.
Binary file removed .gradle/8.1.1/fileHashes/fileHashes.lock
Binary file not shown.
Empty file removed .gradle/8.1.1/gc.properties
Empty file.
Binary file removed .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 0 additions & 2 deletions .gradle/buildOutputCleanup/cache.properties

This file was deleted.

Empty file removed .gradle/vcs-1/gc.properties
Empty file.
17 changes: 0 additions & 17 deletions .idea/$CACHE_FILE$

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

16 changes: 0 additions & 16 deletions .idea/compiler.xml

This file was deleted.

463 changes: 0 additions & 463 deletions .idea/dbnavigator.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/dictionaries

This file was deleted.

21 changes: 0 additions & 21 deletions .idea/gradle.xml

This file was deleted.

20 changes: 0 additions & 20 deletions .idea/jarRepositories.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/misc.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

38 changes: 38 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ plugins {
id 'java'
id 'org.springframework.boot' version '2.7.13'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}


group = 'com.umc'
version = '0.0.1-SNAPSHOT'

Expand All @@ -26,16 +28,52 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'

// querydsl 추가
implementation "com.querydsl:querydsl-jpa:5.0.0"
implementation "com.querydsl:querydsl-apt:5.0.0"

compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'

//gson
implementation 'com.google.code.gson:gson:2.8.8'

//jwt
implementation 'io.jsonwebtoken:jjwt:0.9.1'

//thymeleaf
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
}

tasks.named('test') {
useJUnitPlatform()
}


jar {
enabled = false
}

// Qtype 생성 경로
def querydslDir = "$buildDir/generated/querydsl"
querydsl {
jpa = true
querydslSourcesDir = querydslDir
}
sourceSets {
main.java.srcDir querydslDir
}
compileQuerydsl{
options.annotationProcessorPath = configurations.querydsl
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
querydsl.extendsFrom compileClasspath
}

Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 0 additions & 20 deletions out/production/resources/application.yml

This file was deleted.

Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/main/.DS_Store
Binary file not shown.
85 changes: 85 additions & 0 deletions src/main/java/com/umc/DongnaeFriend/KakaoTokenController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.umc.DongnaeFriend;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.umc.DongnaeFriend.domain.user.dto.UserDto;
import com.umc.DongnaeFriend.domain.user.service.KakaoService;
import com.umc.DongnaeFriend.domain.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Controller
@RequestMapping("")
public class KakaoTokenController {

@Autowired
private UserService userService;

@Autowired
private KakaoService kakaoService;

@GetMapping("/kakao")
public String kakologin(Model model, HttpServletResponse response) {
response.setContentType(MediaType.TEXT_HTML_VALUE);

return "html/index";
}

@GetMapping("/callback")
public String callback(Model model, @RequestParam("code") String code) throws IOException {

try {
//------kakao POST 요청------
String reqURL = "https://kauth.kakao.com/oauth/token?grant_type=authorization_code&client_id=1ad317e194df665ca44dcb82d11a7093&code=" + code;
URL url = new URL(reqURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");


BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));

String line = "";
String result = "";

while ((line = br.readLine()) != null) {
result += line;
}

ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> jsonMap = objectMapper.readValue(result, new TypeReference<Map<String, Object>>() {
});

String accessToken = (String) jsonMap.get("access_token");

//-------------------------------------------------서버 로그인----------------------------------------------------

HashMap<String, Object> userInfo = kakaoService.getUserInfo(accessToken);
UserDto.Response response = userService.userValidation(userInfo);

model.addAttribute("token","Bearer "+ response.getAccessToken());

return "html/token";
} catch (Exception e) {
e.printStackTrace();
}
return null;

}

}
12 changes: 12 additions & 0 deletions src/main/java/com/umc/DongnaeFriend/config/JwtConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.umc.DongnaeFriend.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JwtConfig {

@Value("${jwt.secret-key}")
public String SECRET_KEY;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.umc.DongnaeFriend.config;

import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Configuration
public class QuerydslConfiguration {

@PersistenceContext
private EntityManager entityManager;

@Bean
public JPAQueryFactory jpaQueryFactory() {
return new JPAQueryFactory(entityManager);
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/umc/DongnaeFriend/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.umc.DongnaeFriend.config;


import com.umc.DongnaeFriend.global.security.JwtTokenFilter;
import org.springframework.beans.factory.annotation.Autowired;
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.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private JwtTokenFilter jwtTokenFilter;


@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/user/login").permitAll() // 인증 없이 접근 허용하는 URL
.antMatchers("/user/reissuance").permitAll() // 인증 없이 접근 허용하는 URL
.antMatchers("/kakao").permitAll() // 카카오 토큰 추출(임시)
.antMatchers("/callback").permitAll() // 카카오 토큰 추출(임시)
.anyRequest().authenticated(); // 그 외의 URL은 인증 필요
http.addFilterBefore(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class);
}

// 나머지 코드는 이전 예제와 동일
}
Loading

0 comments on commit 669ddd2

Please sign in to comment.