Skip to content

Commit

Permalink
Merge pull request #205 from readyvery/test
Browse files Browse the repository at this point in the history
25일 오픈 �메인 배포(1)
  • Loading branch information
marinesnow34 authored Mar 20, 2024
2 parents 0ae23ae + 13871ea commit 7c5d948
Show file tree
Hide file tree
Showing 83 changed files with 1,941 additions and 340 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main_merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
host: ${{ secrets.MAIN_HOST }}
key: ${{ secrets.MAIN_SSH_KEY }}
source: "build/libs/*.jar"
target: "/home/ubuntu/docker/java/test/jar"
target: "/home/ready/docker/readyvery/jar"
- name: SSH and deploy
uses: appleboy/[email protected]
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
if: needs.build.result == 'failure'
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
Expand All @@ -67,7 +67,7 @@ jobs:
if: needs.build.result == 'success'
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.pulls.createReview({
owner: context.repo.owner,
Expand Down
18 changes: 16 additions & 2 deletions .github/workflows/test_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ on:
jobs:
build:
runs-on: ubuntu-latest
services:
# Label used to access the service container
redis:
# Docker Hub image
image: redis
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps port 6379 on service container to the host
- 6379:6379
steps:
- name: Checkout source code. # Repo checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -39,7 +53,7 @@ jobs:
if: needs.build.result == 'failure'
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
Expand All @@ -59,7 +73,7 @@ jobs:
if: needs.build.result == 'success'
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.pulls.createReview({
owner: context.repo.owner,
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ out/

### VS Code ###
.vscode/

/src/main/resources/application.properties
18 changes: 18 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ dependencies {
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

// redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'

// swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

// Bouncy Castle Provider
implementation 'org.bouncycastle:bcprov-jdk15on:1.70'

// Bouncy Castle PKIX/CMS/EAC/PKCS/OCSP/TSP/OPENSSL
implementation 'org.bouncycastle:bcpkix-jdk15on:1.70'

// Apache Commons IO
implementation 'commons-io:commons-io:2.11.0'

//SOLAPI
implementation 'net.nurigo:sdk:4.2.7'

// //Querydsl 추가
// implementation 'com.querydsl:querydsl-core:5.0.0'
// implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/com/readyvery/readyverydemo/config/JwtConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.readyvery.readyverydemo.config;

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

import com.auth0.jwt.algorithms.Algorithm;

import lombok.Getter;

@Configuration
@Getter
public class JwtConfig {

private final String secretKey;
private final Long accessTokenExpirationPeriod;
private final Long refreshTokenExpirationPeriod;
private final String accessTokenName;
private final String refreshTokenName;
private final String userFrontendUrl;
private final String guestFrontendUrl;
private final String cookieDomain;
private final Algorithm algorithm;

public static final String ACCESS_TOKEN_SUBJECT = "AccessToken";
public static final String REFRESH_TOKEN_SUBJECT = "RefreshToken";
public static final String EMAIL_CLAIM = "email";
public static final String USER_NUMBER = "userNumber";
public static final String BEARER = "Bearer ";
public static final String AUTHORIZATION = "Authorization";

public JwtConfig(
@Value("${jwt.secretKey}") String secretKey,
@Value("${jwt.access.expiration}") Long accessTokenExpirationPeriod,
@Value("${jwt.refresh.expiration}") Long refreshTokenExpirationPeriod,
@Value("${jwt.access.cookie}") String accessTokenName,
@Value("${jwt.refresh.cookie}") String refreshTokenName,
@Value("${jwt.redirect-uri-user}") String userFrontendUrl,
@Value("${jwt.redirect-uri-guest}") String guestFrontendUrl,
@Value("${jwt.cookie.domain}") String cookieDomain
) {
this.secretKey = secretKey;
this.accessTokenExpirationPeriod = accessTokenExpirationPeriod;
this.refreshTokenExpirationPeriod = refreshTokenExpirationPeriod;
this.accessTokenName = accessTokenName;
this.refreshTokenName = refreshTokenName;
this.userFrontendUrl = userFrontendUrl;
this.guestFrontendUrl = guestFrontendUrl;
this.cookieDomain = cookieDomain;
this.algorithm = initializeAlgorithm(secretKey);
}

private Algorithm initializeAlgorithm(String secretKey) {
if (secretKey == null || secretKey.trim().isEmpty()) {
throw new IllegalArgumentException("Secret key must not be null or empty");
}
return Algorithm.HMAC512(secretKey);
}
}
29 changes: 29 additions & 0 deletions src/main/java/com/readyvery/readyverydemo/config/OauthConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.readyvery.readyverydemo.config;

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

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
@Getter
public class OauthConfig {

@Value("${app.apple.url}")
private String appleUrl;

@Value("${app.apple.private-key}")
private String privateKeyString;
@Value("${app.apple.client-id}")
private String appleClientId;

@Value("${app.apple.team-id}")
private String appleTeamId;

@Value("${app.apple.key-id}")
private String appleKeyId;
public static final String KAKAO_NAME = "kakao";
public static final String APPLE_NAME = "apple";
}
29 changes: 29 additions & 0 deletions src/main/java/com/readyvery/readyverydemo/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.readyvery.readyverydemo.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
public class RedisConfig {

@Value("${spring.data.redis.host}")
private String host;

@Value("${spring.data.redis.port}")
private int port;

@Bean
public RedisConnectionFactory redisConnectionFactory() {

LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(host, port);
log.info("RedisConfig.redisConnectionFactory() called" + lettuceConnectionFactory);
return lettuceConnectionFactory;
}

}
44 changes: 44 additions & 0 deletions src/main/java/com/readyvery/readyverydemo/config/SolApiConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.readyvery.readyverydemo.config;

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

import net.nurigo.sdk.NurigoApp;
import net.nurigo.sdk.message.service.DefaultMessageService;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
@Configuration
public class SolApiConfig {
public static final String SOLAPI_URL = "https://api.solapi.com";

@Value("${solapi.api_key}")
private String apiKey;

@Value("${solapi.secret_key}")
private String apiSecret;

@Value("${solapi.templete.cancel}")
private String templeteCancel;

@Value("${solapi.templete.pickup}")
private String templetePickup;

@Value("${solapi.templete.order}")
private String templeteOrder;

@Value("${solapi.kakao.pfid}")
private String kakaoPfid;

@Value("${solapi.phone_number}")
private String phoneNumber;

@Bean
public DefaultMessageService defaultMessageService() {
return NurigoApp.INSTANCE.initialize(apiKey, apiSecret, SOLAPI_URL);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.readyvery.readyverydemo.security.config;
package com.readyvery.readyverydemo.config;

import java.util.Arrays;

Expand All @@ -11,17 +11,23 @@
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient;
import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient;
import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest;
import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequestEntityConverter;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.readyvery.readyverydemo.domain.repository.RefreshTokenRepository;
import com.readyvery.readyverydemo.domain.repository.UserRepository;
import com.readyvery.readyverydemo.security.exception.CustomAuthenticationEntryPoint;
import com.readyvery.readyverydemo.security.jwt.filter.JwtAuthenticationProcessingFilter;
import com.readyvery.readyverydemo.security.jwt.service.JwtService;
import com.readyvery.readyverydemo.security.oauth2.CustomRequestEntityConverter;
import com.readyvery.readyverydemo.security.oauth2.handler.OAuth2LoginFailureHandler;
import com.readyvery.readyverydemo.security.oauth2.handler.OAuth2LoginSuccessHandler;
import com.readyvery.readyverydemo.security.oauth2.service.CustomOAuth2UserService;
Expand All @@ -37,6 +43,8 @@ public class SpringSecurityConfig {
private final OAuth2LoginSuccessHandler oAuth2LoginSuccessHandler;
private final OAuth2LoginFailureHandler oAuth2LoginFailureHandler;
private final CustomOAuth2UserService customOAuth2UserService;
private final RefreshTokenRepository refreshTokenRepository;
private final OauthConfig oauthConfig;

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
Expand All @@ -62,14 +70,17 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
"/api/v1/order/current",
"/api/v1/auth",
"/api/v1/event/**"

).permitAll() // 위를 제외한 나머지는 모두 허용
.anyRequest().authenticated() // 해당 요청은 인증이 필요함
)
// [PART 3]
//== 소셜 로그인 설정 ==//
.oauth2Login(oauth2 -> oauth2
.tokenEndpoint(token -> token.accessTokenResponseClient(accessTokenResponseClient())) // 토큰 엔드포인트 설정
.successHandler(oAuth2LoginSuccessHandler) // 동의하고 계속하기를 눌렀을 때 Handler 설정
.failureHandler(oAuth2LoginFailureHandler) // 소셜 로그인 실패 시 핸들러 설정

.userInfoEndpoint(userInfo -> userInfo
.userService(customOAuth2UserService)))

Expand Down Expand Up @@ -121,7 +132,19 @@ public WebSecurityCustomizer webSecurityCustomizer() {
@Bean
public JwtAuthenticationProcessingFilter jwtAuthenticationProcessingFilter() {
JwtAuthenticationProcessingFilter jwtAuthenticationFilter = new JwtAuthenticationProcessingFilter(jwtService,
userRepository);
userRepository, refreshTokenRepository);
return jwtAuthenticationFilter;
}

@Bean
public OAuth2AccessTokenResponseClient<OAuth2AuthorizationCodeGrantRequest> accessTokenResponseClient() {

DefaultAuthorizationCodeTokenResponseClient accessTokenResponseClient =
new DefaultAuthorizationCodeTokenResponseClient();
accessTokenResponseClient.setRequestEntityConverter(
new CustomRequestEntityConverter(new OAuth2AuthorizationCodeGrantRequestEntityConverter(),
oauthConfig));

return accessTokenResponseClient;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.readyvery.readyverydemo.config;

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

import lombok.Getter;

@Configuration
@Getter
public class UserApiConfig {
@Value("${jwt.refresh.cookie}")
private String refreshCookie;
@Value("${service.app.admin.key}")
private String serviceAppAdminKey;
}
15 changes: 11 additions & 4 deletions src/main/java/com/readyvery/readyverydemo/domain/Coupon.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import jakarta.persistence.Version;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -25,7 +26,9 @@
@Setter
@Entity
@Builder
@Table(name = "COUPON")
@Table(name = "COUPON", uniqueConstraints = {
@UniqueConstraint(columnNames = {"coupon_detail_idx", "user_idx"})
})
@AllArgsConstructor
@NoArgsConstructor
@Slf4j
Expand All @@ -36,9 +39,13 @@ public class Coupon extends BaseTimeEntity {
@Column(name = "coupon_idx")
private Long id;

// 사용 여부
@Column(name = "used")
private boolean isUsed;
// 발급 갯수
@Column(name = "issue_count")
private int issueCount;

// 사용 갯수
@Column(name = "use_count")
private Long useCount;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "coupon_detail_idx")
Expand Down
Loading

0 comments on commit 7c5d948

Please sign in to comment.