Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

comments to verifier-backend #116

Merged
merged 1 commit into from
Aug 3, 2021
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 @@ -35,21 +35,20 @@ public ResponseEntity<String> sendVP(@RequestBody String token) {
return verifyService.sendVP(token);
}

@GetMapping("/api/tester")
public String test(@RequestParam String token) {
JwtVerifier jwt = new JwtVerifier();
return jwt.verifySubUser(token);
}

/**
* Route that gets if the sent jwt token was verified
* Route that gets if the given userID is verified
* @param id = userID
* @return a boolean true if the token was verified, false if not
*/
@GetMapping("/api/checkVerified")
public boolean checkVerify(@RequestParam(value = "id") String id) {
return verifyService.checkVerify(id);
}

/**
* Route that lets verifier post a userID
* @return a response entity which states that the user was added and HttpStatus.OK
*/
@CrossOrigin(origins = "http://localhost:3000")
@PostMapping("/api/sendUserID")
public ResponseEntity<String> sendUserID(@RequestBody String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
@Service
public class VerifyService {

//private boolean verified = false;


public ResponseEntity<String> sendVP(String token) {
JwtVerifier verifier = new JwtVerifier();
UserIdHandler uih = new UserIdHandler();
Expand All @@ -25,14 +22,9 @@ public ResponseEntity<String> sendVP(String token) {
}
}
return new ResponseEntity<>("token: " + token + ", verified: " + isVerified + ", userID:" + userID, HttpStatus.OK);

}


// public boolean checkVerify() {
// return this.verified;
// }

public boolean checkVerify(String id) {
UserIdHandler uih = new UserIdHandler();
return uih.getIsUserVerified(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public DecodedJWT decodeJwt(String jwtToken) {
}

//Method for checking Audience
/**
* Method that checks if audience matches verifier
* @param token = the token to verify
* @return
*/
private boolean checkAud(String token){
String audience = "127.0.0.1:3000/api/sendVP";
DecodedJWT jwt = decodeJwt(token);
Expand Down Expand Up @@ -99,6 +104,11 @@ private boolean verifyVCType(String token, String type) {
return typeList.contains(jth.getVcType(type));
}

/**
* Method to get the subject from the token
* @param token = the token
* @return the subject/userID
*/
public String verifySubUser(String token){
DecodedJWT jwt = decodeJwt(token);
System.out.println(jwt.getSubject());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@
import java.util.function.BiConsumer;
import java.util.function.BooleanSupplier;


/**
* Class that reads and writes userID's from file
*/
public class UserIdHandler {
private Writer file;

//sjekke at ID finnes, les fra fil
/**
* Method that checks if userID exists in file
* @param id = the id we wish to find
* @return a boolean value for if the id exists or not
*/
private boolean getUserExists(String id) {
try {
File file = new File("src/main/resources/userID.json");
Expand All @@ -43,6 +51,10 @@ private boolean getUserExists(String id) {
return false;
}

/**
* Loads from file the userID and a corresponding boolean value for if the user was verified or not
* @return a hashmap mapping userIDs to a boolean value
*/
public HashMap<String, Boolean> loadFromFile() {
try {
InputStream inputStream = new FileInputStream("src/main/resources/userID.json");
Expand All @@ -62,8 +74,10 @@ public HashMap<String, Boolean> loadFromFile() {

}

//skrive til fil

/**
* Saves to file a hashmap that maps userIDs to corresponding boolean values
* @param publicKeyMap = the map to save to file
*/
private void saveToFile(HashMap<String, Boolean> userIDMap) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();

Expand Down Expand Up @@ -91,14 +105,22 @@ private void saveToFile(HashMap<String, Boolean> userIDMap) {
}
}

//legg til bruker, userID: false
/**
* Adds a mapping of a userID with a corresponding boolean value
* @param id = the userID
* @param verified = boolean value for if the user is verified or not
*/
public void addUserId(String id, boolean verified) {
HashMap<String, Boolean> map = loadFromFile();
map.put(id, verified);
saveToFile(map);
}

//getIsUserVerified(id) return true/false, kalle i checkVerified
/**
* Method that checks if a userID is verified or not
* @param id = the userID
* @return a boolean value that tells if the given userID is verified or not
*/
public boolean getIsUserVerified(String id) {
if (loadFromFile().get(id) == null) {
return false;
Expand Down