-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/NewFit/NewFit-Backend in…
…to release/dev
- Loading branch information
Showing
153 changed files
with
4,519 additions
and
4,159 deletions.
There are no files selected for viewing
32 changes: 17 additions & 15 deletions
32
src/main/java/com/newfit/reservation/common/S3Service.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,29 +1,31 @@ | ||
package com.newfit.reservation.common; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.model.ObjectMetadata; | ||
import lombok.RequiredArgsConstructor; | ||
import java.io.IOException; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.model.ObjectMetadata; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class S3Service { | ||
private final AmazonS3 amazonS3; | ||
private final AmazonS3 amazonS3; | ||
|
||
@Value("${cloud.aws.s3.bucket}") | ||
private String bucket; | ||
@Value("${cloud.aws.s3.bucket}") | ||
private String bucket; | ||
|
||
public String uploadFile(MultipartFile multipartFile) throws IOException { | ||
String originalFilename = multipartFile.getOriginalFilename(); | ||
ObjectMetadata metadata = new ObjectMetadata(); | ||
metadata.setContentType(multipartFile.getContentType()); | ||
metadata.setContentLength(multipartFile.getSize()); | ||
public String uploadFile(MultipartFile multipartFile) throws IOException { | ||
String originalFilename = multipartFile.getOriginalFilename(); | ||
ObjectMetadata metadata = new ObjectMetadata(); | ||
metadata.setContentType(multipartFile.getContentType()); | ||
metadata.setContentLength(multipartFile.getSize()); | ||
|
||
amazonS3.putObject(bucket, originalFilename, multipartFile.getInputStream(), metadata); | ||
return amazonS3.getUrl(bucket, originalFilename).toString(); | ||
} | ||
amazonS3.putObject(bucket, originalFilename, multipartFile.getInputStream(), metadata); | ||
return amazonS3.getUrl(bucket, originalFilename).toString(); | ||
} | ||
} |
60 changes: 31 additions & 29 deletions
60
src/main/java/com/newfit/reservation/common/auth/AuthorityCheckService.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,42 +1,44 @@ | ||
package com.newfit.reservation.common.auth; | ||
|
||
import static com.newfit.reservation.common.exception.ErrorCodeType.*; | ||
|
||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.userdetails.User; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.newfit.reservation.common.exception.CustomException; | ||
import com.newfit.reservation.domains.authority.domain.Authority; | ||
import com.newfit.reservation.domains.authority.repository.AuthorityRepository; | ||
import com.newfit.reservation.domains.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.userdetails.User; | ||
import org.springframework.stereotype.Service; | ||
|
||
import static com.newfit.reservation.common.exception.ErrorCodeType.*; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AuthorityCheckService { | ||
|
||
private final UserRepository userRepository; | ||
private final AuthorityRepository authorityRepository; | ||
|
||
public void validateByUserId(Authentication authentication, Long userId) { | ||
User principal = (User) authentication.getPrincipal(); | ||
com.newfit.reservation.domains.user.domain.User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new CustomException(USER_NOT_FOUND)); | ||
|
||
String nickname = principal.getUsername(); | ||
if (!user.getNickname().equals(nickname)) { | ||
throw new CustomException(UNAUTHORIZED_REQUEST); | ||
} | ||
} | ||
|
||
public void validateByAuthorityId(Authentication authentication, Long authorityId) { | ||
User principal = (User) authentication.getPrincipal(); | ||
Authority authority = authorityRepository.findById(authorityId) | ||
.orElseThrow(() -> new CustomException(AUTHORITY_NOT_FOUND)); | ||
|
||
String nickname = principal.getUsername(); | ||
if (!authority.getUser().getNickname().equals(nickname)) { | ||
throw new CustomException(UNAUTHORIZED_REQUEST); | ||
} | ||
} | ||
private final UserRepository userRepository; | ||
private final AuthorityRepository authorityRepository; | ||
|
||
public void validateByUserId(Authentication authentication, Long userId) { | ||
User principal = (User)authentication.getPrincipal(); | ||
com.newfit.reservation.domains.user.domain.User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new CustomException(USER_NOT_FOUND)); | ||
|
||
String nickname = principal.getUsername(); | ||
if (!user.getNickname().equals(nickname)) { | ||
throw new CustomException(UNAUTHORIZED_REQUEST); | ||
} | ||
} | ||
|
||
public void validateByAuthorityId(Authentication authentication, Long authorityId) { | ||
User principal = (User)authentication.getPrincipal(); | ||
Authority authority = authorityRepository.findById(authorityId) | ||
.orElseThrow(() -> new CustomException(AUTHORITY_NOT_FOUND)); | ||
|
||
String nickname = principal.getUsername(); | ||
if (!authority.getUser().getNickname().equals(nickname)) { | ||
throw new CustomException(UNAUTHORIZED_REQUEST); | ||
} | ||
} | ||
} |
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
13 changes: 7 additions & 6 deletions
13
src/main/java/com/newfit/reservation/common/auth/jwt/JwtProperties.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,17 +1,18 @@ | ||
package com.newfit.reservation.common.auth.jwt; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@Component | ||
public class JwtProperties { // JWT 관련 설정 정보를 담는 클래스 | ||
@Value("${jwt.issuer}") | ||
private String issuer; | ||
@Value("${jwt.issuer}") | ||
private String issuer; | ||
|
||
@Value("${jwt.secret_key}") | ||
private byte[] secretKey; | ||
@Value("${jwt.secret_key}") | ||
private byte[] secretKey; | ||
} |
Oops, something went wrong.