added a possible way to get the user with a given token
This commit is contained in:
parent
57f7cd4164
commit
26e98f3db4
@ -34,6 +34,7 @@ dependencies {
|
||||
|
||||
//JSON Parser
|
||||
implementation 'com.google.code.gson:gson:2.8.5'
|
||||
compile 'com.googlecode.json-simple:json-simple:1.1.1'
|
||||
|
||||
|
||||
//compile 'org.springframework.boot:spring-boot-starter-tomcat'
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package hhn.labsw.bugageocaching.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import hhn.labsw.bugageocaching.entities.*;
|
||||
import hhn.labsw.bugageocaching.repositories.*;
|
||||
import hhn.labsw.bugageocaching.util.FinderUtil;
|
||||
@ -8,6 +9,9 @@ import hhn.labsw.bugageocaching.util.VerificationUtil;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.crypto.bcrypt.BCrypt;
|
||||
@ -118,7 +122,7 @@ public class Controller {
|
||||
|
||||
|
||||
Optional<CacheAccesDefinition> cacheAccesDefinitionOptional =
|
||||
cacheAccesDefinitionRepository.findById(0); // angefangen
|
||||
cacheAccesDefinitionRepository.findById(0); // angefangen
|
||||
if (cacheAccesDefinitionOptional.isPresent()) {
|
||||
CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get();
|
||||
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
|
||||
@ -276,7 +280,8 @@ public class Controller {
|
||||
}
|
||||
|
||||
// TODO claims.get funktioniert denk ich jetzt nurnoch mit claims.get("user") und liefert glaub ein userEntity objekt als JSON zurück
|
||||
// TODO wir könnten doch dann die email aus dem JSON auslesen und mit Hilfe einer findByEmail methode dann den user aus unserer DB finden oder?
|
||||
// TODO wir könnten doch dann die userID aus dem JSON auslesen und mit Hilfe einer findByID methode dann den user aus unserer DB finden oder?
|
||||
// TODO unten sieht man auskommentiert, wie das eventuell funktionieren könnte
|
||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||
@RequestMapping("/api/checkAdmin")
|
||||
@ResponseBody
|
||||
@ -290,6 +295,22 @@ public class Controller {
|
||||
|
||||
Claims claims = (Claims) verifyToken.getBody();
|
||||
|
||||
|
||||
// try {
|
||||
// JSONParser parser = new JSONParser();
|
||||
// JSONObject userObject = (JSONObject) parser.parse(token);
|
||||
// int userID = (Integer) userObject.get("userID");
|
||||
// Optional<User> userOptional = userRepository.findById(userID);
|
||||
// if (userOptional.isPresent()) {
|
||||
// User user = userOptional.get();
|
||||
// // hier dann admin check etc...
|
||||
// } else {
|
||||
// return ResponseEntity.status(404).body("Couldnt find User " + userID);
|
||||
// }
|
||||
// } catch (ParseException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
return ResponseEntity.status(200).body(claims.get("admin"));
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user