Skip to content

Commit

Permalink
Merge pull request #47 from TeamGuttok/GUTTOK-87
Browse files Browse the repository at this point in the history
GUTTOK-87 : 사용자 세션 설정 initializeUserSession로 중복 분리
  • Loading branch information
jucheolkang authored Feb 17, 2025
2 parents d019598 + a85cd6d commit b7cf77b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
19 changes: 9 additions & 10 deletions docker-compose-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

services:
app:
image: ${DOCKERHUB_USERNAME}/guttok_app:latest
Expand All @@ -15,17 +14,17 @@ services:
- MYSQL_URL=jdbc:mysql://mysql:3306/${DOCKER_MYSQL_DATABASE}
- MYSQL_USERNAME=${DOCKER_MYSQL_USERNAME}
- MYSQL_PASSWORD=${DOCKER_MYSQL_PASSWORD}
- REDIS_HOST=redis
- REDIS_HOST=${REDIS_HOST}
- REDIS_PORT=${REDIS_PORT}
- REDIS_PASSWORD=${REDIS_PASSWORD}
- REDIS_PASSWORD=${DOCKER_REDIS_PASSWORD}
volumes:
- /home:/data
- ./app/data:/data
env_file:
- .env

mysql:
image: mysql:8.0
container_name: guttok_mysql_out
container_name: guttok_mysql
restart: always
ports:
- "13306:3306"
Expand All @@ -40,26 +39,26 @@ services:
- ./db/mysql/data:/var/lib/mysql
- ./db/mysql/init:/docker-entrypoint-initdb.d
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost", "-p${MYSQL_PASSWORD}" ]
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost", "-p${DOCKER_MYSQL_PASSWORD}" ]
interval: 10s
timeout: 5s
retries: 3

redis:
image: redis:7.0
container_name: guttok_redis_out
container_name: guttok_redis
restart: always
ports:
- "6380:6379"
- "6379:6379"
env_file:
- .env
command: [ "sh", "-c", "redis-server --requirepass $DOCKER_REDIS_PASSWORD" ]
command: [ "sh", "-c", "redis-server --requirepass ${DOCKER_REDIS_PASSWORD}" ]
environment:
TZ: ${DOCKER_TZ}
volumes:
- ./db/redis/data:/data
healthcheck:
test: [ "CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping" ]
test: [ "CMD", "redis-cli", "-a", "${DOCKER_REDIS_PASSWORD}", "ping" ]
interval: 10s
timeout: 5s
retries: 3
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

@Service
Expand Down Expand Up @@ -37,12 +38,7 @@ private void certification(GetCertificationNumberDto getCertificationNumberDto)

}

// 일치하면 로그인과 같은 권한 부여
public void responseSession(GetCertificationNumberDto getCertificationNumberDto, HttpServletRequest request) {
// 인증 코드 검증
certification(getCertificationNumberDto);

// 세션 초기화 및 생성
private HttpSession initializeUserSession(GetCertificationNumberDto getCertificationNumberDto, HttpServletRequest request) {
HttpSession session = request.getSession(false);
if (session != null) {
session.invalidate();
Expand All @@ -56,8 +52,21 @@ public void responseSession(GetCertificationNumberDto getCertificationNumberDto,
String email = getCertificationNumberDto.getEmail();
session.setAttribute("email", email);

return session;
}


// 일치하면 로그인과 같은 권한 부여
public void responseSession(GetCertificationNumberDto getCertificationNumberDto, HttpServletRequest request) {
// 인증 코드 검증
certification(getCertificationNumberDto);

// 세션 초기화 및 생성
HttpSession session = initializeUserSession(getCertificationNumberDto, request);

// 사용자 정보 가져오기
var userDetails = customUserDetailsService.loadUserByUsername(email);
String email = getCertificationNumberDto.getEmail();
UserDetails userDetails = customUserDetailsService.loadUserByUsername(email);

// 인증 객체 생성 및 SecurityContext 설정
Authentication authentication = new UsernamePasswordAuthenticationToken(
Expand All @@ -77,16 +86,7 @@ public void createUnauthenticatedSession(GetCertificationNumberDto getCertificat

certification(getCertificationNumberDto);

HttpSession session = request.getSession(false);
if (session != null) {
session.invalidate();
}
session = request.getSession(true);

session.setMaxInactiveInterval(600);

String email = getCertificationNumberDto.getEmail();
session.setAttribute("email", email);
initializeUserSession(getCertificationNumberDto, request);

// 권한 없이 세션 반환
SecurityContextHolder.clearContext();
Expand Down

0 comments on commit b7cf77b

Please sign in to comment.