@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()); }
@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; }
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; } }
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; } AuthenticationServiceJwtImpl(); }
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; } AuthenticationServiceJwtImpl(); @Override @Nullable RSocketAppPrincipal auth(String type, String credentials); String generateCredentials(String id, String[] organizations, String[] serviceAccounts, String[] roles, String[] authorities, String sub, String[] audience); RSAPrivateKey readPrivateKey(); RSAPublicKey readPublicKey(); byte[] toBytes(InputStream inputStream); }
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; } AuthenticationServiceJwtImpl(); @Override @Nullable RSocketAppPrincipal auth(String type, String credentials); String generateCredentials(String id, String[] organizations, String[] serviceAccounts, String[] roles, String[] authorities, String sub, String[] audience); RSAPrivateKey readPrivateKey(); RSAPublicKey readPublicKey(); byte[] toBytes(InputStream inputStream);  }