This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit cae1a7c4 authored by Michael Breu's avatar Michael Breu :speech_balloon:
Browse files

Fixing Architecture

parent 09f15754
2 merge requests!188Merging Peer Reviewing et. al to Master,!164211 peer reviewing functionality
......@@ -4,15 +4,12 @@ import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.persistence.criteria.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.querydsl.QPageRequest;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -20,7 +17,6 @@ import org.springframework.transaction.annotation.Transactional;
import at.ac.uibk.gitsearch.domain.UserWatchList;
import at.ac.uibk.gitsearch.repository.UserWatchListRepository;
import at.ac.uibk.gitsearch.security.jwt.TokenProvider;
import at.ac.uibk.gitsearch.service.dto.UserWatchListCriteria;
import at.ac.uibk.gitsearch.service.dto.UserWatchListDTO;
import at.ac.uibk.gitsearch.service.mapper.UserWatchListMapper;
import at.ac.uibk.gitsearch.web.rest.errors.BadRequestAlertException;
......@@ -52,21 +48,21 @@ public class UserWatchListService {
* @param description some description of the request
* @throws BadRequestAlertException if access not allowed
*/
public void checkAccessToWatchList(final Long watchlistId, final String description) throws BadRequestAlertException {
public void checkAccessToWatchList(final Long watchlistId, final String description) throws IllegalAccessError {
final Optional<User> currentPrincipal = tokenProvider.getCurrentPrincipal();
if(currentPrincipal.isEmpty()) {
log.warn("Cannot find a principal for watchlist {} for exercise {}", watchlistId, description);
throw new BadRequestAlertException("Cannot find a principal", "WatchListEntry", "missingPrincipal");
throw new IllegalAccessError("Cannot find a principal");
}
final Optional<UserWatchListDTO> watchListO = findOne(watchlistId);
if(watchListO.isEmpty()) {
log.warn("Cannot find watchlist for : {} for exercise {}", watchlistId, description);
throw new BadRequestAlertException("Cannot find watchlist", "WatchListEntry", "missingWatchlist");
throw new IllegalAccessError("Cannot find watchlist");
}
final boolean isAccessible = watchListO.get().getUserIdLogin().equals(currentPrincipal.get().getUsername());
if(!isAccessible) {
log.warn("watchlist {} does not belong to current user", watchListO.get().getName());
throw new BadRequestAlertException("watchlist does not belong to current User", "WatchListEntry", "illegalAccess");
throw new IllegalAccessError("watchlist does not belong to current User");
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment