@Test public void testInvalidJwtAccessToken_假如_当输入随机字串_那么返回true表示token无效() { String authentication = BEARER + "im random string"; Assert.assertTrue(authService.invalidJwtAccessToken(authentication)); }
@Override public boolean invalidJwtAccessToken(String authentication) { verifier = Optional.ofNullable(verifier).orElse(new MacSigner(signingKey)); boolean invalid = Boolean.TRUE; try { Jwt jwt = getJwt(authentication); jwt.verifySignature(verifier); invalid = Boolean.FALSE; } catch (InvalidSignatureException | IllegalArgumentException ex) { log.warn("user token has expired or signature error "); } return invalid; }
AuthService implements IAuthService { @Override public boolean invalidJwtAccessToken(String authentication) { verifier = Optional.ofNullable(verifier).orElse(new MacSigner(signingKey)); boolean invalid = Boolean.TRUE; try { Jwt jwt = getJwt(authentication); jwt.verifySignature(verifier); invalid = Boolean.FALSE; } catch (InvalidSignatureException | IllegalArgumentException ex) { log.warn("user token has expired or signature error "); } return invalid; } }
AuthService implements IAuthService { @Override public boolean invalidJwtAccessToken(String authentication) { verifier = Optional.ofNullable(verifier).orElse(new MacSigner(signingKey)); boolean invalid = Boolean.TRUE; try { Jwt jwt = getJwt(authentication); jwt.verifySignature(verifier); invalid = Boolean.FALSE; } catch (InvalidSignatureException | IllegalArgumentException ex) { log.warn("user token has expired or signature error "); } return invalid; }  }
AuthService implements IAuthService { @Override public boolean invalidJwtAccessToken(String authentication) { verifier = Optional.ofNullable(verifier).orElse(new MacSigner(signingKey)); boolean invalid = Boolean.TRUE; try { Jwt jwt = getJwt(authentication); jwt.verifySignature(verifier); invalid = Boolean.FALSE; } catch (InvalidSignatureException | IllegalArgumentException ex) { log.warn("user token has expired or signature error "); } return invalid; }  @Override Result authenticate(String authentication, String url, String method); @Override boolean ignoreAuthentication(String url); @Override boolean hasPermission(Result authResult); @Override boolean hasPermission(String authentication, String url, String method); @Override boolean invalidJwtAccessToken(String authentication); @Override Jwt getJwt(String authentication); }
AuthService implements IAuthService { @Override public boolean invalidJwtAccessToken(String authentication) { verifier = Optional.ofNullable(verifier).orElse(new MacSigner(signingKey)); boolean invalid = Boolean.TRUE; try { Jwt jwt = getJwt(authentication); jwt.verifySignature(verifier); invalid = Boolean.FALSE; } catch (InvalidSignatureException | IllegalArgumentException ex) { log.warn("user token has expired or signature error "); } return invalid; }  @Override Result authenticate(String authentication, String url, String method); @Override boolean ignoreAuthentication(String url); @Override boolean hasPermission(Result authResult); @Override boolean hasPermission(String authentication, String url, String method); @Override boolean invalidJwtAccessToken(String authentication); @Override Jwt getJwt(String authentication);  }