class AuthenticationServiceJwtImpl implements AuthenticationService {

    @Override
    @Nullable
    public RSocketAppPrincipal auth(String type, String credentials) {
        int tokenHashCode = credentials.hashCode();
        RSocketAppPrincipal principal = jwtVerifyCache.getIfPresent(tokenHashCode);
        for (JWTVerifier verifier : verifiers) {
            try {
                principal = new JwtPrincipal(verifier.verify(credentials), credentials);
                jwtVerifyCache.put(tokenHashCode, principal);
                break;
            } catch (JWTVerificationException ignore) {

            }
        }
        return principal;
    }

}

class AuthenticationServiceJwtImplTest {

    public AuthenticationServiceJwtImpl authenticationService;

    @Test
    public void testAuth() throws Exception {

        String subject = "testing-only";
        String credentials = authenticationService.generateCredentials(UUID.randomUUID().toString(), new String[]{"alibaba"}, new String[]{"default"}, new String[]{"internal"}, null, subject, new String[]{"leijuan"});
        System.out.println(credentials);
        Principal principal = authenticationService.auth("JWT", credentials);
        Assertions.assertNotNull(principal);
        Assertions.assertEquals(subject, principal.getName());
    }

}