Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ private void validatePinnedLimit(Long festivalId) {

private void validateFestivalBelongsToOrganization(Long festivalId, Long organizationId) {
if (!festivalJpaRepository.existsByIdAndOrganizationId(festivalId, organizationId)) {
throw new BusinessException("해당 조직의 축제가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

private void validateAnnouncementBelongsToOrganization(Long announcementId, Long organizationId) {
if (!announcementJpaRepository.existsByIdAndFestivalOrganizationId(announcementId, organizationId)) {
throw new BusinessException("해당 조직의 공지가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ private void validateDuplicatedEventDate(Long festivalId, LocalDate date) {

private void validateFestivalBelongsToOrganization(Long festivalId, Long organizationId) {
if (!festivalJpaRepository.existsByIdAndOrganizationId(festivalId, organizationId)) {
throw new BusinessException("해당 조직의 축제가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

private void validateEventDateBelongsToOrganization(Long eventDateId, Long organizationId) {
if (!eventDateJpaRepository.existsByIdAndFestivalOrganizationId(eventDateId, organizationId)) {
throw new BusinessException("해당 조직의 일정 날짜가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ private Event getEventById(Long eventId) {

private void validateEventBelongsToOrganization(Long eventId, Long organizationId) {
if (!eventJpaRepository.existsByIdAndEventDateFestivalOrganizationId(eventId, organizationId)) {
throw new BusinessException("해당 조직의 일정이 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

private void validateEventDateBelongsToOrganization(Long eventDateId, Long organizationId) {
if (!eventDateJpaRepository.existsByIdAndFestivalOrganizationId(eventDateId, organizationId)) {
throw new BusinessException("해당 조직의 일정 날짜가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ private FestivalImage getFestivalImageById(Long festivalImageId) {

private void validateFestivalBelongsToOrganization(Long festivalId, Long organizationId) {
if (!festivalJpaRepository.existsByIdAndOrganizationId(festivalId, organizationId)) {
throw new BusinessException("해당 조직의 축제가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

private void validateFestivalImageBelongsToOrganization(Long festivalImageId, Long organizationId) {
if (!festivalImageJpaRepository.existsByIdAndFestivalOrganizationId(festivalImageId, organizationId)) {
throw new BusinessException("해당 조직의 축제 이미지가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public FestivalLostItemGuideUpdateResponse updateFestivalLostItemGuide(

private void validateFestivalBelongsToOrganization(Long festivalId, Long organizationId) {
if (!festivalJpaRepository.existsByIdAndOrganizationId(festivalId, organizationId)) {
throw new BusinessException("해당 조직의 축제가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ private Lineup getLineupById(Long lineupId) {

private void validateFestivalBelongsToOrganization(Long festivalId, Long organizationId) {
if (!festivalJpaRepository.existsByIdAndOrganizationId(festivalId, organizationId)) {
throw new BusinessException("해당 조직의 축제가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

private void validateLineupBelongsToOrganization(Long lineupId, Long organizationId) {
if (!lineupJpaRepository.existsByIdAndFestivalOrganizationId(lineupId, organizationId)) {
throw new BusinessException("해당 조직의 라인업이 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ private Festival getFestivalById(Long festivalId) {

private void validateFestivalBelongsToOrganization(Long festivalId, Long organizationId) {
if (!festivalJpaRepository.existsByIdAndOrganizationId(festivalId, organizationId)) {
throw new BusinessException("해당 조직의 축제가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

private void validateLostItemBelongsToOrganization(Long lostItemId, Long organizationId) {
if (!lostItemJpaRepository.existsByIdAndFestivalOrganizationId(lostItemId, organizationId)) {
throw new BusinessException("해당 조직의 분실물이 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@
import java.util.Collection;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface PlaceJpaRepository extends JpaRepository<Place, Long> {

List<Place> findAllByFestivalId(Long festivalId);

Integer countByIdIn(Collection<Long> ids);

List<Place> findAllByIdInAndFestivalId(Collection<Long> places, Long festivalId);
@Query("SELECT p FROM Place p " +
"WHERE p.id IN (:placeIds) " +
"AND p.festival.id = :festivalId " +
"AND p.festival.organization.id = :organizationId")
List<Place> findAllByIdInAndFestivalId(
@Param("placeIds") Collection<Long> places,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 Collection으로 받는군요..

Comment on lines +16 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요게 그때 festivalId -> organizationId로 변경해야 하는 것 때문에 수정하신건가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 그때, organization에 포함되어있고, festival에도 포함되어 있는 Place를 조회해와야해요

  • festival만 검증하면 organization에 속하지 않는 다른 festival을 제공했을 때 검증을 통과해요

@Param("festivalId") Long festivalId,
@Param("organizationId") Long organizationId
);

boolean existsByIdAndFestivalOrganizationId(Long placeId, Long organizationId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ private void validatePlaceAnnouncementMaxCount(Long placeId) {
private void validatePlaceAnnouncementBelongsToOrganization(Long placeAnnouncementId, Long organizationId) {
if (!placeAnnouncementJpaRepository.existsByIdAndPlaceFestivalOrganizationId(placeAnnouncementId,
organizationId)) {
throw new BusinessException("해당 조직의 플레이스 공지가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

private void validatePlaceBelongsToOrganization(Long placeId, Long organizationId) {
if (!placeJpaRepository.existsByIdAndFestivalOrganizationId(placeId, organizationId)) {
throw new BusinessException("해당 조직의 플레이스가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private Place getPlaceById(Long placeId) {

private void validatePlaceBelongsToOrganization(Long placeId, Long organizationId) {
if (!placeJpaRepository.existsByIdAndFestivalOrganizationId(placeId, organizationId)) {
throw new BusinessException("해당 조직의 플레이스가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@ private void validateAllBelongsToOrganization(List<PlaceImage> placeImages, Long
placeImage.getId(), organizationId));

if (anyMismatch) {
throw new BusinessException("해당 조직의 플레이스 이미지가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

private void validatePlaceImageBelongsToOrganization(Long placeImageId, Long organizationId) {
if (!placeImageJpaRepository.existsByIdAndPlaceFestivalOrganizationId(placeImageId, organizationId)) {
throw new BusinessException("해당 조직의 플레이스 이미지가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

private void validatePlaceBelongsToOrganization(Long placeId, Long organizationId) {
if (!placeJpaRepository.existsByIdAndFestivalOrganizationId(placeId, organizationId)) {
throw new BusinessException("해당 조직의 플레이스가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public PlacesCloneResponse clonePlaces(Long organizationId, Long festivalId, Pla

List<Place> originalPlaces = placeJpaRepository.findAllByIdInAndFestivalId(
request.originalPlaceIds(),
festivalId
festivalId,
organizationId
);
// TODO: 권한 검증 수정 필요
validatePlacesBelongsToOrganization(originalPlaces.size(), request.originalPlaceIds().size());
Expand Down Expand Up @@ -157,7 +158,7 @@ private void updateTimeTags(Long organizationId, Place place, List<Long> timeTag

// 추가할 시간 태그 ID 목록 찾기
List<TimeTag> addTimeTags = getAddTimeTags(existingTimeTagIds, distinctRequestTimeTagIds);
validateTimeTagsBelongsToFestival(addTimeTags, organizationId);
validateTimeTagsBelongsToOrganization(addTimeTags, organizationId);

List<PlaceTimeTag> addPlaceTimeTags = createAddPlaceTimeTags(place, addTimeTags);
placeTimeTagJpaRepository.saveAll(addPlaceTimeTags);
Expand Down Expand Up @@ -265,27 +266,27 @@ private void validateClonePlacesSize(int size) {

private void validateFestivalBelongsToOrganization(Long festivalId, Long organizationId) {
if (!festivalJpaRepository.existsByIdAndOrganizationId(festivalId, organizationId)) {
throw new BusinessException("해당 조직의 축제가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

private void validatePlaceBelongsToOrganization(Long placeId, Long organizationId) {
if (!placeJpaRepository.existsByIdAndFestivalOrganizationId(placeId, organizationId)) {
throw new BusinessException("해당 조직의 플레이스가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

private void validateTimeTagsBelongsToFestival(List<TimeTag> addTimeTags, Long festivalId) {
private void validateTimeTagsBelongsToOrganization(List<TimeTag> addTimeTags, Long organizationId) {
addTimeTags.forEach(addTimeTag -> {
if (!timeTagJpaRepository.existsByIdAndFestivalOrganizationId(addTimeTag.getId(), festivalId)) {
throw new BusinessException("해당 조직의 시간 태그가 아닙니다.", HttpStatus.FORBIDDEN);
if (!timeTagJpaRepository.existsByIdAndFestivalOrganizationId(addTimeTag.getId(), organizationId)) {
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
});
}

private void validatePlacesBelongsToOrganization(int originalPlacesCount, int requestPlaceCounts) {
if (originalPlacesCount != requestPlaceCounts) {
throw new BusinessException("해당 조직의 플레이스가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ private Festival getFestivalById(Long festivalId) {

private void validateFestivalBelongsToOrganization(Long festivalId, Long organizationId) {
if (!festivalJpaRepository.existsByIdAndOrganizationId(festivalId, organizationId)) {
throw new BusinessException("해당 조직의 축제가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

private void validateQuestionBelongsToOrganization(Long questionId, Long organizationId) {
if (!questionJpaRepository.existsByIdAndFestivalOrganizationId(questionId, organizationId)) {
throw new BusinessException("해당 조직의 질문이 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ private void validateTimeTagNotInUse(TimeTag timeTag) {

private void validateFestivalBelongsToOrganization(Long festivalId, Long organizationId) {
if (!festivalJpaRepository.existsByIdAndOrganizationId(festivalId, organizationId)) {
throw new BusinessException("해당 조직의 축제가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}

private void validateTimeTagBelongsToOrganization(Long timeTagId, Long organizationId) {
if (!timeTagJpaRepository.existsByIdAndFestivalOrganizationId(timeTagId, organizationId)) {
throw new BusinessException("해당 조직의 시간 태그가 아닙니다.", HttpStatus.FORBIDDEN);
throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

The exception message is changed to a generic message to avoid exposing internal details. This enhances security by preventing attackers from gaining specific information about authorization failures. Severity: Medium

        if (!timeTagJpaRepository.existsByIdAndFestivalOrganizationId(timeTagId, organizationId)) {
            throw new BusinessException("접근 권한이 없습니다.", HttpStatus.FORBIDDEN);
        }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앞으로 이렇게 하기로 정했으니까 학습해

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class createAnnouncement {
// when & then
assertThatThrownBy(() -> announcementService.createAnnouncement(organizationId, invalidFestivalId, request))
.isInstanceOf(BusinessException.class)
.hasMessage("해당 조직의 축제가 아닙니다.");
.hasMessage("접근 권한이 없습니다.");
}

@Test
Expand All @@ -154,7 +154,7 @@ class createAnnouncement {
// when & then
assertThatThrownBy(() -> announcementService.createAnnouncement(otherOrganizationId, festivalId, request))
.isInstanceOf(BusinessException.class)
.hasMessage("해당 조직의 축제가 아닙니다.");
.hasMessage("접근 권한이 없습니다.");
}

@ParameterizedTest(name = "고정 공지 개수: {0}")
Expand Down Expand Up @@ -315,7 +315,7 @@ class updateAnnouncement {
assertThatThrownBy(
() -> announcementService.updateAnnouncement(organizationId, invalidAnnouncementId, request))
.isInstanceOf(BusinessException.class)
.hasMessage("해당 조직의 공지가 아닙니다.");
.hasMessage("접근 권한이 없습니다.");
}

@Test
Expand All @@ -333,7 +333,7 @@ class updateAnnouncement {
assertThatThrownBy(
() -> announcementService.updateAnnouncement(otherOrganizationId, announcementId, request))
.isInstanceOf(BusinessException.class)
.hasMessage("해당 조직의 공지가 아닙니다.");
.hasMessage("접근 권한이 없습니다.");
}
}

Expand Down Expand Up @@ -388,7 +388,7 @@ class updateAnnouncementPin {
request
))
.isInstanceOf(BusinessException.class)
.hasMessage("해당 조직의 공지가 아닙니다.");
.hasMessage("접근 권한이 없습니다.");
}

@Test
Expand All @@ -408,7 +408,7 @@ class updateAnnouncementPin {
announcementService.updateAnnouncementPin(otherOrganizationId, festivalId, announcementId, request)
)
.isInstanceOf(BusinessException.class)
.hasMessage("해당 조직의 공지가 아닙니다.");
.hasMessage("접근 권한이 없습니다.");
}

@Test
Expand Down Expand Up @@ -500,7 +500,7 @@ class deleteByAnnouncementId {
announcementService.deleteAnnouncementByAnnouncementId(organizationId, invalidAnnouncementId)
)
.isInstanceOf(BusinessException.class)
.hasMessage("해당 조직의 공지가 아닙니다.");
.hasMessage("접근 권한이 없습니다.");
}

@Test
Expand All @@ -517,7 +517,7 @@ class deleteByAnnouncementId {
announcementService.deleteAnnouncementByAnnouncementId(otherOrganizationId, announcementId)
)
.isInstanceOf(BusinessException.class)
.hasMessage("해당 조직의 공지가 아닙니다.");
.hasMessage("접근 권한이 없습니다.");
}
}

Expand Down Expand Up @@ -568,7 +568,7 @@ class sendAnnouncementNotification {
announcementService.sendAnnouncementNotification(organizationId, festivalId, invalidAnnouncementId)
)
.isInstanceOf(BusinessException.class)
.hasMessage("해당 조직의 공지가 아닙니다.");
.hasMessage("접근 권한이 없습니다.");
}

@Test
Expand All @@ -586,7 +586,7 @@ class sendAnnouncementNotification {
announcementService.sendAnnouncementNotification(otherOrganizationId, festivalId, announcementId)
)
.isInstanceOf(BusinessException.class)
.hasMessage("해당 조직의 공지가 아닙니다.");
.hasMessage("접근 권한이 없습니다.");
}

@Test
Expand Down
Loading