CustomAuthorizer implements Authorizer { protected boolean checkAuthorization(List<OAuthScope> scopeInfo, Resource resource, String operation) { for (int i = 0; i < scopeInfo.size(); i++) { OAuthScope scope = scopeInfo.get(i); String lowerCaseOperation = operation.toLowerCase(); String lowerCaseResourceName = resource.name().toLowerCase(); String lowerCaseCaseResourceType = resource.resourceType().toString().toLowerCase(); boolean operationVal = scope.getOperation().toLowerCase().equals(lowerCaseOperation); boolean nameVal = scope.getResourceName().toLowerCase().equals(lowerCaseResourceName); boolean typeVal = scope.getResourceType().toLowerCase().equals(lowerCaseCaseResourceType); if (operationVal && nameVal && typeVal) { log.info("Successfully Authorized."); return true; } } log.info("Not Authorized to operate on the given resource."); return false; } 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 checkAuthorization() { List<OAuthScope> list = new ArrayList<>(); OAuthScope scope = new OAuthScope(); scope.setOperation("Write"); scope.setResourceName("test"); scope.setResourceType("topic"); list.add(scope); Resource resource = new Resource(ResourceType.fromString("Topic"), "TEST"); CustomAuthorizer authorizer = new CustomAuthorizer(); boolean result = authorizer.checkAuthorization(list, resource, "write"); assertTrue(result); }