Adapt to catch InvalidJwtException (?)

This commit is contained in:
jeffcheasey88 2023-09-18 12:03:26 +02:00
parent 06ac691747
commit b58934cff8
2 changed files with 10 additions and 8 deletions

View file

@ -24,7 +24,6 @@ public class Client<U extends User> extends Thread{
Context context = null;
try{
String[] headers = reader.readLine().split("\\s");
System.out.println(Arrays.toString(headers));
reader.readHeaders();
RequestType type = RequestType.valueOf(headers[0]);
@ -33,7 +32,7 @@ public class Client<U extends User> extends Thread{
writer.flush();
writer.close();
}catch(InvalidJwtException e){
e.printStackTrace();
// e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
if(context != null && context.getResponseCode() == 0){
@ -47,17 +46,19 @@ public class Client<U extends User> extends Thread{
if(context != null) logger.setValue(context);
}
private User isLogin(Router<U> router, RequestType type, HttpReader reader) throws Exception{
private User isLogin(Router<U> router, RequestType type, HttpReader reader) throws InvalidJwtException{
String auth = reader.getHeader("Authorization");
if(auth == null) return null;
auth = auth.substring(7);
try{
return this.router.getUser(auth);
}catch(Exception e){
}catch(InvalidJwtException e){
e.printStackTrace();
try{
writer.response(401, router.getDefaultHeaders(type));
writer.flush();
writer.close();
}catch(Exception ex){}
throw e;
}
}

View file

@ -16,6 +16,7 @@ import org.jose4j.jwk.RsaJwkGenerator;
import org.jose4j.jws.AlgorithmIdentifiers;
import org.jose4j.jws.JsonWebSignature;
import org.jose4j.jwt.JwtClaims;
import org.jose4j.jwt.consumer.InvalidJwtException;
import org.jose4j.jwt.consumer.JwtConsumer;
import org.jose4j.jwt.consumer.JwtConsumerBuilder;
import org.jose4j.lang.JoseException;
@ -107,7 +108,7 @@ public class Router<U extends User>{
return this;
}
public U getUser(String token) throws Exception{
public U getUser(String token) throws InvalidJwtException{
return this.userCreator.apply(this.jwtConsumer.processToClaims(token));
}