diff --git a/src/main/java/com/dku/council/domain/danfesta/model/dto/LineUpImageDto.java b/src/main/java/com/dku/council/domain/danfesta/model/dto/LineUpImageDto.java index 3d0cd570..b7c23268 100644 --- a/src/main/java/com/dku/council/domain/danfesta/model/dto/LineUpImageDto.java +++ b/src/main/java/com/dku/council/domain/danfesta/model/dto/LineUpImageDto.java @@ -23,12 +23,16 @@ public class LineUpImageDto { @Schema(description = "이미지 파일 타입", example = "image/jpeg") private final String mimeType; + @Schema(description = "blur 데이터") + private final String blurData; + public LineUpImageDto(ObjectUploadContext context, LineUpImage image) { this.url = context.getImageUrl(image.getFileId()); this.originalName = image.getFileName(); String imageMimeType = image.getMimeType(); this.mimeType = Objects.requireNonNullElse(imageMimeType, MediaType.APPLICATION_OCTET_STREAM_VALUE); + this.blurData = image.getBlurData(); } public static List listOf(ObjectUploadContext context, List entities) { diff --git a/src/main/java/com/dku/council/domain/danfesta/model/entity/LineUpImage.java b/src/main/java/com/dku/council/domain/danfesta/model/entity/LineUpImage.java index fd7cca7a..a071573d 100644 --- a/src/main/java/com/dku/council/domain/danfesta/model/entity/LineUpImage.java +++ b/src/main/java/com/dku/council/domain/danfesta/model/entity/LineUpImage.java @@ -28,11 +28,15 @@ public class LineUpImage extends BaseEntity { private String fileName; + @Lob + private String blurData; + @Builder - private LineUpImage(String fileId, String mimeType, String fileName) { + private LineUpImage(String fileId, String mimeType, String fileName, String blurData) { this.fileId = fileId; this.mimeType = mimeType; this.fileName = fileName; + this.blurData = blurData; } public void changeLineUp(LineUp lineUp) { diff --git a/src/main/java/com/dku/council/domain/oauth/controller/OauthController.java b/src/main/java/com/dku/council/domain/oauth/controller/OauthController.java index bef178bd..047524d2 100644 --- a/src/main/java/com/dku/council/domain/oauth/controller/OauthController.java +++ b/src/main/java/com/dku/council/domain/oauth/controller/OauthController.java @@ -3,15 +3,13 @@ import com.dku.council.domain.oauth.model.dto.request.OauthLoginRequest; import com.dku.council.domain.oauth.model.dto.request.OauthRequest; import com.dku.council.domain.oauth.model.dto.request.TokenExchangeRequest; -import com.dku.council.domain.oauth.model.dto.response.OauthLoginResponse; import com.dku.council.domain.oauth.model.dto.response.TokenExchangeResponse; import com.dku.council.domain.oauth.service.OauthService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.view.RedirectView; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; @RestController @RequestMapping("/oauth") @@ -20,23 +18,22 @@ public class OauthController { private final OauthService oauthService; @GetMapping("/authorize") - public void authorize(@RequestParam String codeChallenge, - @RequestParam(required = false) String codeChallengeMethod, - @RequestParam String clientId, - @RequestParam String redirectUri, - @RequestParam String responseType, - @RequestParam String scope, - HttpServletResponse response) throws IOException { + public RedirectView authorize(@RequestParam String codeChallenge, + @RequestParam(required = false) String codeChallengeMethod, + @RequestParam String clientId, + @RequestParam String redirectUri, + @RequestParam String responseType, + @RequestParam String scope) { OauthRequest request = OauthRequest.of(codeChallenge, codeChallengeMethod, clientId, redirectUri, responseType, scope); String uri = oauthService.authorize(request); - response.sendRedirect(uri); + return new RedirectView(uri); } @PostMapping("/login") - public ResponseEntity login(@RequestBody OauthLoginRequest request) throws IOException { - OauthLoginResponse response = oauthService.login(request.toLoginInfo(), request.toOauthInfo()); - return ResponseEntity.ok(response); + public RedirectView login(@RequestBody OauthLoginRequest request) { + String uri = oauthService.login(request.toLoginInfo(), request.toOauthInfo()); + return new RedirectView(uri); } diff --git a/src/main/java/com/dku/council/domain/oauth/model/entity/OauthClient.java b/src/main/java/com/dku/council/domain/oauth/model/entity/OauthClient.java index bc19267f..e0eb534a 100644 --- a/src/main/java/com/dku/council/domain/oauth/model/entity/OauthClient.java +++ b/src/main/java/com/dku/council/domain/oauth/model/entity/OauthClient.java @@ -11,6 +11,9 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; +import java.util.HashSet; +import java.util.List; + import static javax.persistence.GenerationType.IDENTITY; import static lombok.AccessLevel.PROTECTED; @@ -51,9 +54,9 @@ public void checkClientSecret(String clientSecret) { } public void checkRedirectUri(String redirectUri) { - if (!this.redirectUri.equals(redirectUri)) { + HashSet redirectUriSet = new HashSet<>(List.of(this.redirectUri.split(" "))); + if (!redirectUriSet.contains(redirectUri)) { throw new InvalidOauthRedirectUriException(redirectUri); } } - } diff --git a/src/main/java/com/dku/council/domain/oauth/service/OauthService.java b/src/main/java/com/dku/council/domain/oauth/service/OauthService.java index 496c9977..fb5dbf63 100644 --- a/src/main/java/com/dku/council/domain/oauth/service/OauthService.java +++ b/src/main/java/com/dku/council/domain/oauth/service/OauthService.java @@ -5,7 +5,6 @@ import com.dku.council.domain.oauth.exception.OauthCacheNotFoundException; import com.dku.council.domain.oauth.exception.OauthClientNotFoundException; import com.dku.council.domain.oauth.model.dto.request.*; -import com.dku.council.domain.oauth.model.dto.response.OauthLoginResponse; import com.dku.council.domain.oauth.model.dto.response.TokenExchangeResponse; import com.dku.council.domain.oauth.model.entity.HashAlgorithm; import com.dku.council.domain.oauth.model.entity.OauthClient; @@ -39,6 +38,7 @@ public class OauthService { private final PasswordEncoder passwordEncoder; private final CodeChallengeConverter codeChallengeConverter; private final JwtProvider jwtProvider; + private static final String LOGIN_URL = "https://danvery.com/login"; public String authorize(OauthRequest oauthRequest) { String clientId = oauthRequest.getClientId(); @@ -48,24 +48,31 @@ public String authorize(OauthRequest oauthRequest) { oauthClient.checkClientId(clientId); oauthClient.checkRedirectUri(redirectUri); return UriComponentsBuilder - .fromUriString(oauthClient.getRedirectUri()) + .fromUriString(LOGIN_URL) .toUriString(); } @Transactional - public OauthLoginResponse login(RequestLoginDto loginInfo, OauthInfo oauthInfo) { + public String login(RequestLoginDto loginInfo, OauthInfo oauthInfo) { checkResponseType(oauthInfo.getResponseType()); User user = userRepository.findByStudentId(loginInfo.getStudentId()) .orElseThrow(UserNotFoundException::new); - if (!passwordEncoder.matches(loginInfo.getPassword(), user.getPassword())) { - throw new WrongPasswordException(); - } + checkPassword(loginInfo.getPassword(), user.getPassword()); String authCode = CodeGenerator.generateUUIDCode(); Long userId = user.getId(); OauthCachePayload cachePayload = oauthInfo.toCachePayload(userId); oauthRedisRepository.cacheOauth(authCode, cachePayload); - return OauthLoginResponse.from(authCode); + return UriComponentsBuilder + .fromUriString(oauthInfo.getRedirectUri()) + .queryParam("code", authCode) + .toUriString(); + } + + private void checkPassword(String inputPassword, String userPassword) { + if (!passwordEncoder.matches(inputPassword, userPassword)) { + throw new WrongPasswordException(); + } } public TokenExchangeResponse exchangeToken(ClientInfo clientInfo, OAuthTarget target) { diff --git a/src/test/java/com/dku/council/domain/oauth/service/OauthServiceTest.java b/src/test/java/com/dku/council/domain/oauth/service/OauthServiceTest.java index 9ee1159a..03c2af6f 100644 --- a/src/test/java/com/dku/council/domain/oauth/service/OauthServiceTest.java +++ b/src/test/java/com/dku/council/domain/oauth/service/OauthServiceTest.java @@ -130,7 +130,7 @@ void loginWhenValidCredentials() { when(passwordEncoder.matches(any(), any())).thenReturn(true); // when - OauthLoginResponse response = oauthService.login(loginInfo, oauthInfo); + String response = oauthService.login(loginInfo, oauthInfo); // then assertNotNull(response);