ServiceMeshInspectorImpl implements ServiceMeshInspector { @Override public boolean isRequestAllowed(RSocketAppPrincipal requesterPrincipal, String routing, RSocketAppPrincipal responderPrincipal) { if (!authRequired) return true; int relationHashCode = (requesterPrincipal.hashCode() + ":" + responderPrincipal.hashCode()).hashCode(); if (whiteRelationBitmap.contains(relationHashCode)) { return true; } int aclHashCode = (requesterPrincipal.hashCode() + ":" + routing + ":" + responderPrincipal.hashCode()).hashCode(); if (whiteRelationBitmap.contains(aclHashCode)) { return true; } boolean orgFriendly = false; for (String principalOrg : requesterPrincipal.getOrganizations()) { if (responderPrincipal.getOrganizations().contains(principalOrg)) { orgFriendly = true; break; } } if (orgFriendly) { boolean serviceAccountFriendly = false; for (String serviceAccount : requesterPrincipal.getServiceAccounts()) { if (responderPrincipal.getServiceAccounts().contains(serviceAccount)) { serviceAccountFriendly = true; break; } } if (serviceAccountFriendly) { whiteRelationBitmap.add(relationHashCode); return true; } } return false; } ServiceMeshInspectorImpl();  ServiceMeshInspectorImpl(boolean authRequired); void setAuthRequired(boolean authRequired); @Override boolean isRequestAllowed(RSocketAppPrincipal requesterPrincipal, String routing, RSocketAppPrincipal responderPrincipal); @Override Integer getWhiteRelationCount();  }
@Test public void testAuth() throws Exception { String routing="com.alibaba.user.UserService"; Set<String> serviceAccounts = toSet("serviceAccount1", "serviceAccount2"); Set<String> serviceAccounts2 = toSet("serviceAccount3", "serviceAccount4"); Set<String> orgs = toSet("org1", "or2"); Set<String> orgs2 = toSet("org3", "or4"); RSocketAppPrincipalMock requesterPrincipal = new RSocketAppPrincipalMock("app1", orgs, serviceAccounts); RSocketAppPrincipalMock responderPrincipal = new RSocketAppPrincipalMock("app1", orgs, serviceAccounts); Assertions.assertTrue(serviceMeshInspector.isRequestAllowed(requesterPrincipal, routing, responderPrincipal)); Assertions.assertFalse(serviceMeshInspector.isRequestAllowed(requesterPrincipal, routing, new RSocketAppPrincipalMock("app1", orgs2, serviceAccounts))); Assertions.assertFalse(serviceMeshInspector.isRequestAllowed(requesterPrincipal, routing, new RSocketAppPrincipalMock("app1", orgs, serviceAccounts2))); }