@Test public void testValidPrivileges() throws Exception { KafkaPrivilegeValidator kafkaPrivilegeValidator = new KafkaPrivilegeValidator(); try { kafkaPrivilegeValidator.validate(new PrivilegeValidatorContext("host=host1->cluster=kafka-cluster->action=read")); } catch (ConfigurationException ex) { Assert.fail("Not expected ConfigurationException"); } try { kafkaPrivilegeValidator.validate(new PrivilegeValidatorContext("host=host1->topic=t1->action=read")); } catch (ConfigurationException ex) { Assert.fail("Not expected ConfigurationException"); } try { kafkaPrivilegeValidator.validate(new PrivilegeValidatorContext("host=host1->consumergroup=g1->action=read")); } catch (ConfigurationException ex) { Assert.fail("Not expected ConfigurationException"); } }
@Override public void validate(PrivilegeValidatorContext context) throws ConfigurationException { List<String> splits = Lists.newArrayList(); for (String section : AUTHORIZABLE_SPLITTER.split(context.getPrivilege())) { splits.add(section); } if (splits.size() < 2 || splits.size() > 3) { throw new ConfigurationException(KafkaPrivilegeHelpMsg); } if (isAction(splits.get(0))) { throw new ConfigurationException("Kafka privilege can not start with an action.\n" + KafkaPrivilegeHelpMsg); } KafkaAuthorizable hostAuthorizable = KafkaModelAuthorizables.from(splits.get(0)); if (hostAuthorizable == null) { throw new ConfigurationException("No Kafka authorizable found for " + splits.get(0) + "\n." + KafkaPrivilegeHelpMsg); } if (!(hostAuthorizable instanceof Host)) { throw new ConfigurationException("Kafka privilege must begin with host authorizable.\n" + KafkaPrivilegeHelpMsg); } if (splits.size() == 3) { if (isAction(splits.get(1))) { throw new ConfigurationException("Kafka privilege can have action only at the end of privilege.\n" + KafkaPrivilegeHelpMsg); } KafkaAuthorizable authorizable = KafkaModelAuthorizables.from(splits.get(1)); if (authorizable == null) { throw new ConfigurationException("No Kafka authorizable found for " + splits.get(1) + "\n." + KafkaPrivilegeHelpMsg); } if (authorizable instanceof Host) { throw new ConfigurationException("Host authorizable can be specified just once in a Kafka privilege.\n" + KafkaPrivilegeHelpMsg); } } if (!isAction(splits.get(splits.size() - 1))) { throw new ConfigurationException("Kafka privilege must end with a valid action.\n" + KafkaPrivilegeHelpMsg); } }
KafkaPrivilegeValidator implements PrivilegeValidator { @Override public void validate(PrivilegeValidatorContext context) throws ConfigurationException { List<String> splits = Lists.newArrayList(); for (String section : AUTHORIZABLE_SPLITTER.split(context.getPrivilege())) { splits.add(section); } if (splits.size() < 2 || splits.size() > 3) { throw new ConfigurationException(KafkaPrivilegeHelpMsg); } if (isAction(splits.get(0))) { throw new ConfigurationException("Kafka privilege can not start with an action.\n" + KafkaPrivilegeHelpMsg); } KafkaAuthorizable hostAuthorizable = KafkaModelAuthorizables.from(splits.get(0)); if (hostAuthorizable == null) { throw new ConfigurationException("No Kafka authorizable found for " + splits.get(0) + "\n." + KafkaPrivilegeHelpMsg); } if (!(hostAuthorizable instanceof Host)) { throw new ConfigurationException("Kafka privilege must begin with host authorizable.\n" + KafkaPrivilegeHelpMsg); } if (splits.size() == 3) { if (isAction(splits.get(1))) { throw new ConfigurationException("Kafka privilege can have action only at the end of privilege.\n" + KafkaPrivilegeHelpMsg); } KafkaAuthorizable authorizable = KafkaModelAuthorizables.from(splits.get(1)); if (authorizable == null) { throw new ConfigurationException("No Kafka authorizable found for " + splits.get(1) + "\n." + KafkaPrivilegeHelpMsg); } if (authorizable instanceof Host) { throw new ConfigurationException("Host authorizable can be specified just once in a Kafka privilege.\n" + KafkaPrivilegeHelpMsg); } } if (!isAction(splits.get(splits.size() - 1))) { throw new ConfigurationException("Kafka privilege must end with a valid action.\n" + KafkaPrivilegeHelpMsg); } } }
KafkaPrivilegeValidator implements PrivilegeValidator { @Override public void validate(PrivilegeValidatorContext context) throws ConfigurationException { List<String> splits = Lists.newArrayList(); for (String section : AUTHORIZABLE_SPLITTER.split(context.getPrivilege())) { splits.add(section); } if (splits.size() < 2 || splits.size() > 3) { throw new ConfigurationException(KafkaPrivilegeHelpMsg); } if (isAction(splits.get(0))) { throw new ConfigurationException("Kafka privilege can not start with an action.\n" + KafkaPrivilegeHelpMsg); } KafkaAuthorizable hostAuthorizable = KafkaModelAuthorizables.from(splits.get(0)); if (hostAuthorizable == null) { throw new ConfigurationException("No Kafka authorizable found for " + splits.get(0) + "\n." + KafkaPrivilegeHelpMsg); } if (!(hostAuthorizable instanceof Host)) { throw new ConfigurationException("Kafka privilege must begin with host authorizable.\n" + KafkaPrivilegeHelpMsg); } if (splits.size() == 3) { if (isAction(splits.get(1))) { throw new ConfigurationException("Kafka privilege can have action only at the end of privilege.\n" + KafkaPrivilegeHelpMsg); } KafkaAuthorizable authorizable = KafkaModelAuthorizables.from(splits.get(1)); if (authorizable == null) { throw new ConfigurationException("No Kafka authorizable found for " + splits.get(1) + "\n." + KafkaPrivilegeHelpMsg); } if (authorizable instanceof Host) { throw new ConfigurationException("Host authorizable can be specified just once in a Kafka privilege.\n" + KafkaPrivilegeHelpMsg); } } if (!isAction(splits.get(splits.size() - 1))) { throw new ConfigurationException("Kafka privilege must end with a valid action.\n" + KafkaPrivilegeHelpMsg); } } KafkaPrivilegeValidator(); }
KafkaPrivilegeValidator implements PrivilegeValidator { @Override public void validate(PrivilegeValidatorContext context) throws ConfigurationException { List<String> splits = Lists.newArrayList(); for (String section : AUTHORIZABLE_SPLITTER.split(context.getPrivilege())) { splits.add(section); } if (splits.size() < 2 || splits.size() > 3) { throw new ConfigurationException(KafkaPrivilegeHelpMsg); } if (isAction(splits.get(0))) { throw new ConfigurationException("Kafka privilege can not start with an action.\n" + KafkaPrivilegeHelpMsg); } KafkaAuthorizable hostAuthorizable = KafkaModelAuthorizables.from(splits.get(0)); if (hostAuthorizable == null) { throw new ConfigurationException("No Kafka authorizable found for " + splits.get(0) + "\n." + KafkaPrivilegeHelpMsg); } if (!(hostAuthorizable instanceof Host)) { throw new ConfigurationException("Kafka privilege must begin with host authorizable.\n" + KafkaPrivilegeHelpMsg); } if (splits.size() == 3) { if (isAction(splits.get(1))) { throw new ConfigurationException("Kafka privilege can have action only at the end of privilege.\n" + KafkaPrivilegeHelpMsg); } KafkaAuthorizable authorizable = KafkaModelAuthorizables.from(splits.get(1)); if (authorizable == null) { throw new ConfigurationException("No Kafka authorizable found for " + splits.get(1) + "\n." + KafkaPrivilegeHelpMsg); } if (authorizable instanceof Host) { throw new ConfigurationException("Host authorizable can be specified just once in a Kafka privilege.\n" + KafkaPrivilegeHelpMsg); } } if (!isAction(splits.get(splits.size() - 1))) { throw new ConfigurationException("Kafka privilege must end with a valid action.\n" + KafkaPrivilegeHelpMsg); } } KafkaPrivilegeValidator(); @Override void validate(PrivilegeValidatorContext context); }
KafkaPrivilegeValidator implements PrivilegeValidator { @Override public void validate(PrivilegeValidatorContext context) throws ConfigurationException { List<String> splits = Lists.newArrayList(); for (String section : AUTHORIZABLE_SPLITTER.split(context.getPrivilege())) { splits.add(section); } if (splits.size() < 2 || splits.size() > 3) { throw new ConfigurationException(KafkaPrivilegeHelpMsg); } if (isAction(splits.get(0))) { throw new ConfigurationException("Kafka privilege can not start with an action.\n" + KafkaPrivilegeHelpMsg); } KafkaAuthorizable hostAuthorizable = KafkaModelAuthorizables.from(splits.get(0)); if (hostAuthorizable == null) { throw new ConfigurationException("No Kafka authorizable found for " + splits.get(0) + "\n." + KafkaPrivilegeHelpMsg); } if (!(hostAuthorizable instanceof Host)) { throw new ConfigurationException("Kafka privilege must begin with host authorizable.\n" + KafkaPrivilegeHelpMsg); } if (splits.size() == 3) { if (isAction(splits.get(1))) { throw new ConfigurationException("Kafka privilege can have action only at the end of privilege.\n" + KafkaPrivilegeHelpMsg); } KafkaAuthorizable authorizable = KafkaModelAuthorizables.from(splits.get(1)); if (authorizable == null) { throw new ConfigurationException("No Kafka authorizable found for " + splits.get(1) + "\n." + KafkaPrivilegeHelpMsg); } if (authorizable instanceof Host) { throw new ConfigurationException("Host authorizable can be specified just once in a Kafka privilege.\n" + KafkaPrivilegeHelpMsg); } } if (!isAction(splits.get(splits.size() - 1))) { throw new ConfigurationException("Kafka privilege must end with a valid action.\n" + KafkaPrivilegeHelpMsg); } } KafkaPrivilegeValidator(); @Override void validate(PrivilegeValidatorContext context); static final String KafkaPrivilegeHelpMsg; }