-
Notifications
You must be signed in to change notification settings - Fork 1
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 #58 from JNU-econovation/be
[BE] be -> develop
- Loading branch information
Showing
28 changed files
with
526 additions
and
104 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
FROM openjdk:17-oracle | ||
ARG JAR_FILE=/build/libs/overflow-0.0.1-SNAPSHOT.jar | ||
COPY ${JAR_FILE} app.jar | ||
ENTRYPOINT ["java", "-jar", "/app.jar"] |
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,35 @@ | ||
version: '3.1' | ||
services: | ||
mysql: | ||
container_name: overflow-mysql-dev | ||
image: mysql/mysql-server:8.0.27 | ||
environment: | ||
- MYSQL_DATABASE=overflow | ||
- MYSQL_ROOT_HOST=% | ||
- MYSQL_ROOT_PASSWORD=root | ||
command: [ "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci", "--lower_case_table_names=1", "--max_connections=2048", "--wait_timeout=3600" ] | ||
ports: | ||
- "13307:3306" | ||
volumes: #볼륨 지정 | ||
- ./resources/develop-environment/mysql-init.d:/docker-entrypoint-initdb.d | ||
networks: #사용할 네트워크 지정 | ||
- overflow-network | ||
backend: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
container_name: overflow-app-dev | ||
ports: | ||
- "8080:8080" | ||
depends_on: | ||
- mysql | ||
restart: always | ||
environment: | ||
SPRING_DATASOURCE_URL: jdbc:mysql://overflow-mysql-dev:3306/overflow?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false&allowPublicKeyRetrieval=true | ||
SPRING_DATASOURCE_USERNAME: root | ||
SPRING_DATASOURCE_PASSWORD: root | ||
SPRING_PROFILES_ACTIVE: dev | ||
networks: #사용할 네트워크 지정 | ||
- overflow-network | ||
networks: | ||
overflow-network: |
13 changes: 13 additions & 0 deletions
13
be/overflow/resources/develop-environment/mysql-init.d/00_init.sql
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,13 @@ | ||
CREATE | ||
USER 'overflow-local'@'localhost' IDENTIFIED BY 'root'; | ||
CREATE | ||
USER 'overflow-local'@'%' IDENTIFIED BY 'root'; | ||
|
||
GRANT ALL PRIVILEGES ON *.* TO | ||
'overflow-local'@'localhost'; | ||
GRANT ALL PRIVILEGES ON *.* TO | ||
'overflow-local'@'%'; | ||
|
||
-- CREATE | ||
-- DATABASE overflow DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
23 changes: 23 additions & 0 deletions
23
be/overflow/resources/develop-environment/mysql-init.d/01_create_table.sql
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 @@ | ||
create table auth_info_tb | ||
( | ||
auth_info_id BIGINT not null auto_increment, | ||
user_id BIGINT not null, | ||
auth_info_type varchar(255) not null, | ||
auth_info_token varchar(255) not null, | ||
created_date datetime not null, | ||
deleted bit not null, | ||
updated_date datetime not null, | ||
primary key (auth_info_id) | ||
) ENGINE = InnoDB; | ||
|
||
create table user_tb | ||
( | ||
user_id BIGINT not null auto_increment, | ||
user_email varchar(255) not null, | ||
user_nickname varchar(255) not null, | ||
user_password varchar(255) not null, | ||
created_date datetime not null, | ||
deleted bit not null, | ||
updated_date datetime not null, | ||
primary key (user_id) | ||
) ENGINE = InnoDB; |
11 changes: 11 additions & 0 deletions
11
.../src/main/java/com/econovation/overflow/auth/domain/exception/AuthorizationException.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,11 @@ | ||
package com.econovation.overflow.auth.domain.exception; | ||
|
||
import com.econovation.overflow.common.exception.BusinessException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class AuthorizationException extends BusinessException { | ||
|
||
public AuthorizationException(String message) { | ||
super(message, HttpStatus.NOT_FOUND); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...erflow/src/main/java/com/econovation/overflow/auth/domain/service/CreateTokenService.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,42 @@ | ||
package com.econovation.overflow.auth.domain.service; | ||
|
||
import com.econovation.overflow.auth.domain.dto.converter.TokenConverter; | ||
import com.econovation.overflow.auth.domain.dto.response.TokenResponse; | ||
import com.econovation.overflow.auth.persistence.converter.AuthInfoEntityConverter; | ||
import com.econovation.overflow.auth.persistence.entity.AuthInfoEntity; | ||
import com.econovation.overflow.auth.persistence.repository.AuthInfoRepository; | ||
import com.econovation.overflow.security.authority.UserRole; | ||
import com.econovation.overflow.security.token.TokenProvider; | ||
import com.econovation.overflow.security.token.TokenResolver; | ||
import java.util.Collections; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class CreateTokenService { | ||
private final TokenProvider tokenProvider; | ||
private final TokenConverter tokenConverter; | ||
private final TokenResolver tokenResolver; | ||
private final AuthInfoRepository authInfoRepository; | ||
private final AuthInfoEntityConverter authInfoEntityConverter; | ||
|
||
@Transactional | ||
public TokenResponse execute(final Long userId) { | ||
String accessToken = | ||
tokenProvider.createAccessToken(userId, Collections.singletonList(UserRole.USER)); | ||
String refreshToken = tokenProvider.createRefreshToken(userId); | ||
|
||
saveToken(userId, refreshToken); | ||
|
||
return tokenConverter.from( | ||
accessToken, tokenResolver.getExpiredDate(accessToken), refreshToken); | ||
} | ||
|
||
private void saveToken(Long userId, String token) { | ||
AuthInfoEntity authInfoEntity = authInfoEntityConverter.from(userId, token); | ||
authInfoRepository.save(authInfoEntity); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
be/overflow/src/main/java/com/econovation/overflow/auth/domain/usecase/ReissueUseCase.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,34 @@ | ||
package com.econovation.overflow.auth.domain.usecase; | ||
|
||
import com.econovation.overflow.auth.domain.dto.response.TokenResponse; | ||
import com.econovation.overflow.auth.domain.exception.AuthorizationException; | ||
import com.econovation.overflow.auth.domain.service.CreateTokenService; | ||
import com.econovation.overflow.auth.persistence.entity.AuthInfoEntity; | ||
import com.econovation.overflow.auth.persistence.repository.AuthInfoRepository; | ||
import com.econovation.overflow.security.token.TokenResolver; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
@Slf4j | ||
public class ReissueUseCase { | ||
private final CreateTokenService createTokenService; | ||
private final TokenResolver tokenResolver; | ||
private final AuthInfoRepository authInfoRepository; | ||
|
||
@Transactional | ||
public TokenResponse execute(final String token) { | ||
Long userId = tokenResolver.getUserInfo(token); | ||
|
||
AuthInfoEntity authInfoEntity = authInfoRepository | ||
.findByUserIdAndToken(userId, token) | ||
.orElseThrow(() -> new AuthorizationException("잘못된 토큰 입니다")); | ||
|
||
authInfoRepository.delete(authInfoEntity); | ||
return createTokenService.execute(userId); | ||
} | ||
} |
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
5 changes: 4 additions & 1 deletion
5
...rc/main/java/com/econovation/overflow/auth/persistence/repository/AuthInfoRepository.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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package com.econovation.overflow.auth.persistence.repository; | ||
|
||
import com.econovation.overflow.auth.persistence.entity.AuthInfoEntity; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface AuthInfoRepository extends JpaRepository<AuthInfoEntity, Long> {} | ||
public interface AuthInfoRepository extends JpaRepository<AuthInfoEntity, Long> { | ||
Optional<AuthInfoEntity> findByUserIdAndToken(Long userId, String token); | ||
} |
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
45 changes: 45 additions & 0 deletions
45
be/overflow/src/main/java/com/econovation/overflow/auth/web/support/CookieExtractor.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,45 @@ | ||
package com.econovation.overflow.auth.web.support; | ||
|
||
import com.econovation.overflow.auth.domain.exception.AuthorizationException; | ||
import java.util.Arrays; | ||
import java.util.Optional; | ||
import javax.servlet.http.Cookie; | ||
import javax.servlet.http.HttpServletRequest; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CookieExtractor implements TokenExtractor { | ||
private static final String REFRESH_KEY = "refreshToken"; | ||
|
||
@Override | ||
public String extract(HttpServletRequest request) { | ||
Cookie[] cookies = getCookies(request); | ||
Optional<Cookie> tokenCookie = | ||
Arrays.stream(cookies).filter(cookie -> cookie.getName().equals(REFRESH_KEY)).findAny(); | ||
|
||
Cookie refreshCookie = | ||
tokenCookie.orElseThrow(() -> new AuthorizationException("토큰이 존재하지 않습니다.")); | ||
|
||
return getValue(refreshCookie); | ||
} | ||
|
||
private Cookie[] getCookies(HttpServletRequest request) { | ||
Cookie[] cookies = request.getCookies(); | ||
if (cookies == null) { | ||
throw new AuthorizationException("토큰이 존재하지 않습니다"); | ||
} | ||
return cookies; | ||
} | ||
|
||
private String getValue(Cookie cookie) { | ||
String token = cookie.getValue(); | ||
validNullToken(token); | ||
return token; | ||
} | ||
|
||
private void validNullToken(String token) { | ||
if (token == null) { | ||
throw new AuthorizationException("토큰이 존재하지 않습니다"); | ||
} | ||
} | ||
} |
Oops, something went wrong.