CustomAuthorizer implements Authorizer { protected List<OAuthScope> parseScopes(java.util.Set<String> scopes) { List<OAuthScope> result = new ArrayList<>(); for (String scope : scopes) { String[] scopeArray = scope.split("\\s+"); for (String str : scopeArray){ convertScope(result, str); } } return result; } CustomAuthorizer(); @Override boolean authorize(Session session, Operation operation, Resource resource); @Override void addAcls(Set<Acl> acls, Resource resource); @Override boolean removeAcls(Set<Acl> acls, Resource resource); @Override boolean removeAcls(Resource resource); @Override Set<Acl> getAcls(Resource resource); @Override Map<Resource, Set<Acl>> getAcls(KafkaPrincipal principal); @Override Map<Resource, Set<Acl>> getAcls(); @Override void close(); @Override void configure(java.util.Map<String, ?> map);  }
@Test public void parseScopes() { Set<String> set = new HashSet<>(); set.add("urn:kafka:topic:test:write"); set.add("urn:kafka:group:test:read"); CustomAuthorizer authorizer = new CustomAuthorizer(); List<OAuthScope> scopes = authorizer.parseScopes(set); assertTrue(scopes.size() == 2); assertTrue(scopes.get(0).getOperation().equals("write")); assertTrue(scopes.get(0).getResourceName().equals("test")); assertTrue(scopes.get(0).getResourceType().equals("topic")); }
@Test public void parseBadScope() { Set<String> set = new HashSet<>(); set.add("urn:test:write"); CustomAuthorizer authorizer = new CustomAuthorizer(); List<OAuthScope> scopes = authorizer.parseScopes(set); assertTrue(scopes.size() == 0); }