Skip to content

Commit

Permalink
Merge pull request EveryUniv#191 from EveryUniv/dev
Browse files Browse the repository at this point in the history
Release dev_deploy
  • Loading branch information
gutanbug authored May 14, 2024
2 parents 21996ff + 19d2b0d commit 448573f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<LineUpImageDto> listOf(ObjectUploadContext context, List<LineUpImage> entities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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<OauthLoginResponse> 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);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,9 +54,9 @@ public void checkClientSecret(String clientSecret) {
}

public void checkRedirectUri(String redirectUri) {
if (!this.redirectUri.equals(redirectUri)) {
HashSet<String> redirectUriSet = new HashSet<>(List.of(this.redirectUri.split(" ")));
if (!redirectUriSet.contains(redirectUri)) {
throw new InvalidOauthRedirectUriException(redirectUri);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 448573f

Please sign in to comment.