Skip to content

Commit

Permalink
chore: Update run script
Browse files Browse the repository at this point in the history
style: Update Code Style
  • Loading branch information
jinsu4755 committed Jul 10, 2023
1 parent 3db0484 commit 3a8ca2e
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 93 deletions.
7 changes: 6 additions & 1 deletion scripts/run_new.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

DEFAULT_PATH=/home/ubuntu/uni-sparkle-deploy/uni-sparkle
JAR_NAME=$(ls ${DEFAULT_PATH}/build/libs/ | grep '.jar' | tail -n 1)
JAR_PATH=${DEFAULT_PATH}/build/libs/${JAR_NAME}

CURRENT_PORT=$(cat /home/ubuntu/service_url.inc | grep -Po '[0-9]+' | tail -1)
TARGET_PORT=0

Expand All @@ -21,6 +25,7 @@ if [ ! -z ${TARGET_PID} ]; then
sudo kill ${TARGET_PID}
fi

nohup java -jar -Dspring.profiles.active=prod -Dserver.port=${TARGET_PORT} /home/ubuntu/uni-sparkle-deploy/uni-sparkle/build/libs/uni-0.0.1-SNAPSHOT.jar >nohup.out 2>&1 </dev/null &
echo "${JAR_PATH} 를 배포합니다"
nohup java -jar -Dspring.profiles.active=prod -Dserver.port=${TARGET_PORT} ${JAR_PATH} >nohup.out 2>&1 </dev/null &
echo "${TARGET_PORT} 로 새로운 서비스를 시작합니다"
exit 0
1 change: 0 additions & 1 deletion src/main/java/com/universe/uni/config/QueryDslConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import com.querydsl.jpa.impl.JPAQueryFactory;


