diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 3efc682..cb1419a 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -61,8 +61,6 @@ public class Controller { return ResponseEntity.status(200).body(new Gson().toJson(cacheRepository.findAll())); } - // user muss jetzt anders aus dem token geholt werden, da kein subject mehr gesetzt wird und username nichtmehr unique ist - // (über der checkAdmin methode steht ein möglicher lösungsvorschlag dafür) @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/startCache") @ResponseBody @@ -85,8 +83,6 @@ public class Controller { Claims claims = (Claims) tokenVerification.getBody(); - - //Sollte jetzt eigentlich funktionieren...hoffe ich ResponseEntity getUser = FinderUtil.findUserFromClaim(claims); if (getUser.getStatusCodeValue() != 200) { @@ -118,16 +114,17 @@ public class Controller { Station startStation = cache.getStationen().get(0); bearbeitet.setAktuelleStation(startStation); + //Get CacheAccesDefinition + ResponseEntity getCacheAccesDefinition = FinderUtil.findCacheAccesDefinitionById("0"); - Optional cacheAccesDefinitionOptional = - cacheAccesDefinitionRepository.findById(0); // angefangen - if (cacheAccesDefinitionOptional.isPresent()) { - CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get(); - bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); - } else { - return ResponseEntity.status(404).body("There is no cacheAccesDefinition with the ID " + 0); + if (getCacheAccesDefinition.getStatusCodeValue() != 200) { + return getCacheAccesDefinition; } + CacheAccesDefinition cacheAccesDefinition = (CacheAccesDefinition) getCacheAccesDefinition.getBody(); + //---------------------- + bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); + bearbeitetRepository.save(bearbeitet); return ResponseEntity.status(201).body(new Gson().toJson(bearbeitet)); @@ -146,7 +143,6 @@ public class Controller { } } - //user muss jetzt anders aus dem token geholt werden, da kein subject mehr gesetzt wird und username nichtmehr unique ist @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/checkStation") @ResponseBody @@ -261,8 +257,8 @@ public class Controller { //---------------------- user_info.setRankingPointsSum(user_info.getRankingPointsSum() + cache.getRankingPoints()); user_infoRepository.save(user_info); - bearbeitetRepository.save(bearbeitet); } + bearbeitetRepository.save(bearbeitet); return ResponseEntity.status(200).body(new Gson().toJson(bearbeitet)); } else { return ResponseEntity.status(400).body("The scanned station isn´t the correct following station"); @@ -292,15 +288,20 @@ public class Controller { ResponseEntity userResponse = FinderUtil.findUserFromClaim(claims); - if(userResponse.getStatusCodeValue() != 200){ + if (userResponse.getStatusCodeValue() != 200) { return userResponse; } User user = (User) userResponse.getBody(); - //TODO Hier Admin Check einfügen + List roles = user.getRoles(); + for (Role role : roles) { + if (role.getDomain().equals("geocaching.de") && role.getName().equals("ADMIN")) { + return ResponseEntity.status(200).body(true); + } + } - return ResponseEntity.status(200).body(claims.get("admin")); + return ResponseEntity.status(404).body(false); } @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @@ -354,8 +355,6 @@ public class Controller { } } - // Ich hab mal eine Hilfsklasse erstellt, damit die Daten in einer schöneren Form ins Frontend kommen und da quasi nichts geändert - // werden muss. Ich konnte es noch nicht ausprobieren, da die se server down sind (11:05 Uhr) @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/getRankingList") @ResponseBody