Skip to content

Commit

Permalink
[DEV-000] formatting (#283)
Browse files Browse the repository at this point in the history
* style: formatting

* style: formatting

* chore: platform 옵션 삭제

* style: formatting
  • Loading branch information
k-kbk authored Nov 7, 2024
1 parent ed4acc4 commit 6b07cb9
Show file tree
Hide file tree
Showing 326 changed files with 3,215 additions and 2,701 deletions.
1 change: 0 additions & 1 deletion infra/localcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ services:
environment:
MYSQL_ROOT_PASSWORD: mysql
MYSQL_DATABASE: myongji_graduate
platform: linux/x86_64
restart: always

redis:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.plzgraduate.myongjigraduatebe.auth.api.signin;

import javax.validation.Valid;

import org.springframework.web.bind.annotation.RequestBody;

import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.request.SignInRequest;
import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.response.TokenResponse;
import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser;

import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.RequestBody;

@Tag(name = "SignIn", description = "로그인 API")
public interface SignInApiPresentation {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.plzgraduate.myongjigraduatebe.auth.api.signin;

import javax.validation.Valid;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.request.SignInRequest;
import com.plzgraduate.myongjigraduatebe.auth.application.usecase.signin.SignInUseCase;
import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.response.TokenResponse;
import com.plzgraduate.myongjigraduatebe.auth.application.usecase.signin.SignInUseCase;
import com.plzgraduate.myongjigraduatebe.core.meta.LoginUser;
import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter;

import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

@WebAdapter
@RequestMapping("api/v1/auth")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.request;

import javax.validation.constraints.NotBlank;

import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.NotBlank;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -24,5 +23,4 @@ private SignInRequest(String authId, String password) {
this.authId = authId;
this.password = password;
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.plzgraduate.myongjigraduatebe.auth.api.token;

import javax.validation.Valid;

import org.springframework.web.bind.annotation.RequestBody;

import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.request.TokenRequest;
import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.response.AccessTokenResponse;

import io.swagger.v3.oas.annotations.tags.Tag;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.RequestBody;

@Tag(name = "Token", description = "토큰 발급 API")
public interface TokenApiPresentation {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.plzgraduate.myongjigraduatebe.auth.api.token;

import javax.validation.Valid;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.request.TokenRequest;
import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.response.AccessTokenResponse;
import com.plzgraduate.myongjigraduatebe.auth.application.usecase.token.TokenUseCase;
import com.plzgraduate.myongjigraduatebe.core.meta.WebAdapter;

import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

@WebAdapter
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.plzgraduate.myongjigraduatebe.auth.api.token.dto.request;

import javax.validation.constraints.NotBlank;

import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.NotBlank;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -19,5 +18,4 @@ public class TokenRequest {
private TokenRequest(String refreshToken) {
this.refreshToken = refreshToken;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
import java.util.Optional;

public interface FindRefreshTokenPort {

Optional<Long> findByRefreshToken(String refreshToken);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.plzgraduate.myongjigraduatebe.auth.application.port;


public interface SaveRefreshTokenPort {

void saveRefreshToken(String refreshToken, Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.plzgraduate.myongjigraduatebe.auth.application.service.signin;

import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.transaction.annotation.Transactional;

import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.response.TokenResponse;
import com.plzgraduate.myongjigraduatebe.auth.application.port.SaveRefreshTokenPort;
import com.plzgraduate.myongjigraduatebe.auth.application.usecase.signin.SignInUseCase;
import com.plzgraduate.myongjigraduatebe.auth.security.JwtAuthenticationToken;
import com.plzgraduate.myongjigraduatebe.auth.security.TokenProvider;
import com.plzgraduate.myongjigraduatebe.core.meta.UseCase;

import lombok.RequiredArgsConstructor;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.transaction.annotation.Transactional;

@UseCase
@Transactional(readOnly = true)
Expand All @@ -37,8 +35,8 @@ private Authentication authenticateCommand(String authId, String password) {
JwtAuthenticationToken authenticationToken =
new JwtAuthenticationToken(authId, password);
Authentication authentication = authenticationManager.authenticate(authenticationToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
SecurityContextHolder.getContext()
.setAuthentication(authentication);
return authentication;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.plzgraduate.myongjigraduatebe.auth.application.usecase.token.TokenUseCase;
import com.plzgraduate.myongjigraduatebe.auth.security.TokenProvider;
import com.plzgraduate.myongjigraduatebe.core.meta.UseCase;

import lombok.RequiredArgsConstructor;

@UseCase
Expand All @@ -15,6 +14,7 @@ public class TokenService implements TokenUseCase {
private final TokenProvider tokenProvider;

private final FindRefreshTokenPort findRefreshTokenPort;

@Override
public AccessTokenResponse generateNewToken(String refreshToken) {
Long userId = findByRefreshToken(refreshToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
import com.plzgraduate.myongjigraduatebe.auth.api.signin.dto.response.TokenResponse;

public interface SignInUseCase {

TokenResponse signIn(String authId, String password);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
import com.plzgraduate.myongjigraduatebe.auth.api.token.dto.response.AccessTokenResponse;

public interface TokenUseCase {

AccessTokenResponse generateNewToken(String refreshToken);
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package com.plzgraduate.myongjigraduatebe.auth.infrastructure.adapter.repository;

import java.util.Optional;
import java.util.concurrent.TimeUnit;

import org.springframework.stereotype.Component;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.plzgraduate.myongjigraduatebe.auth.application.port.FindRefreshTokenPort;
import com.plzgraduate.myongjigraduatebe.auth.application.port.SaveRefreshTokenPort;

import java.util.Optional;
import java.util.concurrent.TimeUnit;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class InMemoryTokenRepository implements FindRefreshTokenPort, SaveRefreshTokenPort {

private static final Cache<String, Long> TOKEN_REPOSITORY = CacheBuilder.newBuilder()
.expireAfterWrite(15, TimeUnit.DAYS)
.build();

@Override
public void saveRefreshToken(String refreshToken, Long userId) {
TOKEN_REPOSITORY.put(refreshToken, userId);
Expand All @@ -28,5 +26,4 @@ public void saveRefreshToken(String refreshToken, Long userId) {
public Optional<Long> findByRefreshToken(String refreshToken) {
return Optional.ofNullable(TOKEN_REPOSITORY.getIfPresent(refreshToken));
}

}
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
package com.plzgraduate.myongjigraduatebe.auth.security;

import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.*;
import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.AUTHENTICATION_FAIL_FORBIDDEN;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.plzgraduate.myongjigraduatebe.core.exception.ExceptionResponse;
import java.io.IOException;

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

import org.springframework.http.HttpStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode;
import com.plzgraduate.myongjigraduatebe.core.exception.ExceptionResponse;

import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class JwtAccessDeniedHandler implements AccessDeniedHandler {

private static final ExceptionResponse E403 = ExceptionResponse.from(AUTHENTICATION_FAIL_FORBIDDEN.toString());
private static final ExceptionResponse E403 = ExceptionResponse.from(
AUTHENTICATION_FAIL_FORBIDDEN.toString());

private final ObjectMapper om;

Expand All @@ -32,8 +26,11 @@ public void handle(HttpServletRequest request, HttpServletResponse response,
AccessDeniedException accessDeniedException) throws IOException {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
response.setHeader("content-type", "application/json");
response.getWriter().write(om.writeValueAsString(E403));
response.getWriter().flush();
response.getWriter().close();
response.getWriter()
.write(om.writeValueAsString(E403));
response.getWriter()
.flush();
response.getWriter()
.close();
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
package com.plzgraduate.myongjigraduatebe.auth.security;

import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.*;
import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.AUTHENTICATION_FAIL_UNAUTHORIZED;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.plzgraduate.myongjigraduatebe.core.exception.ExceptionResponse;
import java.io.IOException;

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

import org.springframework.http.HttpStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode;
import com.plzgraduate.myongjigraduatebe.core.exception.ExceptionResponse;

import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
private static final ExceptionResponse E401 = ExceptionResponse.from(AUTHENTICATION_FAIL_UNAUTHORIZED.toString());

private static final ExceptionResponse E401 = ExceptionResponse.from(
AUTHENTICATION_FAIL_UNAUTHORIZED.toString());

private final ObjectMapper om;

Expand All @@ -31,8 +26,11 @@ public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws IOException {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
response.setHeader("content-type", "application/json");
response.getWriter().write(om.writeValueAsString(E401));
response.getWriter().flush();
response.getWriter().close();
response.getWriter()
.write(om.writeValueAsString(E401));
response.getWriter()
.flush();
response.getWriter()
.close();
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package com.plzgraduate.myongjigraduatebe.auth.security;

import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.*;
import static com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode.INCORRECT_PASSWORD;
import static org.hibernate.validator.internal.util.TypeHelper.isAssignable;

import com.plzgraduate.myongjigraduatebe.core.exception.UnAuthorizedException;
import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase;
import com.plzgraduate.myongjigraduatebe.user.domain.model.User;
import java.util.Collections;

import lombok.RequiredArgsConstructor;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.crypto.password.PasswordEncoder;

import com.plzgraduate.myongjigraduatebe.core.exception.ErrorCode;
import com.plzgraduate.myongjigraduatebe.core.exception.UnAuthorizedException;
import com.plzgraduate.myongjigraduatebe.user.application.usecase.find.FindUserUseCase;
import com.plzgraduate.myongjigraduatebe.user.domain.model.User;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class JwtAuthenticationProvider implements AuthenticationProvider {

Expand All @@ -31,15 +27,18 @@ public boolean supports(Class<?> authentication) {
}

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
JwtAuthenticationToken authenticationToken = (JwtAuthenticationToken) authentication;
return processAuthentication(authenticationToken);
}

private Authentication processAuthentication(JwtAuthenticationToken authenticationToken) {
User user = findUserUseCase.findUserByAuthId(String.valueOf(authenticationToken.getPrincipal()));
User user = findUserUseCase.findUserByAuthId(
String.valueOf(authenticationToken.getPrincipal()));
try {
user.matchPassword(passwordEncoder, String.valueOf(authenticationToken.getCredentials()));
user.matchPassword(passwordEncoder,
String.valueOf(authenticationToken.getCredentials()));
return new JwtAuthenticationToken(
user.getId(), null, Collections.singleton(new SimpleGrantedAuthority("ROLE_USER"))
);
Expand Down
Loading

0 comments on commit 6b07cb9

Please sign in to comment.