@Configuration
public class QueryDslConfig {
@PersistenceContext
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/com/universe/uni/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
.cors().and().csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.formLogin().disable()
.authorizeRequests()
.antMatchers("/swagger-ui.html", "/swagger-ui/**", "/auth/*", "/status/uni/*").permitAll()
.and()
.authorizeRequests()
.antMatchers("/api").authenticated()
.anyRequest().permitAll()
.and()
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(jwtExceptionFilter, JwtAuthenticationFilter.class)
.build();
.cors().and().csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.formLogin().disable()
.authorizeRequests()
.antMatchers("/swagger-ui.html", "/swagger-ui/**", "/auth/*", "/status/uni/*").permitAll()
.and()
.authorizeRequests()
.antMatchers("/api").authenticated()
.anyRequest().permitAll()
.and()
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(jwtExceptionFilter, JwtAuthenticationFilter.class)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.universe.uni.config.jwt;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
Expand All @@ -26,16 +28,16 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {

@Override
protected void doFilterInternal(
HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain
HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain
) throws ServletException, IOException {
val uri = request.getRequestURI();
if (isContainApiPath(uri)) {
String token = getJwtFromRequest(request);
Long userId = jwtManager.getUserIdFromJwt(token);
UsernamePasswordAuthenticationToken authentication =
new UsernamePasswordAuthenticationToken(userId, null, null);
new UsernamePasswordAuthenticationToken(userId, null, null);
SecurityContextHolder.getContext().setAuthentication(authentication);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.universe.uni.controller;

import java.util.Objects;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -29,52 +30,52 @@ public class ControllerExceptionAdvice extends ResponseEntityExceptionHandler {
*/
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(
MethodArgumentNotValidException exception,
HttpHeaders headers,
HttpStatus status,
WebRequest request
MethodArgumentNotValidException exception,
HttpHeaders headers,
HttpStatus status,
WebRequest request
) {
ErrorResponse errorResponse = ErrorResponse.businessErrorOf(ErrorType.VALIDATION_REQUEST_MISSING_EXCEPTION);
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}

@Override
protected ResponseEntity<Object> handleMissingServletRequestParameter(
MissingServletRequestParameterException exception,
HttpHeaders headers,
HttpStatus status,
WebRequest request
MissingServletRequestParameterException exception,
HttpHeaders headers,
HttpStatus status,
WebRequest request
) {
ErrorResponse errorResponse = ErrorResponse.businessErrorOf(ErrorType.VALIDATION_REQUEST_MISSING_EXCEPTION);
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}

@Override
protected ResponseEntity<Object> handleMissingPathVariable(
MissingPathVariableException exception,
HttpHeaders headers,
HttpStatus status,
WebRequest request
MissingPathVariableException exception,
HttpHeaders headers,
HttpStatus status,
WebRequest request
) {
ErrorResponse errorResponse = ErrorResponse.businessErrorOf(ErrorType.VALIDATION_REQUEST_MISSING_EXCEPTION);
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(MissingRequestHeaderException.class)
protected ResponseEntity<Object> handleMissingRequestHeaderException(
MissingRequestHeaderException exception
MissingRequestHeaderException exception
) {
ErrorResponse errorResponse = ErrorResponse.businessErrorOf(ErrorType.VALIDATION_EXCEPTION);
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}

@Override
protected ResponseEntity<Object> handleExceptionInternal(
Exception ex,
Object body,
HttpHeaders headers,
HttpStatus status,
WebRequest request
Exception ex,
Object body,
HttpHeaders headers,
HttpStatus status,
WebRequest request
) {
try {
final ErrorType errorType = ErrorType.findErrorTypeBy(status);
Expand All @@ -93,7 +94,7 @@ protected ResponseEntity<Object> handleExceptionInternal(
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Exception.class)
protected ErrorResponse handleException(
final Exception exception
final Exception exception
) {
return ErrorResponse.businessErrorOf(ErrorType.INTERNAL_SERVER_ERROR);
}
Expand All @@ -103,8 +104,9 @@ protected ErrorResponse handleException(
*/
@ExceptionHandler(ApiException.class)
protected ResponseEntity<ErrorResponse> handleCustomException(
ApiException exception
ApiException exception
) {
return ResponseEntity.status(exception.getHttpStatus()).body(ErrorResponse.businessErrorOf(exception.getError()));
return ResponseEntity.status(exception.getHttpStatus())
.body(ErrorResponse.businessErrorOf(exception.getError()));
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/universe/uni/domain/GameResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public enum GameResult {

public static GameResult findMatchResultBy(String gameResultName) {
return Arrays.stream(values())
.filter(gameResult -> Objects.equals(gameResult.name(),gameResultName))
.findFirst()
.orElseThrow(()->new IllegalArgumentException("Unsupported match result type"));
.filter(gameResult -> Objects.equals(gameResult.name(), gameResultName))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unsupported match result type"));
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/universe/uni/domain/GameType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public enum GameType {

public static GameType findMatchTypeBy(String gameTypeName) {
return Arrays.stream(values())
.filter(gameType -> Objects.equals(gameType.name(), gameTypeName))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unsupported match type" + gameTypeName));
.filter(gameType -> Objects.equals(gameType.name(), gameTypeName))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unsupported match type" + gameTypeName));
}
}
18 changes: 9 additions & 9 deletions src/main/java/com/universe/uni/domain/SnsType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import java.util.Objects;

public enum SnsType {
KAKAO,
GOOGLE,
APPLE;
KAKAO,
GOOGLE,
APPLE;

public static SnsType findSnsTypeBy(String snsTypeName) {
return Arrays.stream(values())
.filter(snsType -> Objects.equals(snsType.name(), snsTypeName))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unsupported social login type: " + snsTypeName));
}
public static SnsType findSnsTypeBy(String snsTypeName) {
return Arrays.stream(values())
.filter(snsType -> Objects.equals(snsType.name(), snsTypeName))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unsupported social login type: " + snsTypeName));
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/universe/uni/domain/entity/Couple.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.universe.uni.domain.entity;

import java.time.LocalDate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.ColumnDefault;

import lombok.AccessLevel;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/universe/uni/domain/entity/Game.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.universe.uni.domain.entity;

import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class RoundGame {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "game_id", nullable = false)
private Game game;
private Game game;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "mission_category_id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.universe.uni.domain.entity;

import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.universe.uni.domain.entity;

import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.universe.uni.domain.entity;

import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/universe/uni/exception/dto/ErrorType.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.universe.uni.exception.dto;

import java.util.Arrays;

import org.springframework.http.HttpStatus;

import lombok.AccessLevel;
Expand Down Expand Up @@ -32,7 +33,6 @@ public enum ErrorType {
*/
NOT_ACCEPTABLE(HttpStatus.NOT_ACCEPTABLE, "UE7001", "Accept 헤더에 유효하지 않거나 지원되지 않는 미디어 유형을 지정되었습니다."),


/**
* 409 CONFLICT
*/
Expand Down Expand Up @@ -75,7 +75,7 @@ private boolean hasErrorType(HttpStatus httpStatus) {

public static ErrorType findErrorTypeBy(HttpStatus httpStatus) {
return Arrays.stream(values()).filter((errorType -> errorType.hasErrorType(httpStatus)))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("UnSupported Business HttpStatus Code :" + httpStatus));
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("UnSupported Business HttpStatus Code :" + httpStatus));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

import com.universe.uni.domain.entity.User;


public interface UserRepository extends JpaRepository<User, Long> {
}
26 changes: 14 additions & 12 deletions src/main/java/com/universe/uni/service/JwtManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.time.ZoneId;
import java.util.Base64;
import java.util.Date;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -36,7 +38,7 @@ public class JwtManager {
@PostConstruct
protected void init() {
jwtSecret = Base64.getEncoder()
.encodeToString(jwtSecret.getBytes(StandardCharsets.UTF_8));
.encodeToString(jwtSecret.getBytes(StandardCharsets.UTF_8));
}

public String issueToken(String userId) {
Expand All @@ -45,17 +47,17 @@ public String issueToken(String userId) {
OffsetDateTime expiration = now.plusSeconds(accessTokenExpiryPeriod);

final Claims claims = Jwts.claims()
.setSubject("accessToken")
.setIssuedAt(toDate(now))
.setExpiration(toDate(expiration));
.setSubject("accessToken")
.setIssuedAt(toDate(now))
.setExpiration(toDate(expiration));

claims.put("userId", userId);

return Jwts.builder()
.setHeaderParam(Header.TYPE, Header.JWT_TYPE)
.setClaims(claims)
.signWith(getSigningKey())
.compact();
.setHeaderParam(Header.TYPE, Header.JWT_TYPE)
.setClaims(claims)
.signWith(getSigningKey())
.compact();
}

private Date toDate(OffsetDateTime offsetDateTime) {
Expand All @@ -79,10 +81,10 @@ public boolean isVerifiedToken(String token) {
private Claims getBody(String token) {
try {
return Jwts.parserBuilder()
.setSigningKey(getSigningKey())
.build()
.parseClaimsJwt(token)
.getBody();
.setSigningKey(getSigningKey())
.build()
.parseClaimsJwt(token)
.getBody();
} catch (ExpiredJwtException exception) {
log.error("EXPIRED_JWT_TOKEN");
throw new UnauthorizedException(ErrorType.EXPIRED_TOKEN);
Expand Down
Loading

0 comments on commit 3a8ca2e

Please sign in to comment.