More Logger

This commit is contained in:
Maximilian Leopold 2019-05-14 09:09:59 +02:00
parent c75eb3f5e2
commit 074a18a831
2 changed files with 34 additions and 5 deletions

View File

@ -68,6 +68,7 @@ public class Controller {
@RequestMapping(value = "/api/allCaches", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResponseEntity getAllCaches() {
logger.warn("API CALL: /api/allCaches");
return ResponseEntity.status(200).body(new Gson().toJson(cacheRepository.findAll()));
}
@ -405,6 +406,7 @@ public class Controller {
@RequestMapping(value = "/api/getAllStations", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResponseEntity getAllStations() {
logger.warn("API CALL: /api/getAllStations");
return ResponseEntity.status(200).body(new Gson().toJson(stationRepository.findAll()));
}
@ -416,6 +418,7 @@ public class Controller {
@RequestMapping(value = "/api/deleteCache", method = {RequestMethod.DELETE, RequestMethod.GET}, produces = "application/json")
@ResponseBody
public ResponseEntity deleteCache(@RequestParam String cacheID) {
logger.warn("API CALL: /api/deleteCache");
return deleteCacheUtil(cacheID);
}
@ -430,6 +433,7 @@ public class Controller {
@ResponseBody
public ResponseEntity getMyCaches(@RequestParam String token) {
logger.warn("API CALL: /api/getMyCaches");
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
@ -439,6 +443,8 @@ public class Controller {
Claims claims = (Claims) verifyToken.getBody();
logger.debug("/api/getMyCaches Token verified");
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
@ -447,14 +453,18 @@ public class Controller {
User user = (User) getUser.getBody();
if (user != null) {
ArrayList<Bearbeitet> bearbeitetList = new ArrayList<>();
logger.debug("/api/getMyCaches Got User: " + user.getEmail());
for (Bearbeitet bearbeitet : bearbeitetRepository.findAll()) {
if (user != null) {
//ArrayList<Bearbeitet> bearbeitetList = new ArrayList<>();
/*for (Bearbeitet bearbeitet : bearbeitetRepository.findAll()) {
if (bearbeitet.getUser().getId() == user.getId()) {
bearbeitetList.add(bearbeitet);
}
}
}*/
List<Bearbeitet> bearbeitetList = bearbeitetRepository.findByUser(user);
logger.debug("/api/getMyCaches Got all bearbeitet entreis of user: " +user.getEmail());
return ResponseEntity.status(200).body(new Gson().toJson(bearbeitetList));
} else {
return ResponseEntity.status(404).body("User was not found in the database");
@ -470,13 +480,18 @@ public class Controller {
@ResponseBody
public ResponseEntity getRankingList() {
logger.warn("API CALL: /api/getRankingList");
List<RankingListHelper> sendBackUsers = new LinkedList<>();
logger.debug("/api/getRankingList create sendBackUsers");
List<Object[]> rankingUsers = userRepository.getRankingList();
logger.debug("/api/getRankingList got Object[] from DB");
for (Object[] obj : rankingUsers) {
RankingListHelper tmp = new RankingListHelper((String) obj[1], (Integer) obj[2]);
System.out.println(tmp);
sendBackUsers.add(tmp);
}
logger.debug("/api/getRankingList Converted Objects to RankingListHelper");
return ResponseEntity.status(200).body(new Gson().toJson(sendBackUsers));
}

View File

@ -1,5 +1,6 @@
package hhn.labsw.bugageocaching.util;
import hhn.labsw.bugageocaching.controller.Controller;
import hhn.labsw.bugageocaching.fetchObjects.PublicKey;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException;
@ -16,16 +17,23 @@ public class VerificationUtil {
public static Key publicKey;
private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(VerificationUtil.class);
public static void fetchPublicKey(){
RestTemplate restTemplate = new RestTemplate();
try {
logger.warn("POST CONSCTRUCT: FETCH PUBLIC KEY");
PublicKey response = restTemplate.getForObject("http://seserver.se.hs-heilbronn.de:9080/buga19usermanagement/token/publickey", PublicKey.class);
logger.debug("FETCH PUBLIC KEY: Got response from http://seserver.se.hs-heilbronn.de:9080/buga19usermanagement/token/publickey");
byte[] decodedKey = Base64.getDecoder().decode(response.getMessage());
KeyFactory factory = KeyFactory.getInstance("RSA");
X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(decodedKey);
Key key = factory.generatePublic(publicKeySpec);
publicKey = key;
logger.debug("FETCH PUBLIC KEY: Decoded Key: " + publicKey.toString());
} catch (Exception e) {
e.printStackTrace();
}
@ -36,14 +44,20 @@ public class VerificationUtil {
public static ResponseEntity verifyToken(String token){
try{
logger.warn("VERIFY TOKEN: token: " + token);
Claims claims = Jwts.parser() //Parse JWT
.setSigningKey(VerificationUtil.publicKey)
.parseClaimsJws(token).getBody();
logger.debug("VERIFY TOKEN: Got Claims: " + claims);
return ResponseEntity.status(200).body(claims);
} catch (ExpiredJwtException e){
logger.debug("VERIFY TOKEN: JWT Token expired");
return ResponseEntity.status(401).body("JWT Token expired");
} catch (Exception e){
logger.debug("VERIFY TOKEN: Something went wrong verificating");
return ResponseEntity.status(400).body("Something went wrong");
}
}