target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test public void unknownConversions() { assertThrows(RuntimeException.class, () -> { final TypeSchema ts = new TypeSchema(); final TypeRegistry mockRegistry = new TypeRegistryImpl(); ts.put("type", "integer"); ts.put("format", "int63"); ts.getTypeClass(mockRegistry); }); assertThrows(RuntimeException.class, () -> { final TypeSchema ts = new TypeSchema(); final TypeRegistry mockRegistry = new TypeRegistryImpl(); ts.put("type", "number"); ts.put("format", "approximate"); ts.getTypeClass(mockRegistry); }); }
public Class<?> getTypeClass(final TypeRegistry typeRegistry) { Class<?> clz = null; String type = getType(); if (type == null) { type = "object"; } if (type.contentEquals("string")) { final String format = getFormat(); if (format != null && format.contentEquals("uint16")) { clz = char.class; } else { clz = String.class; } } else if (type.contentEquals("integer")) { final String format = getFormat(); switch (format) { case "int8": clz = byte.class; break; case "int16": clz = short.class; break; case "int32": clz = int.class; break; case "int64": clz = long.class; break; default: throw new RuntimeException("Unknown format for integer of " + format); } } else if (type.contentEquals("number")) { final String format = getFormat(); switch (format) { case "double": clz = double.class; break; case "float": clz = float.class; break; default: throw new RuntimeException("Unknown format for number of " + format); } } else if (type.contentEquals("boolean")) { clz = boolean.class; } else if (type.contentEquals("object")) { final String ref = this.getRef(); final String format = ref.substring(ref.lastIndexOf("/") + 1); clz = typeRegistry.getDataType(format).getTypeClass(); } else if (type.contentEquals("array")) { final TypeSchema typdef = this.getItems(); final Class<?> arrayType = typdef.getTypeClass(typeRegistry); clz = Array.newInstance(arrayType, 0).getClass(); } return clz; }
TypeSchema extends HashMap<String, Object> { public Class<?> getTypeClass(final TypeRegistry typeRegistry) { Class<?> clz = null; String type = getType(); if (type == null) { type = "object"; } if (type.contentEquals("string")) { final String format = getFormat(); if (format != null && format.contentEquals("uint16")) { clz = char.class; } else { clz = String.class; } } else if (type.contentEquals("integer")) { final String format = getFormat(); switch (format) { case "int8": clz = byte.class; break; case "int16": clz = short.class; break; case "int32": clz = int.class; break; case "int64": clz = long.class; break; default: throw new RuntimeException("Unknown format for integer of " + format); } } else if (type.contentEquals("number")) { final String format = getFormat(); switch (format) { case "double": clz = double.class; break; case "float": clz = float.class; break; default: throw new RuntimeException("Unknown format for number of " + format); } } else if (type.contentEquals("boolean")) { clz = boolean.class; } else if (type.contentEquals("object")) { final String ref = this.getRef(); final String format = ref.substring(ref.lastIndexOf("/") + 1); clz = typeRegistry.getDataType(format).getTypeClass(); } else if (type.contentEquals("array")) { final TypeSchema typdef = this.getItems(); final Class<?> arrayType = typdef.getTypeClass(typeRegistry); clz = Array.newInstance(arrayType, 0).getClass(); } return clz; } }
TypeSchema extends HashMap<String, Object> { public Class<?> getTypeClass(final TypeRegistry typeRegistry) { Class<?> clz = null; String type = getType(); if (type == null) { type = "object"; } if (type.contentEquals("string")) { final String format = getFormat(); if (format != null && format.contentEquals("uint16")) { clz = char.class; } else { clz = String.class; } } else if (type.contentEquals("integer")) { final String format = getFormat(); switch (format) { case "int8": clz = byte.class; break; case "int16": clz = short.class; break; case "int32": clz = int.class; break; case "int64": clz = long.class; break; default: throw new RuntimeException("Unknown format for integer of " + format); } } else if (type.contentEquals("number")) { final String format = getFormat(); switch (format) { case "double": clz = double.class; break; case "float": clz = float.class; break; default: throw new RuntimeException("Unknown format for number of " + format); } } else if (type.contentEquals("boolean")) { clz = boolean.class; } else if (type.contentEquals("object")) { final String ref = this.getRef(); final String format = ref.substring(ref.lastIndexOf("/") + 1); clz = typeRegistry.getDataType(format).getTypeClass(); } else if (type.contentEquals("array")) { final TypeSchema typdef = this.getItems(); final Class<?> arrayType = typdef.getTypeClass(typeRegistry); clz = Array.newInstance(arrayType, 0).getClass(); } return clz; } TypeSchema(); }
TypeSchema extends HashMap<String, Object> { public Class<?> getTypeClass(final TypeRegistry typeRegistry) { Class<?> clz = null; String type = getType(); if (type == null) { type = "object"; } if (type.contentEquals("string")) { final String format = getFormat(); if (format != null && format.contentEquals("uint16")) { clz = char.class; } else { clz = String.class; } } else if (type.contentEquals("integer")) { final String format = getFormat(); switch (format) { case "int8": clz = byte.class; break; case "int16": clz = short.class; break; case "int32": clz = int.class; break; case "int64": clz = long.class; break; default: throw new RuntimeException("Unknown format for integer of " + format); } } else if (type.contentEquals("number")) { final String format = getFormat(); switch (format) { case "double": clz = double.class; break; case "float": clz = float.class; break; default: throw new RuntimeException("Unknown format for number of " + format); } } else if (type.contentEquals("boolean")) { clz = boolean.class; } else if (type.contentEquals("object")) { final String ref = this.getRef(); final String format = ref.substring(ref.lastIndexOf("/") + 1); clz = typeRegistry.getDataType(format).getTypeClass(); } else if (type.contentEquals("array")) { final TypeSchema typdef = this.getItems(); final Class<?> arrayType = typdef.getTypeClass(typeRegistry); clz = Array.newInstance(arrayType, 0).getClass(); } return clz; } TypeSchema(); String getType(); TypeSchema getItems(); String getRef(); String getFormat(); Class<?> getTypeClass(final TypeRegistry typeRegistry); static TypeSchema typeConvert(final Class<?> clz); void validate(final JSONObject obj); }
TypeSchema extends HashMap<String, Object> { public Class<?> getTypeClass(final TypeRegistry typeRegistry) { Class<?> clz = null; String type = getType(); if (type == null) { type = "object"; } if (type.contentEquals("string")) { final String format = getFormat(); if (format != null && format.contentEquals("uint16")) { clz = char.class; } else { clz = String.class; } } else if (type.contentEquals("integer")) { final String format = getFormat(); switch (format) { case "int8": clz = byte.class; break; case "int16": clz = short.class; break; case "int32": clz = int.class; break; case "int64": clz = long.class; break; default: throw new RuntimeException("Unknown format for integer of " + format); } } else if (type.contentEquals("number")) { final String format = getFormat(); switch (format) { case "double": clz = double.class; break; case "float": clz = float.class; break; default: throw new RuntimeException("Unknown format for number of " + format); } } else if (type.contentEquals("boolean")) { clz = boolean.class; } else if (type.contentEquals("object")) { final String ref = this.getRef(); final String format = ref.substring(ref.lastIndexOf("/") + 1); clz = typeRegistry.getDataType(format).getTypeClass(); } else if (type.contentEquals("array")) { final TypeSchema typdef = this.getItems(); final Class<?> arrayType = typdef.getTypeClass(typeRegistry); clz = Array.newInstance(arrayType, 0).getClass(); } return clz; } TypeSchema(); String getType(); TypeSchema getItems(); String getRef(); String getFormat(); Class<?> getTypeClass(final TypeRegistry typeRegistry); static TypeSchema typeConvert(final Class<?> clz); void validate(final JSONObject obj); }
@Test public void validate() { final TypeSchema ts = TypeSchema.typeConvert(org.hyperledger.fabric.contract.MyType.class); final DataTypeDefinition dtd = new DataTypeDefinitionImpl(org.hyperledger.fabric.contract.MyType.class); MetadataBuilder.addComponent(dtd); final JSONObject json = new JSONObject(); ts.validate(json); }
public void validate(final JSONObject obj) { final JSONObject toValidate = new JSONObject(); toValidate.put("prop", obj); JSONObject schemaJSON; if (this.containsKey("schema")) { schemaJSON = new JSONObject((Map) this.get("schema")); } else { schemaJSON = new JSONObject(this); } final JSONObject rawSchema = new JSONObject(); rawSchema.put("properties", new JSONObject().put("prop", schemaJSON)); rawSchema.put("components", new JSONObject().put("schemas", MetadataBuilder.getComponents())); final Schema schema = SchemaLoader.load(rawSchema); try { schema.validate(toValidate); } catch (final ValidationException e) { final StringBuilder sb = new StringBuilder("Validation Errors::"); e.getCausingExceptions().stream().map(ValidationException::getMessage).forEach(sb::append); logger.info(sb.toString()); throw new ContractRuntimeException(sb.toString(), e); } }
TypeSchema extends HashMap<String, Object> { public void validate(final JSONObject obj) { final JSONObject toValidate = new JSONObject(); toValidate.put("prop", obj); JSONObject schemaJSON; if (this.containsKey("schema")) { schemaJSON = new JSONObject((Map) this.get("schema")); } else { schemaJSON = new JSONObject(this); } final JSONObject rawSchema = new JSONObject(); rawSchema.put("properties", new JSONObject().put("prop", schemaJSON)); rawSchema.put("components", new JSONObject().put("schemas", MetadataBuilder.getComponents())); final Schema schema = SchemaLoader.load(rawSchema); try { schema.validate(toValidate); } catch (final ValidationException e) { final StringBuilder sb = new StringBuilder("Validation Errors::"); e.getCausingExceptions().stream().map(ValidationException::getMessage).forEach(sb::append); logger.info(sb.toString()); throw new ContractRuntimeException(sb.toString(), e); } } }
TypeSchema extends HashMap<String, Object> { public void validate(final JSONObject obj) { final JSONObject toValidate = new JSONObject(); toValidate.put("prop", obj); JSONObject schemaJSON; if (this.containsKey("schema")) { schemaJSON = new JSONObject((Map) this.get("schema")); } else { schemaJSON = new JSONObject(this); } final JSONObject rawSchema = new JSONObject(); rawSchema.put("properties", new JSONObject().put("prop", schemaJSON)); rawSchema.put("components", new JSONObject().put("schemas", MetadataBuilder.getComponents())); final Schema schema = SchemaLoader.load(rawSchema); try { schema.validate(toValidate); } catch (final ValidationException e) { final StringBuilder sb = new StringBuilder("Validation Errors::"); e.getCausingExceptions().stream().map(ValidationException::getMessage).forEach(sb::append); logger.info(sb.toString()); throw new ContractRuntimeException(sb.toString(), e); } } TypeSchema(); }
TypeSchema extends HashMap<String, Object> { public void validate(final JSONObject obj) { final JSONObject toValidate = new JSONObject(); toValidate.put("prop", obj); JSONObject schemaJSON; if (this.containsKey("schema")) { schemaJSON = new JSONObject((Map) this.get("schema")); } else { schemaJSON = new JSONObject(this); } final JSONObject rawSchema = new JSONObject(); rawSchema.put("properties", new JSONObject().put("prop", schemaJSON)); rawSchema.put("components", new JSONObject().put("schemas", MetadataBuilder.getComponents())); final Schema schema = SchemaLoader.load(rawSchema); try { schema.validate(toValidate); } catch (final ValidationException e) { final StringBuilder sb = new StringBuilder("Validation Errors::"); e.getCausingExceptions().stream().map(ValidationException::getMessage).forEach(sb::append); logger.info(sb.toString()); throw new ContractRuntimeException(sb.toString(), e); } } TypeSchema(); String getType(); TypeSchema getItems(); String getRef(); String getFormat(); Class<?> getTypeClass(final TypeRegistry typeRegistry); static TypeSchema typeConvert(final Class<?> clz); void validate(final JSONObject obj); }
TypeSchema extends HashMap<String, Object> { public void validate(final JSONObject obj) { final JSONObject toValidate = new JSONObject(); toValidate.put("prop", obj); JSONObject schemaJSON; if (this.containsKey("schema")) { schemaJSON = new JSONObject((Map) this.get("schema")); } else { schemaJSON = new JSONObject(this); } final JSONObject rawSchema = new JSONObject(); rawSchema.put("properties", new JSONObject().put("prop", schemaJSON)); rawSchema.put("components", new JSONObject().put("schemas", MetadataBuilder.getComponents())); final Schema schema = SchemaLoader.load(rawSchema); try { schema.validate(toValidate); } catch (final ValidationException e) { final StringBuilder sb = new StringBuilder("Validation Errors::"); e.getCausingExceptions().stream().map(ValidationException::getMessage).forEach(sb::append); logger.info(sb.toString()); throw new ContractRuntimeException(sb.toString(), e); } } TypeSchema(); String getType(); TypeSchema getItems(); String getRef(); String getFormat(); Class<?> getTypeClass(final TypeRegistry typeRegistry); static TypeSchema typeConvert(final Class<?> clz); void validate(final JSONObject obj); }
@Test public void systemContract() { final SystemContract system = new SystemContract(); final ChaincodeStub stub = new ChaincodeStubNaiveImpl(); system.getMetadata(new Context(stub)); }
public static String getMetadata() { return metadata().toString(); }
MetadataBuilder { public static String getMetadata() { return metadata().toString(); } }
MetadataBuilder { public static String getMetadata() { return metadata().toString(); } private MetadataBuilder(); }
MetadataBuilder { public static String getMetadata() { return metadata().toString(); } private MetadataBuilder(); static void validate(); static void initialize(final RoutingRegistry registry, final TypeRegistry typeRegistry); static void addComponent(final DataTypeDefinition datatype); @SuppressWarnings("serial") static String addContract(final ContractDefinition contractDefinition); static void addTransaction(final TxFunction txFunction, final String contractName); static String getMetadata(); static String debugString(); static Map<?, ?> getComponents(); }
MetadataBuilder { public static String getMetadata() { return metadata().toString(); } private MetadataBuilder(); static void validate(); static void initialize(final RoutingRegistry registry, final TypeRegistry typeRegistry); static void addComponent(final DataTypeDefinition datatype); @SuppressWarnings("serial") static String addContract(final ContractDefinition contractDefinition); static void addTransaction(final TxFunction txFunction, final String contractName); static String getMetadata(); static String debugString(); static Map<?, ?> getComponents(); }
@Test public void toBuffer() { final TypeRegistry tr = TypeRegistry.getRegistry(); tr.addDataType(MyType.class); MetadataBuilder.addComponent(tr.getDataType("MyType")); final JSONTransactionSerializer serializer = new JSONTransactionSerializer(); byte[] bytes = serializer.toBuffer("hello world", TypeSchema.typeConvert(String.class)); assertThat(new String(bytes, StandardCharsets.UTF_8), equalTo("hello world")); bytes = serializer.toBuffer(42, TypeSchema.typeConvert(Integer.class)); assertThat(new String(bytes, StandardCharsets.UTF_8), equalTo("42")); bytes = serializer.toBuffer(true, TypeSchema.typeConvert(Boolean.class)); assertThat(new String(bytes, StandardCharsets.UTF_8), equalTo("true")); bytes = serializer.toBuffer(new MyType(), TypeSchema.typeConvert(MyType.class)); assertThat(new String(bytes, StandardCharsets.UTF_8), equalTo("{}")); bytes = serializer.toBuffer(new MyType().setValue("Hello"), TypeSchema.typeConvert(MyType.class)); assertThat(new String(bytes, StandardCharsets.UTF_8), equalTo("{\"value\":\"Hello\"}")); final MyType[] array = new MyType[2]; array[0] = new MyType().setValue("hello"); array[1] = new MyType().setValue("world"); bytes = serializer.toBuffer(array, TypeSchema.typeConvert(MyType[].class)); final byte[] buffer = "[{\"value\":\"hello\"},{\"value\":\"world\"}]".getBytes(StandardCharsets.UTF_8); System.out.println(new String(buffer, StandardCharsets.UTF_8)); System.out.println(new String(bytes, StandardCharsets.UTF_8)); assertThat(bytes, equalTo(buffer)); }
@Override public byte[] toBuffer(final Object value, final TypeSchema ts) { logger.debug(() -> "Schema to convert is " + ts); byte[] buffer = null; if (value != null) { final String type = ts.getType(); if (type != null) { switch (type) { case "array": final JSONArray array = normalizeArray(new JSONArray(value), ts); buffer = array.toString().getBytes(UTF_8); break; case "string": final String format = ts.getFormat(); if (format != null && format.contentEquals("uint16")) { buffer = Character.valueOf((char) value).toString().getBytes(UTF_8); } else { buffer = ((String) value).getBytes(UTF_8); } break; case "number": case "integer": case "boolean": default: buffer = (value).toString().getBytes(UTF_8); } } else { final DataTypeDefinition dtd = this.typeRegistry.getDataType(ts); final Set<String> keySet = dtd.getProperties().keySet(); final String[] propNames = keySet.toArray(new String[keySet.size()]); final JSONObject obj = new JSONObject(new JSONObject(value), propNames); buffer = obj.toString().getBytes(UTF_8); } } return buffer; }
JSONTransactionSerializer implements SerializerInterface { @Override public byte[] toBuffer(final Object value, final TypeSchema ts) { logger.debug(() -> "Schema to convert is " + ts); byte[] buffer = null; if (value != null) { final String type = ts.getType(); if (type != null) { switch (type) { case "array": final JSONArray array = normalizeArray(new JSONArray(value), ts); buffer = array.toString().getBytes(UTF_8); break; case "string": final String format = ts.getFormat(); if (format != null && format.contentEquals("uint16")) { buffer = Character.valueOf((char) value).toString().getBytes(UTF_8); } else { buffer = ((String) value).getBytes(UTF_8); } break; case "number": case "integer": case "boolean": default: buffer = (value).toString().getBytes(UTF_8); } } else { final DataTypeDefinition dtd = this.typeRegistry.getDataType(ts); final Set<String> keySet = dtd.getProperties().keySet(); final String[] propNames = keySet.toArray(new String[keySet.size()]); final JSONObject obj = new JSONObject(new JSONObject(value), propNames); buffer = obj.toString().getBytes(UTF_8); } } return buffer; } }
JSONTransactionSerializer implements SerializerInterface { @Override public byte[] toBuffer(final Object value, final TypeSchema ts) { logger.debug(() -> "Schema to convert is " + ts); byte[] buffer = null; if (value != null) { final String type = ts.getType(); if (type != null) { switch (type) { case "array": final JSONArray array = normalizeArray(new JSONArray(value), ts); buffer = array.toString().getBytes(UTF_8); break; case "string": final String format = ts.getFormat(); if (format != null && format.contentEquals("uint16")) { buffer = Character.valueOf((char) value).toString().getBytes(UTF_8); } else { buffer = ((String) value).getBytes(UTF_8); } break; case "number": case "integer": case "boolean": default: buffer = (value).toString().getBytes(UTF_8); } } else { final DataTypeDefinition dtd = this.typeRegistry.getDataType(ts); final Set<String> keySet = dtd.getProperties().keySet(); final String[] propNames = keySet.toArray(new String[keySet.size()]); final JSONObject obj = new JSONObject(new JSONObject(value), propNames); buffer = obj.toString().getBytes(UTF_8); } } return buffer; } JSONTransactionSerializer(); }
JSONTransactionSerializer implements SerializerInterface { @Override public byte[] toBuffer(final Object value, final TypeSchema ts) { logger.debug(() -> "Schema to convert is " + ts); byte[] buffer = null; if (value != null) { final String type = ts.getType(); if (type != null) { switch (type) { case "array": final JSONArray array = normalizeArray(new JSONArray(value), ts); buffer = array.toString().getBytes(UTF_8); break; case "string": final String format = ts.getFormat(); if (format != null && format.contentEquals("uint16")) { buffer = Character.valueOf((char) value).toString().getBytes(UTF_8); } else { buffer = ((String) value).getBytes(UTF_8); } break; case "number": case "integer": case "boolean": default: buffer = (value).toString().getBytes(UTF_8); } } else { final DataTypeDefinition dtd = this.typeRegistry.getDataType(ts); final Set<String> keySet = dtd.getProperties().keySet(); final String[] propNames = keySet.toArray(new String[keySet.size()]); final JSONObject obj = new JSONObject(new JSONObject(value), propNames); buffer = obj.toString().getBytes(UTF_8); } } return buffer; } JSONTransactionSerializer(); @Override byte[] toBuffer(final Object value, final TypeSchema ts); @Override Object fromBuffer(final byte[] buffer, final TypeSchema ts); }
JSONTransactionSerializer implements SerializerInterface { @Override public byte[] toBuffer(final Object value, final TypeSchema ts) { logger.debug(() -> "Schema to convert is " + ts); byte[] buffer = null; if (value != null) { final String type = ts.getType(); if (type != null) { switch (type) { case "array": final JSONArray array = normalizeArray(new JSONArray(value), ts); buffer = array.toString().getBytes(UTF_8); break; case "string": final String format = ts.getFormat(); if (format != null && format.contentEquals("uint16")) { buffer = Character.valueOf((char) value).toString().getBytes(UTF_8); } else { buffer = ((String) value).getBytes(UTF_8); } break; case "number": case "integer": case "boolean": default: buffer = (value).toString().getBytes(UTF_8); } } else { final DataTypeDefinition dtd = this.typeRegistry.getDataType(ts); final Set<String> keySet = dtd.getProperties().keySet(); final String[] propNames = keySet.toArray(new String[keySet.size()]); final JSONObject obj = new JSONObject(new JSONObject(value), propNames); buffer = obj.toString().getBytes(UTF_8); } } return buffer; } JSONTransactionSerializer(); @Override byte[] toBuffer(final Object value, final TypeSchema ts); @Override Object fromBuffer(final byte[] buffer, final TypeSchema ts); }
@Test public void fromBufferObject() { final byte[] buffer = "[{\"value\":\"hello\"},{\"value\":\"world\"}]".getBytes(StandardCharsets.UTF_8); final TypeRegistry tr = TypeRegistry.getRegistry(); tr.addDataType(MyType.class); MetadataBuilder.addComponent(tr.getDataType("MyType")); final JSONTransactionSerializer serializer = new JSONTransactionSerializer(); final TypeSchema ts = TypeSchema.typeConvert(MyType[].class); final MyType[] o = (MyType[]) serializer.fromBuffer(buffer, ts); assertThat(o[0].toString(), equalTo("++++ MyType: hello")); assertThat(o[1].toString(), equalTo("++++ MyType: world")); }
@Override public Object fromBuffer(final byte[] buffer, final TypeSchema ts) { try { final String stringData = new String(buffer, StandardCharsets.UTF_8); Object value = null; value = convert(stringData, ts); return value; } catch (InstantiationException | IllegalAccessException e) { final ContractRuntimeException cre = new ContractRuntimeException(e); throw cre; } }
JSONTransactionSerializer implements SerializerInterface { @Override public Object fromBuffer(final byte[] buffer, final TypeSchema ts) { try { final String stringData = new String(buffer, StandardCharsets.UTF_8); Object value = null; value = convert(stringData, ts); return value; } catch (InstantiationException | IllegalAccessException e) { final ContractRuntimeException cre = new ContractRuntimeException(e); throw cre; } } }
JSONTransactionSerializer implements SerializerInterface { @Override public Object fromBuffer(final byte[] buffer, final TypeSchema ts) { try { final String stringData = new String(buffer, StandardCharsets.UTF_8); Object value = null; value = convert(stringData, ts); return value; } catch (InstantiationException | IllegalAccessException e) { final ContractRuntimeException cre = new ContractRuntimeException(e); throw cre; } } JSONTransactionSerializer(); }
JSONTransactionSerializer implements SerializerInterface { @Override public Object fromBuffer(final byte[] buffer, final TypeSchema ts) { try { final String stringData = new String(buffer, StandardCharsets.UTF_8); Object value = null; value = convert(stringData, ts); return value; } catch (InstantiationException | IllegalAccessException e) { final ContractRuntimeException cre = new ContractRuntimeException(e); throw cre; } } JSONTransactionSerializer(); @Override byte[] toBuffer(final Object value, final TypeSchema ts); @Override Object fromBuffer(final byte[] buffer, final TypeSchema ts); }
JSONTransactionSerializer implements SerializerInterface { @Override public Object fromBuffer(final byte[] buffer, final TypeSchema ts) { try { final String stringData = new String(buffer, StandardCharsets.UTF_8); Object value = null; value = convert(stringData, ts); return value; } catch (InstantiationException | IllegalAccessException e) { final ContractRuntimeException cre = new ContractRuntimeException(e); throw cre; } } JSONTransactionSerializer(); @Override byte[] toBuffer(final Object value, final TypeSchema ts); @Override Object fromBuffer(final byte[] buffer, final TypeSchema ts); }
@Test public void fromBufferErrors() { final TypeRegistry tr = new TypeRegistryImpl(); tr.addDataType(MyType.class); MetadataBuilder.addComponent(tr.getDataType("MyType")); final JSONTransactionSerializer serializer = new JSONTransactionSerializer(); final TypeSchema ts = TypeSchema.typeConvert(MyType[].class); serializer.toBuffer(null, ts); }
@Override public byte[] toBuffer(final Object value, final TypeSchema ts) { logger.debug(() -> "Schema to convert is " + ts); byte[] buffer = null; if (value != null) { final String type = ts.getType(); if (type != null) { switch (type) { case "array": final JSONArray array = normalizeArray(new JSONArray(value), ts); buffer = array.toString().getBytes(UTF_8); break; case "string": final String format = ts.getFormat(); if (format != null && format.contentEquals("uint16")) { buffer = Character.valueOf((char) value).toString().getBytes(UTF_8); } else { buffer = ((String) value).getBytes(UTF_8); } break; case "number": case "integer": case "boolean": default: buffer = (value).toString().getBytes(UTF_8); } } else { final DataTypeDefinition dtd = this.typeRegistry.getDataType(ts); final Set<String> keySet = dtd.getProperties().keySet(); final String[] propNames = keySet.toArray(new String[keySet.size()]); final JSONObject obj = new JSONObject(new JSONObject(value), propNames); buffer = obj.toString().getBytes(UTF_8); } } return buffer; }
JSONTransactionSerializer implements SerializerInterface { @Override public byte[] toBuffer(final Object value, final TypeSchema ts) { logger.debug(() -> "Schema to convert is " + ts); byte[] buffer = null; if (value != null) { final String type = ts.getType(); if (type != null) { switch (type) { case "array": final JSONArray array = normalizeArray(new JSONArray(value), ts); buffer = array.toString().getBytes(UTF_8); break; case "string": final String format = ts.getFormat(); if (format != null && format.contentEquals("uint16")) { buffer = Character.valueOf((char) value).toString().getBytes(UTF_8); } else { buffer = ((String) value).getBytes(UTF_8); } break; case "number": case "integer": case "boolean": default: buffer = (value).toString().getBytes(UTF_8); } } else { final DataTypeDefinition dtd = this.typeRegistry.getDataType(ts); final Set<String> keySet = dtd.getProperties().keySet(); final String[] propNames = keySet.toArray(new String[keySet.size()]); final JSONObject obj = new JSONObject(new JSONObject(value), propNames); buffer = obj.toString().getBytes(UTF_8); } } return buffer; } }
JSONTransactionSerializer implements SerializerInterface { @Override public byte[] toBuffer(final Object value, final TypeSchema ts) { logger.debug(() -> "Schema to convert is " + ts); byte[] buffer = null; if (value != null) { final String type = ts.getType(); if (type != null) { switch (type) { case "array": final JSONArray array = normalizeArray(new JSONArray(value), ts); buffer = array.toString().getBytes(UTF_8); break; case "string": final String format = ts.getFormat(); if (format != null && format.contentEquals("uint16")) { buffer = Character.valueOf((char) value).toString().getBytes(UTF_8); } else { buffer = ((String) value).getBytes(UTF_8); } break; case "number": case "integer": case "boolean": default: buffer = (value).toString().getBytes(UTF_8); } } else { final DataTypeDefinition dtd = this.typeRegistry.getDataType(ts); final Set<String> keySet = dtd.getProperties().keySet(); final String[] propNames = keySet.toArray(new String[keySet.size()]); final JSONObject obj = new JSONObject(new JSONObject(value), propNames); buffer = obj.toString().getBytes(UTF_8); } } return buffer; } JSONTransactionSerializer(); }
JSONTransactionSerializer implements SerializerInterface { @Override public byte[] toBuffer(final Object value, final TypeSchema ts) { logger.debug(() -> "Schema to convert is " + ts); byte[] buffer = null; if (value != null) { final String type = ts.getType(); if (type != null) { switch (type) { case "array": final JSONArray array = normalizeArray(new JSONArray(value), ts); buffer = array.toString().getBytes(UTF_8); break; case "string": final String format = ts.getFormat(); if (format != null && format.contentEquals("uint16")) { buffer = Character.valueOf((char) value).toString().getBytes(UTF_8); } else { buffer = ((String) value).getBytes(UTF_8); } break; case "number": case "integer": case "boolean": default: buffer = (value).toString().getBytes(UTF_8); } } else { final DataTypeDefinition dtd = this.typeRegistry.getDataType(ts); final Set<String> keySet = dtd.getProperties().keySet(); final String[] propNames = keySet.toArray(new String[keySet.size()]); final JSONObject obj = new JSONObject(new JSONObject(value), propNames); buffer = obj.toString().getBytes(UTF_8); } } return buffer; } JSONTransactionSerializer(); @Override byte[] toBuffer(final Object value, final TypeSchema ts); @Override Object fromBuffer(final byte[] buffer, final TypeSchema ts); }
JSONTransactionSerializer implements SerializerInterface { @Override public byte[] toBuffer(final Object value, final TypeSchema ts) { logger.debug(() -> "Schema to convert is " + ts); byte[] buffer = null; if (value != null) { final String type = ts.getType(); if (type != null) { switch (type) { case "array": final JSONArray array = normalizeArray(new JSONArray(value), ts); buffer = array.toString().getBytes(UTF_8); break; case "string": final String format = ts.getFormat(); if (format != null && format.contentEquals("uint16")) { buffer = Character.valueOf((char) value).toString().getBytes(UTF_8); } else { buffer = ((String) value).getBytes(UTF_8); } break; case "number": case "integer": case "boolean": default: buffer = (value).toString().getBytes(UTF_8); } } else { final DataTypeDefinition dtd = this.typeRegistry.getDataType(ts); final Set<String> keySet = dtd.getProperties().keySet(); final String[] propNames = keySet.toArray(new String[keySet.size()]); final JSONObject obj = new JSONObject(new JSONObject(value), propNames); buffer = obj.toString().getBytes(UTF_8); } } return buffer; } JSONTransactionSerializer(); @Override byte[] toBuffer(final Object value, final TypeSchema ts); @Override Object fromBuffer(final byte[] buffer, final TypeSchema ts); }
@Test public void testGetObjectType() { final CompositeKey key = new CompositeKey("abc", Arrays.asList("def", "ghi", "jkl", "mno")); assertThat(key.getObjectType(), is(equalTo("abc"))); }
public String getObjectType() { return objectType; }
CompositeKey { public String getObjectType() { return objectType; } }
CompositeKey { public String getObjectType() { return objectType; } CompositeKey(final String objectType, final String... attributes); CompositeKey(final String objectType, final List<String> attributes); }
CompositeKey { public String getObjectType() { return objectType; } CompositeKey(final String objectType, final String... attributes); CompositeKey(final String objectType, final List<String> attributes); String getObjectType(); List<String> getAttributes(); @Override String toString(); static CompositeKey parseCompositeKey(final String compositeKey); static void validateSimpleKeys(final String... keys); }
CompositeKey { public String getObjectType() { return objectType; } CompositeKey(final String objectType, final String... attributes); CompositeKey(final String objectType, final List<String> attributes); String getObjectType(); List<String> getAttributes(); @Override String toString(); static CompositeKey parseCompositeKey(final String compositeKey); static void validateSimpleKeys(final String... keys); static final String NAMESPACE; }
@Test public void testMapLevel() { assertEquals("Error maps", Level.SEVERE, proxyMapLevel("ERROR")); assertEquals("Critical maps", Level.SEVERE, proxyMapLevel("critical")); assertEquals("Warn maps", Level.WARNING, proxyMapLevel("WARNING")); assertEquals("Info maps", Level.INFO, proxyMapLevel("INFO")); assertEquals("Config maps", Level.CONFIG, proxyMapLevel(" notice")); assertEquals("Info maps", Level.INFO, proxyMapLevel(" info")); assertEquals("Debug maps", Level.FINEST, proxyMapLevel("debug ")); assertEquals("Info maps", Level.INFO, proxyMapLevel("wibble ")); assertEquals("Info maps", Level.INFO, proxyMapLevel(new Object[] {null})); }
private static Level mapLevel(final String level) { if (level != null) { switch (level.toUpperCase().trim()) { case "ERROR": case "CRITICAL": return Level.SEVERE; case "WARNING": return Level.WARNING; case "INFO": return Level.INFO; case "NOTICE": return Level.CONFIG; case "DEBUG": return Level.FINEST; default: return Level.INFO; } } return Level.INFO; }
Logging { private static Level mapLevel(final String level) { if (level != null) { switch (level.toUpperCase().trim()) { case "ERROR": case "CRITICAL": return Level.SEVERE; case "WARNING": return Level.WARNING; case "INFO": return Level.INFO; case "NOTICE": return Level.CONFIG; case "DEBUG": return Level.FINEST; default: return Level.INFO; } } return Level.INFO; } }
Logging { private static Level mapLevel(final String level) { if (level != null) { switch (level.toUpperCase().trim()) { case "ERROR": case "CRITICAL": return Level.SEVERE; case "WARNING": return Level.WARNING; case "INFO": return Level.INFO; case "NOTICE": return Level.CONFIG; case "DEBUG": return Level.FINEST; default: return Level.INFO; } } return Level.INFO; } private Logging(); }
Logging { private static Level mapLevel(final String level) { if (level != null) { switch (level.toUpperCase().trim()) { case "ERROR": case "CRITICAL": return Level.SEVERE; case "WARNING": return Level.WARNING; case "INFO": return Level.INFO; case "NOTICE": return Level.CONFIG; case "DEBUG": return Level.FINEST; default: return Level.INFO; } } return Level.INFO; } private Logging(); static String formatError(final Throwable throwable); static void setLogLevel(final String newLevel); }
Logging { private static Level mapLevel(final String level) { if (level != null) { switch (level.toUpperCase().trim()) { case "ERROR": case "CRITICAL": return Level.SEVERE; case "WARNING": return Level.WARNING; case "INFO": return Level.INFO; case "NOTICE": return Level.CONFIG; case "DEBUG": return Level.FINEST; default: return Level.INFO; } } return Level.INFO; } private Logging(); static String formatError(final Throwable throwable); static void setLogLevel(final String newLevel); static final String PERFLOGGER; }
@Test public void testFormatError() { final Exception e1 = new Exception("Computer says no"); assertThat(Logging.formatError(e1), containsString("Computer says no")); final NullPointerException npe1 = new NullPointerException("Nothing here"); npe1.initCause(e1); assertThat(Logging.formatError(npe1), containsString("Computer says no")); assertThat(Logging.formatError(npe1), containsString("Nothing here")); assertThat(Logging.formatError(null), CoreMatchers.nullValue()); }
public static String formatError(final Throwable throwable) { if (throwable == null) { return null; } final StringWriter buffer = new StringWriter(); buffer.append(throwable.getMessage()).append(System.lineSeparator()); throwable.printStackTrace(new PrintWriter(buffer)); final Throwable cause = throwable.getCause(); if (cause != null) { buffer.append(".. caused by ..").append(System.lineSeparator()); buffer.append(Logging.formatError(cause)); } return buffer.toString(); }
Logging { public static String formatError(final Throwable throwable) { if (throwable == null) { return null; } final StringWriter buffer = new StringWriter(); buffer.append(throwable.getMessage()).append(System.lineSeparator()); throwable.printStackTrace(new PrintWriter(buffer)); final Throwable cause = throwable.getCause(); if (cause != null) { buffer.append(".. caused by ..").append(System.lineSeparator()); buffer.append(Logging.formatError(cause)); } return buffer.toString(); } }
Logging { public static String formatError(final Throwable throwable) { if (throwable == null) { return null; } final StringWriter buffer = new StringWriter(); buffer.append(throwable.getMessage()).append(System.lineSeparator()); throwable.printStackTrace(new PrintWriter(buffer)); final Throwable cause = throwable.getCause(); if (cause != null) { buffer.append(".. caused by ..").append(System.lineSeparator()); buffer.append(Logging.formatError(cause)); } return buffer.toString(); } private Logging(); }
Logging { public static String formatError(final Throwable throwable) { if (throwable == null) { return null; } final StringWriter buffer = new StringWriter(); buffer.append(throwable.getMessage()).append(System.lineSeparator()); throwable.printStackTrace(new PrintWriter(buffer)); final Throwable cause = throwable.getCause(); if (cause != null) { buffer.append(".. caused by ..").append(System.lineSeparator()); buffer.append(Logging.formatError(cause)); } return buffer.toString(); } private Logging(); static String formatError(final Throwable throwable); static void setLogLevel(final String newLevel); }
Logging { public static String formatError(final Throwable throwable) { if (throwable == null) { return null; } final StringWriter buffer = new StringWriter(); buffer.append(throwable.getMessage()).append(System.lineSeparator()); throwable.printStackTrace(new PrintWriter(buffer)); final Throwable cause = throwable.getCause(); if (cause != null) { buffer.append(".. caused by ..").append(System.lineSeparator()); buffer.append(Logging.formatError(cause)); } return buffer.toString(); } private Logging(); static String formatError(final Throwable throwable); static void setLogLevel(final String newLevel); static final String PERFLOGGER; }
@Test public void testSetLogLevel() { final java.util.logging.Logger l = java.util.logging.Logger.getLogger("org.hyperledger.fabric.test"); final java.util.logging.Logger another = java.util.logging.Logger.getLogger("acme.wibble"); final Level anotherLevel = another.getLevel(); Logging.setLogLevel("debug"); assertThat(l.getLevel(), CoreMatchers.equalTo(Level.FINEST)); assertThat(another.getLevel(), CoreMatchers.equalTo(anotherLevel)); Logging.setLogLevel("dsomethoig"); assertThat(l.getLevel(), CoreMatchers.equalTo(Level.INFO)); assertThat(another.getLevel(), CoreMatchers.equalTo(anotherLevel)); Logging.setLogLevel("ERROR"); assertThat(l.getLevel(), CoreMatchers.equalTo(Level.SEVERE)); assertThat(another.getLevel(), CoreMatchers.equalTo(anotherLevel)); Logging.setLogLevel("INFO"); }
public static void setLogLevel(final String newLevel) { final Level l = mapLevel(newLevel); final LogManager logManager = LogManager.getLogManager(); final ArrayList<String> allLoggers = Collections.list(logManager.getLoggerNames()); allLoggers.add("org.hyperledger"); allLoggers.stream().filter(name -> name.startsWith("org.hyperledger")).map(name -> logManager.getLogger(name)).forEach(logger -> { if (logger != null) { logger.setLevel(l); } }); }
Logging { public static void setLogLevel(final String newLevel) { final Level l = mapLevel(newLevel); final LogManager logManager = LogManager.getLogManager(); final ArrayList<String> allLoggers = Collections.list(logManager.getLoggerNames()); allLoggers.add("org.hyperledger"); allLoggers.stream().filter(name -> name.startsWith("org.hyperledger")).map(name -> logManager.getLogger(name)).forEach(logger -> { if (logger != null) { logger.setLevel(l); } }); } }
Logging { public static void setLogLevel(final String newLevel) { final Level l = mapLevel(newLevel); final LogManager logManager = LogManager.getLogManager(); final ArrayList<String> allLoggers = Collections.list(logManager.getLoggerNames()); allLoggers.add("org.hyperledger"); allLoggers.stream().filter(name -> name.startsWith("org.hyperledger")).map(name -> logManager.getLogger(name)).forEach(logger -> { if (logger != null) { logger.setLevel(l); } }); } private Logging(); }
Logging { public static void setLogLevel(final String newLevel) { final Level l = mapLevel(newLevel); final LogManager logManager = LogManager.getLogManager(); final ArrayList<String> allLoggers = Collections.list(logManager.getLoggerNames()); allLoggers.add("org.hyperledger"); allLoggers.stream().filter(name -> name.startsWith("org.hyperledger")).map(name -> logManager.getLogger(name)).forEach(logger -> { if (logger != null) { logger.setLevel(l); } }); } private Logging(); static String formatError(final Throwable throwable); static void setLogLevel(final String newLevel); }
Logging { public static void setLogLevel(final String newLevel) { final Level l = mapLevel(newLevel); final LogManager logManager = LogManager.getLogManager(); final ArrayList<String> allLoggers = Collections.list(logManager.getLoggerNames()); allLoggers.add("org.hyperledger"); allLoggers.stream().filter(name -> name.startsWith("org.hyperledger")).map(name -> logManager.getLogger(name)).forEach(logger -> { if (logger != null) { logger.setLevel(l); } }); } private Logging(); static String formatError(final Throwable throwable); static void setLogLevel(final String newLevel); static final String PERFLOGGER; }
@Test public void testGetAttributes() { final CompositeKey key = new CompositeKey("abc", Arrays.asList("def", "ghi", "jkl", "mno")); assertThat(key.getObjectType(), is(equalTo("abc"))); assertThat(key.getAttributes(), hasSize(4)); assertThat(key.getAttributes(), contains("def", "ghi", "jkl", "mno")); }
public List<String> getAttributes() { return attributes; }
CompositeKey { public List<String> getAttributes() { return attributes; } }
CompositeKey { public List<String> getAttributes() { return attributes; } CompositeKey(final String objectType, final String... attributes); CompositeKey(final String objectType, final List<String> attributes); }
CompositeKey { public List<String> getAttributes() { return attributes; } CompositeKey(final String objectType, final String... attributes); CompositeKey(final String objectType, final List<String> attributes); String getObjectType(); List<String> getAttributes(); @Override String toString(); static CompositeKey parseCompositeKey(final String compositeKey); static void validateSimpleKeys(final String... keys); }
CompositeKey { public List<String> getAttributes() { return attributes; } CompositeKey(final String objectType, final String... attributes); CompositeKey(final String objectType, final List<String> attributes); String getObjectType(); List<String> getAttributes(); @Override String toString(); static CompositeKey parseCompositeKey(final String compositeKey); static void validateSimpleKeys(final String... keys); static final String NAMESPACE; }
@Test public void testToString() { final CompositeKey key = new CompositeKey("abc", Arrays.asList("def", "ghi", "jkl", "mno")); assertThat(key.toString(), is(equalTo("\u0000abc\u0000def\u0000ghi\u0000jkl\u0000mno\u0000"))); }
@Override public String toString() { return compositeKey; }
CompositeKey { @Override public String toString() { return compositeKey; } }
CompositeKey { @Override public String toString() { return compositeKey; } CompositeKey(final String objectType, final String... attributes); CompositeKey(final String objectType, final List<String> attributes); }
CompositeKey { @Override public String toString() { return compositeKey; } CompositeKey(final String objectType, final String... attributes); CompositeKey(final String objectType, final List<String> attributes); String getObjectType(); List<String> getAttributes(); @Override String toString(); static CompositeKey parseCompositeKey(final String compositeKey); static void validateSimpleKeys(final String... keys); }
CompositeKey { @Override public String toString() { return compositeKey; } CompositeKey(final String objectType, final String... attributes); CompositeKey(final String objectType, final List<String> attributes); String getObjectType(); List<String> getAttributes(); @Override String toString(); static CompositeKey parseCompositeKey(final String compositeKey); static void validateSimpleKeys(final String... keys); static final String NAMESPACE; }
@Test public void run() { final LocalDate now = LocalDate.now(); when(dateTimeProvider.getCurrentDate()).thenReturn(now); subject.run(); verify(accessControlListDao, times(1)).removePermanentBlocksBefore(argThat(new BaseMatcher<LocalDate>() { @Override public boolean matches(Object item) { return item.equals(now.minusYears(1)); } @Override public void describeTo(Description description) { description.appendText("Should only delete bans older than 1 year"); } })); verify(accessControlListDao, times(1)).removeBlockEventsBefore(argThat(new BaseMatcher<LocalDate>() { @Override public boolean matches(Object item) { return item.equals(now.minusMonths(3)); } @Override public void describeTo(Description description) { description.appendText("Should only delete events older than 3 months"); } })); }
@Override @Scheduled(cron = "0 0 0 * * *") @SchedulerLock(name = "AutomaticPermanentBlocksCleanup") public void run() { final LocalDate eventRemoveDate = dateTimeProvider.getCurrentDate().minusMonths(3); LOGGER.debug("Removing block events before {}", eventRemoveDate); accessControlListDao.removeBlockEventsBefore(eventRemoveDate); final LocalDate blockRemoveDate = dateTimeProvider.getCurrentDate().minusYears(1); LOGGER.debug("Removing permanent bans before {}", blockRemoveDate); accessControlListDao.removePermanentBlocksBefore(blockRemoveDate); }
AutomaticPermanentBlocksCleanup implements DailyScheduledTask { @Override @Scheduled(cron = "0 0 0 * * *") @SchedulerLock(name = "AutomaticPermanentBlocksCleanup") public void run() { final LocalDate eventRemoveDate = dateTimeProvider.getCurrentDate().minusMonths(3); LOGGER.debug("Removing block events before {}", eventRemoveDate); accessControlListDao.removeBlockEventsBefore(eventRemoveDate); final LocalDate blockRemoveDate = dateTimeProvider.getCurrentDate().minusYears(1); LOGGER.debug("Removing permanent bans before {}", blockRemoveDate); accessControlListDao.removePermanentBlocksBefore(blockRemoveDate); } }
AutomaticPermanentBlocksCleanup implements DailyScheduledTask { @Override @Scheduled(cron = "0 0 0 * * *") @SchedulerLock(name = "AutomaticPermanentBlocksCleanup") public void run() { final LocalDate eventRemoveDate = dateTimeProvider.getCurrentDate().minusMonths(3); LOGGER.debug("Removing block events before {}", eventRemoveDate); accessControlListDao.removeBlockEventsBefore(eventRemoveDate); final LocalDate blockRemoveDate = dateTimeProvider.getCurrentDate().minusYears(1); LOGGER.debug("Removing permanent bans before {}", blockRemoveDate); accessControlListDao.removePermanentBlocksBefore(blockRemoveDate); } @Autowired AutomaticPermanentBlocksCleanup(final DateTimeProvider dateTimeProvider, final AccessControlListDao accessControlListDao); }
AutomaticPermanentBlocksCleanup implements DailyScheduledTask { @Override @Scheduled(cron = "0 0 0 * * *") @SchedulerLock(name = "AutomaticPermanentBlocksCleanup") public void run() { final LocalDate eventRemoveDate = dateTimeProvider.getCurrentDate().minusMonths(3); LOGGER.debug("Removing block events before {}", eventRemoveDate); accessControlListDao.removeBlockEventsBefore(eventRemoveDate); final LocalDate blockRemoveDate = dateTimeProvider.getCurrentDate().minusYears(1); LOGGER.debug("Removing permanent bans before {}", blockRemoveDate); accessControlListDao.removePermanentBlocksBefore(blockRemoveDate); } @Autowired AutomaticPermanentBlocksCleanup(final DateTimeProvider dateTimeProvider, final AccessControlListDao accessControlListDao); @Override @Scheduled(cron = "0 0 0 * * *") @SchedulerLock(name = "AutomaticPermanentBlocksCleanup") void run(); }
AutomaticPermanentBlocksCleanup implements DailyScheduledTask { @Override @Scheduled(cron = "0 0 0 * * *") @SchedulerLock(name = "AutomaticPermanentBlocksCleanup") public void run() { final LocalDate eventRemoveDate = dateTimeProvider.getCurrentDate().minusMonths(3); LOGGER.debug("Removing block events before {}", eventRemoveDate); accessControlListDao.removeBlockEventsBefore(eventRemoveDate); final LocalDate blockRemoveDate = dateTimeProvider.getCurrentDate().minusYears(1); LOGGER.debug("Removing permanent bans before {}", blockRemoveDate); accessControlListDao.removePermanentBlocksBefore(blockRemoveDate); } @Autowired AutomaticPermanentBlocksCleanup(final DateTimeProvider dateTimeProvider, final AccessControlListDao accessControlListDao); @Override @Scheduled(cron = "0 0 0 * * *") @SchedulerLock(name = "AutomaticPermanentBlocksCleanup") void run(); }
@Test public void translate_to_uuid_username_not_stored_in_context() { final RpslObject object = RpslObject.parse("mntner: TEST-MNT\nauth: SSO [email protected]"); when(updateContext.getSsoTranslationResult("[email protected]")).thenReturn("BBBB-1234-CCCC-DDDD"); final RpslObject result = subject.translateFromCacheAuthToUuid(updateContext, object); assertThat(result, is(RpslObject.parse("mntner: TEST-MNT\nauth: SSO BBBB-1234-CCCC-DDDD"))); verify(updateContext).getSsoTranslationResult("[email protected]"); }
public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); }
SsoTranslator { public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } }
SsoTranslator { public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } @Autowired SsoTranslator(final CrowdClient crowdClient); }
SsoTranslator { public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
SsoTranslator { public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
@Test public void translate_to_username_uuid_stored_in_context_already() { final RpslObject object = RpslObject.parse("mntner: TEST-MNT\nauth: SSO aadd-2132-aaa-fff"); when(updateContext.getSsoTranslationResult("aadd-2132-aaa-fff")).thenReturn("[email protected]"); final RpslObject result = subject.translateFromCacheAuthToUuid(updateContext, object); assertThat(result, is(RpslObject.parse("mntner: TEST-MNT\nauth: SSO [email protected]"))); }
public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); }
SsoTranslator { public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } }
SsoTranslator { public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } @Autowired SsoTranslator(final CrowdClient crowdClient); }
SsoTranslator { public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
SsoTranslator { public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
@Test public void populate_not_maintainer_object() { final RpslObject object = RpslObject.parse("aut-num: AS1234"); when(update.getSubmittedObject()).thenReturn(object); subject.populateCacheAuthToUuid(updateContext, update); verifyZeroInteractions(updateContext); }
public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); }
SsoTranslator { public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); } }
SsoTranslator { public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); } @Autowired SsoTranslator(final CrowdClient crowdClient); }
SsoTranslator { public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
SsoTranslator { public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
@Test public void populate_no_sso_auth() { final RpslObject object = RpslObject.parse("mntner: TEST-MNT\nauth: MD5-PW aaff1232431"); when(update.getSubmittedObject()).thenReturn(object); subject.populateCacheAuthToUuid(updateContext, update); verifyZeroInteractions(updateContext); }
public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); }
SsoTranslator { public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); } }
SsoTranslator { public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); } @Autowired SsoTranslator(final CrowdClient crowdClient); }
SsoTranslator { public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
SsoTranslator { public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
@Test public void populate_sso_auth() { final RpslObject object = RpslObject.parse("mntner: TEST-MNT\nauth: SSO [email protected]"); when(update.getSubmittedObject()).thenReturn(object); when(updateContext.hasSsoTranslationResult("[email protected]")).thenReturn(true); subject.populateCacheAuthToUuid(updateContext, update); verify(updateContext, times(0)).addSsoTranslationResult(eq("[email protected]"), anyString()); }
public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); }
SsoTranslator { public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); } }
SsoTranslator { public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); } @Autowired SsoTranslator(final CrowdClient crowdClient); }
SsoTranslator { public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
SsoTranslator { public void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update) { final RpslObject submittedObject = update.getSubmittedObject(); SsoHelper.translateAuth(submittedObject, new AuthTranslator() { @Override @CheckForNull public RpslAttribute translate(final String authType, final String authToken, final RpslAttribute originalAttribute) { if (authType.equals("SSO")) { if (!updateContext.hasSsoTranslationResult(authToken)) { try { final String uuid = crowdClient.getUuid(authToken); updateContext.addSsoTranslationResult(authToken, uuid); } catch (CrowdClientException e) { updateContext.addMessage(update, originalAttribute, UpdateMessages.ripeAccessAccountUnavailable(authToken)); } } } return null; } }); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
@Test public void filter_mnt_routes_from_autnum() { final RpslObject autnum = RpslObject.parse( "aut-num: AS3333\n" + "as-name: TEST-AS\n" + "org: ORG-TEST1-TEST\n" + " # Transit:\n" + "import: from AS3333 action pref=700; accept ANY # preserve \n" + "export: to AS3333 announce AS3333:AS-TEST # formatting \n" + "admin-c: AA1-TEST\n" + "tech-c: AA1-TEST\n" + "status: ASSIGNED\n" + "mnt-by: RIPE-NCC-END-MNT\n" + "mnt-by: OWNER-MNT\n" + "mnt-routes: ANOTHER-MNT\n" + "created: 1970-01-01T00:00:00Z\n" + "last-modified: 2018-7-25T09:01:00Z\n" + "source: TEST"); final RpslObject updatedAutnum = subject.transform(autnum, update, updateContext, Action.MODIFY); assertThat(updatedAutnum.containsAttribute(AttributeType.MNT_ROUTES), is(false)); assertThat(diff(autnum, updatedAutnum), is( "@@ -11,3 +11,2 @@\n" + " mnt-by: OWNER-MNT\n" + "-mnt-routes: ANOTHER-MNT\n" + " created: 1970-01-01T00:00:00Z\n")); verifyMessageAdded(); }
public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); }
MntRoutesAttributeTransformer implements Transformer { public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); } }
MntRoutesAttributeTransformer implements Transformer { public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); } }
MntRoutesAttributeTransformer implements Transformer { public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); } RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action); }
MntRoutesAttributeTransformer implements Transformer { public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); } RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action); }
@Test public void no_mnt_routes_in_autnum() { final RpslObject autnum = RpslObject.parse( "aut-num: AS3333\n" + "as-name: TEST-AS\n" + "org: ORG-TEST1-TEST\n" + " # Transit:\n" + "import: from AS3333 action pref=700; accept ANY\n" + "export: to AS3333 announce AS3333:AS-TEST\n" + "admin-c: AA1-TEST\n" + "tech-c: AA1-TEST\n" + "status: ASSIGNED\n" + "mnt-by: RIPE-NCC-END-MNT\n" + "mnt-by: OWNER-MNT\n" + "created: 1970-01-01T00:00:00Z\n" + "last-modified: 2018-7-25T09:01:00Z\n" + "source: TEST"); final RpslObject updatedAutnum = subject.transform(autnum, update, updateContext, Action.MODIFY); assertThat(updatedAutnum.containsAttribute(AttributeType.MNT_ROUTES), is(false)); assertThat(diff(autnum, updatedAutnum), isEmptyString()); verifyMessageNotAdded(); }
public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); }
MntRoutesAttributeTransformer implements Transformer { public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); } }
MntRoutesAttributeTransformer implements Transformer { public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); } }
MntRoutesAttributeTransformer implements Transformer { public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); } RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action); }
MntRoutesAttributeTransformer implements Transformer { public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); } RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action); }
@Test public void dont_filter_mnt_routes_from_inetnum() { final RpslObject inetnum = RpslObject.parse( "inetnum: 192.0.0.0 - 192.255.255.255\n" + "netname: TEST-NET-NAME\n" + "descr: TEST network\n" + "country: NL\n" + "org: ORG-LIR1-TEST\n" + "admin-c: TP1-TEST\n" + "tech-c: TP1-TEST\n" + "status: ALLOCATED UNSPECIFIED\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-lower: LIR-MNT\n" + "mnt-routes: LIR-MNT\n" + "source: TEST\n"); final RpslObject updatedInetnum = subject.transform(inetnum, update, updateContext, Action.MODIFY); assertThat(updatedInetnum.containsAttribute(AttributeType.MNT_ROUTES), is(true)); assertThat(diff(inetnum, updatedInetnum), isEmptyString()); verifyMessageNotAdded(); }
public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); }
MntRoutesAttributeTransformer implements Transformer { public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); } }
MntRoutesAttributeTransformer implements Transformer { public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); } }
MntRoutesAttributeTransformer implements Transformer { public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); } RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action); }
MntRoutesAttributeTransformer implements Transformer { public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { if ((rpslObject.getType() != ObjectType.AUT_NUM) || !rpslObject.containsAttribute(AttributeType.MNT_ROUTES)) { return rpslObject; } updateContext.addMessage(update, UpdateMessages.mntRoutesAttributeRemoved()); return new RpslObjectBuilder(rpslObject).removeAttributeType(AttributeType.MNT_ROUTES).get(); } RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action); }
@Test public void dont_transform_no_short_format_attributes() { final RpslObject mntner = RpslObject.parse( "mntner: MINE-MNT\n" + "admin-c: AA1-TEST\n" + "auth: MD5-PW $1$/7f2XnzQ$p5ddbI7SXq4z4yNrObFS/0 # emptypassword\n" + "mnt-by: MINE-MNT\n" + "source: TEST\n"); final RpslObject updatedObject = subject.transform(mntner, update, updateContext, Action.MODIFY); assertThat(updatedObject, is(mntner)); verifyNoMoreInteractions(update); verifyNoMoreInteractions(updateContext); }
@Override public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { final RpslObjectBuilder builder = new RpslObjectBuilder(rpslObject); boolean updated = false; final ListIterator<RpslAttribute> iterator = builder.getAttributes().listIterator(); while (iterator.hasNext()) { final RpslAttribute rpslAttribute = iterator.next(); if (rpslAttribute.getType() != null && !rpslAttribute.getType().getName().equals(rpslAttribute.getKey())) { iterator.set(new RpslAttribute(rpslAttribute.getType(), rpslAttribute.getValue())); updated = true; } } if (updated) { updateContext.addMessage(update, UpdateMessages.shortFormatAttributeReplaced()); return builder.get(); } return rpslObject; }
ShortFormatTransformer implements Transformer { @Override public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { final RpslObjectBuilder builder = new RpslObjectBuilder(rpslObject); boolean updated = false; final ListIterator<RpslAttribute> iterator = builder.getAttributes().listIterator(); while (iterator.hasNext()) { final RpslAttribute rpslAttribute = iterator.next(); if (rpslAttribute.getType() != null && !rpslAttribute.getType().getName().equals(rpslAttribute.getKey())) { iterator.set(new RpslAttribute(rpslAttribute.getType(), rpslAttribute.getValue())); updated = true; } } if (updated) { updateContext.addMessage(update, UpdateMessages.shortFormatAttributeReplaced()); return builder.get(); } return rpslObject; } }
ShortFormatTransformer implements Transformer { @Override public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { final RpslObjectBuilder builder = new RpslObjectBuilder(rpslObject); boolean updated = false; final ListIterator<RpslAttribute> iterator = builder.getAttributes().listIterator(); while (iterator.hasNext()) { final RpslAttribute rpslAttribute = iterator.next(); if (rpslAttribute.getType() != null && !rpslAttribute.getType().getName().equals(rpslAttribute.getKey())) { iterator.set(new RpslAttribute(rpslAttribute.getType(), rpslAttribute.getValue())); updated = true; } } if (updated) { updateContext.addMessage(update, UpdateMessages.shortFormatAttributeReplaced()); return builder.get(); } return rpslObject; } }
ShortFormatTransformer implements Transformer { @Override public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { final RpslObjectBuilder builder = new RpslObjectBuilder(rpslObject); boolean updated = false; final ListIterator<RpslAttribute> iterator = builder.getAttributes().listIterator(); while (iterator.hasNext()) { final RpslAttribute rpslAttribute = iterator.next(); if (rpslAttribute.getType() != null && !rpslAttribute.getType().getName().equals(rpslAttribute.getKey())) { iterator.set(new RpslAttribute(rpslAttribute.getType(), rpslAttribute.getValue())); updated = true; } } if (updated) { updateContext.addMessage(update, UpdateMessages.shortFormatAttributeReplaced()); return builder.get(); } return rpslObject; } @Override RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action); }
ShortFormatTransformer implements Transformer { @Override public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { final RpslObjectBuilder builder = new RpslObjectBuilder(rpslObject); boolean updated = false; final ListIterator<RpslAttribute> iterator = builder.getAttributes().listIterator(); while (iterator.hasNext()) { final RpslAttribute rpslAttribute = iterator.next(); if (rpslAttribute.getType() != null && !rpslAttribute.getType().getName().equals(rpslAttribute.getKey())) { iterator.set(new RpslAttribute(rpslAttribute.getType(), rpslAttribute.getValue())); updated = true; } } if (updated) { updateContext.addMessage(update, UpdateMessages.shortFormatAttributeReplaced()); return builder.get(); } return rpslObject; } @Override RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action); }
@Test public void transform_short_format_attributes() { final RpslObject mntner = RpslObject.parse( "mntner: MINE-MNT\n" + "admin-c: AA1-TEST\n" + "auth: MD5-PW $1$/7f2XnzQ$p5ddbI7SXq4z4yNrObFS/0 # emptypassword\n" + "mb: MINE-MNT # mb\n" + "*mb: MINE-MNT # star mb\n" + "mnt-by: MINE-MNT\n" + "source: TEST\n"); final RpslObject updatedObject = subject.transform(mntner, update, updateContext, Action.MODIFY); assertThat(updatedObject.toString(), is( "mntner: MINE-MNT\n" + "admin-c: AA1-TEST\n" + "auth: MD5-PW $1$/7f2XnzQ$p5ddbI7SXq4z4yNrObFS/0 # emptypassword\n" + "mnt-by: MINE-MNT # mb\n" + "mnt-by: MINE-MNT # star mb\n" + "mnt-by: MINE-MNT\n" + "source: TEST\n")); verify(updateContext).addMessage(update, UpdateMessages.shortFormatAttributeReplaced()); verifyNoMoreInteractions(update); verifyNoMoreInteractions(updateContext); }
@Override public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { final RpslObjectBuilder builder = new RpslObjectBuilder(rpslObject); boolean updated = false; final ListIterator<RpslAttribute> iterator = builder.getAttributes().listIterator(); while (iterator.hasNext()) { final RpslAttribute rpslAttribute = iterator.next(); if (rpslAttribute.getType() != null && !rpslAttribute.getType().getName().equals(rpslAttribute.getKey())) { iterator.set(new RpslAttribute(rpslAttribute.getType(), rpslAttribute.getValue())); updated = true; } } if (updated) { updateContext.addMessage(update, UpdateMessages.shortFormatAttributeReplaced()); return builder.get(); } return rpslObject; }
ShortFormatTransformer implements Transformer { @Override public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { final RpslObjectBuilder builder = new RpslObjectBuilder(rpslObject); boolean updated = false; final ListIterator<RpslAttribute> iterator = builder.getAttributes().listIterator(); while (iterator.hasNext()) { final RpslAttribute rpslAttribute = iterator.next(); if (rpslAttribute.getType() != null && !rpslAttribute.getType().getName().equals(rpslAttribute.getKey())) { iterator.set(new RpslAttribute(rpslAttribute.getType(), rpslAttribute.getValue())); updated = true; } } if (updated) { updateContext.addMessage(update, UpdateMessages.shortFormatAttributeReplaced()); return builder.get(); } return rpslObject; } }
ShortFormatTransformer implements Transformer { @Override public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { final RpslObjectBuilder builder = new RpslObjectBuilder(rpslObject); boolean updated = false; final ListIterator<RpslAttribute> iterator = builder.getAttributes().listIterator(); while (iterator.hasNext()) { final RpslAttribute rpslAttribute = iterator.next(); if (rpslAttribute.getType() != null && !rpslAttribute.getType().getName().equals(rpslAttribute.getKey())) { iterator.set(new RpslAttribute(rpslAttribute.getType(), rpslAttribute.getValue())); updated = true; } } if (updated) { updateContext.addMessage(update, UpdateMessages.shortFormatAttributeReplaced()); return builder.get(); } return rpslObject; } }
ShortFormatTransformer implements Transformer { @Override public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { final RpslObjectBuilder builder = new RpslObjectBuilder(rpslObject); boolean updated = false; final ListIterator<RpslAttribute> iterator = builder.getAttributes().listIterator(); while (iterator.hasNext()) { final RpslAttribute rpslAttribute = iterator.next(); if (rpslAttribute.getType() != null && !rpslAttribute.getType().getName().equals(rpslAttribute.getKey())) { iterator.set(new RpslAttribute(rpslAttribute.getType(), rpslAttribute.getValue())); updated = true; } } if (updated) { updateContext.addMessage(update, UpdateMessages.shortFormatAttributeReplaced()); return builder.get(); } return rpslObject; } @Override RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action); }
ShortFormatTransformer implements Transformer { @Override public RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action) { final RpslObjectBuilder builder = new RpslObjectBuilder(rpslObject); boolean updated = false; final ListIterator<RpslAttribute> iterator = builder.getAttributes().listIterator(); while (iterator.hasNext()) { final RpslAttribute rpslAttribute = iterator.next(); if (rpslAttribute.getType() != null && !rpslAttribute.getType().getName().equals(rpslAttribute.getKey())) { iterator.set(new RpslAttribute(rpslAttribute.getType(), rpslAttribute.getValue())); updated = true; } } if (updated) { updateContext.addMessage(update, UpdateMessages.shortFormatAttributeReplaced()); return builder.get(); } return rpslObject; } @Override RpslObject transform(final RpslObject rpslObject, final Update update, final UpdateContext updateContext, final Action action); }
@Test public void transform_inetnum_prefix() { final RpslObject rpslObject = RpslObject.parse("inetnum: 193/8"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.INETNUM).toString(), is("193.0.0.0 - 193.255.255.255")); verify(objectMessages).addMessage(result.getTypeAttribute(), ValidationMessages.attributeValueConverted("193/8", "193.0.0.0 - 193.255.255.255")); verifyNoMoreInteractions(objectMessages); }
public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
@Test public void getException() { final String response = subject.createExceptionResponse(updateContext, origin); assertThat(response, containsString("" + "> From: Andre Kampert <[email protected]>\n" + "> Subject: delete route 194.39.132.0/24\n" + "> Date: Thu, 14 Jun 2012 10:04:42 +0200\n" + "> Reply-To: [email protected]\n" + "> Message-ID: <[email protected]>\n" + "\n" + "Internal software error\n" + "\n" + "\n" + "The RIPE Database is subject to Terms and Conditions:\n" + "http: "\n" + "For assistance or clarification please contact:\n" + "RIPE Database Administration <[email protected]>\n")); assertVersion(response); }
public String createExceptionResponse(final UpdateContext updateContext, final Origin origin) { final VelocityContext velocityContext = new VelocityContext(); return createResponse(TEMPLATE_EXCEPTION, updateContext, velocityContext, origin); }
ResponseFactory { public String createExceptionResponse(final UpdateContext updateContext, final Origin origin) { final VelocityContext velocityContext = new VelocityContext(); return createResponse(TEMPLATE_EXCEPTION, updateContext, velocityContext, origin); } }
ResponseFactory { public String createExceptionResponse(final UpdateContext updateContext, final Origin origin) { final VelocityContext velocityContext = new VelocityContext(); return createResponse(TEMPLATE_EXCEPTION, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); }
ResponseFactory { public String createExceptionResponse(final UpdateContext updateContext, final Origin origin) { final VelocityContext velocityContext = new VelocityContext(); return createResponse(TEMPLATE_EXCEPTION, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
ResponseFactory { public String createExceptionResponse(final UpdateContext updateContext, final Origin origin) { final VelocityContext velocityContext = new VelocityContext(); return createResponse(TEMPLATE_EXCEPTION, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
@Test public void getAck_no_errors() { final RpslObject rpslObject = RpslObject.parse("mntner: DEV-ROOT-MNT"); updateResults.add(new UpdateResult(rpslObject, rpslObject, Action.DELETE, UpdateStatus.SUCCESS, new ObjectMessages(), 0, false)); final Ack ack = new Ack(updateResults, ignoredParagraphs); final String response = subject.createAckResponse(updateContext, origin, ack); assertThat(response, containsString("Number of objects found: 1")); assertThat(response, containsString("Number of objects processed successfully: 1")); assertThat(response, containsString("Delete: 1")); assertThat(response, containsString("Number of objects processed with errors: 0")); assertThat(response, containsString("Delete: 0")); assertThat(response, not(containsString(WARNING))); assertThat(response, not(containsString(ERROR))); assertThat(response, not(containsString(SKIPPED_PARAGRAPH))); assertThat(response, containsString("" + "> From: Andre Kampert <[email protected]>\n" + "> Subject: delete route 194.39.132.0/24\n" + "> Date: Thu, 14 Jun 2012 10:04:42 +0200\n" + "> Reply-To: [email protected]\n" + "> Message-ID: <[email protected]>\n" + "\n" + "SUMMARY OF UPDATE:\n" + "\n" + "Number of objects found: 1\n" + "Number of objects processed successfully: 1\n" + " Create: 0\n" + " Modify: 0\n" + " Delete: 1\n" + " No Operation: 0\n" + "Number of objects processed with errors: 0\n" + " Create: 0\n" + " Modify: 0\n" + " Delete: 0\n" + "\n" + "DETAILED EXPLANATION:\n" + "\n" + "\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + "The following object(s) were processed SUCCESSFULLY:\n" + "\n" + "---\n" + "Delete SUCCEEDED: [mntner] DEV-ROOT-MNT\n" + "\n" + "\n" + "\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + "\n" + "The RIPE Database is subject to Terms and Conditions:\n" + "http: "\n" + "For assistance or clarification please contact:\n" + "RIPE Database Administration <[email protected]>\n\n")); assertVersion(response); }
public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); }
ResponseFactory { public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); } }
ResponseFactory { public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); }
ResponseFactory { public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
ResponseFactory { public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
@Test public void getAck_skipped_paragraphs() { final Paragraph paragraph1 = new Paragraph("paragraph 1"); final Paragraph paragraph2 = new Paragraph("paragraph 2"); ignoredParagraphs.add(paragraph1); ignoredParagraphs.add(paragraph2); final Ack ack = new Ack(updateResults, ignoredParagraphs); final String response = subject.createAckResponse(updateContext, origin, ack); assertThat(response, containsString(SKIPPED_PARAGRAPH)); assertThat(response, containsString(paragraph1.getContent())); assertThat(response, containsString(paragraph2.getContent())); assertThat(response, containsString("" + "> From: Andre Kampert <[email protected]>\n" + "> Subject: delete route 194.39.132.0/24\n" + "> Date: Thu, 14 Jun 2012 10:04:42 +0200\n" + "> Reply-To: [email protected]\n" + "> Message-ID: <[email protected]>\n" + "\n" + "SUMMARY OF UPDATE:\n" + "\n" + "Number of objects found: 0\n" + "Number of objects processed successfully: 0\n" + " Create: 0\n" + " Modify: 0\n" + " Delete: 0\n" + " No Operation: 0\n" + "Number of objects processed with errors: 0\n" + " Create: 0\n" + " Modify: 0\n" + " Delete: 0\n" + "\n" + "DETAILED EXPLANATION:\n" + "\n" + "\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + "The following paragraph(s) do not look like objects\n" + "and were NOT PROCESSED:\n" + "\n" + "paragraph 1\n" + "\n" + "paragraph 2\n" + "\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + "\n" + "The RIPE Database is subject to Terms and Conditions:\n" + "http: "\n" + "For assistance or clarification please contact:\n" + "RIPE Database Administration <[email protected]>\n")); assertVersion(response); }
public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); }
ResponseFactory { public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); } }
ResponseFactory { public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); }
ResponseFactory { public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
ResponseFactory { public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
@Test public void getAck_errors() { final String rpslObjectString = "" + "route: 194.39.132.0/24\n" + "descr: Description\n" + "origin: AS1\n" + "notify: [email protected]\n" + "mnt-by: TEST-MNT\n" + "source: RIPE\n" + "delete: no longer required\n"; final RpslObject rpslObject = RpslObject.parse(rpslObjectString); final ObjectMessages objectMessages = new ObjectMessages(); objectMessages.addMessage(rpslObject.findAttribute(AttributeType.SOURCE), UpdateMessages.unrecognizedSource("RIPE")); updateResults.add(new UpdateResult(rpslObject, rpslObject, Action.DELETE, UpdateStatus.FAILED, objectMessages, 0, false)); final Ack ack = new Ack(updateResults, ignoredParagraphs); final String response = subject.createAckResponse(updateContext, origin, ack); assertThat(response, not(containsString(SKIPPED_PARAGRAPH))); assertThat(response, containsString(ERROR)); assertThat(response, containsString("" + "> From: Andre Kampert <[email protected]>\n" + "> Subject: delete route 194.39.132.0/24\n" + "> Date: Thu, 14 Jun 2012 10:04:42 +0200\n" + "> Reply-To: [email protected]\n" + "> Message-ID: <[email protected]>\n" + "\n" + "SUMMARY OF UPDATE:\n" + "\n" + "Number of objects found: 1\n" + "Number of objects processed successfully: 0\n" + " Create: 0\n" + " Modify: 0\n" + " Delete: 0\n" + " No Operation: 0\n" + "Number of objects processed with errors: 1\n" + " Create: 0\n" + " Modify: 0\n" + " Delete: 1\n" + "\n" + "DETAILED EXPLANATION:\n" + "\n" + "\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + "The following object(s) were found to have ERRORS:\n" + "\n" + "---\n" + "Delete FAILED: [route] 194.39.132.0/24AS1\n" + "\n" + "route: 194.39.132.0/24\n" + "descr: Description\n" + "origin: AS1\n" + "notify: [email protected]\n" + "mnt-by: TEST-MNT\n" + "source: RIPE\n" + "***Error: Unrecognized source: RIPE\n" + "delete: no longer required\n" + "\n" + "\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + "\n" + "The RIPE Database is subject to Terms and Conditions:\n" + "http: "\n" + "For assistance or clarification please contact:\n" + "RIPE Database Administration <[email protected]>\n")); assertVersion(response); }
public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); }
ResponseFactory { public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); } }
ResponseFactory { public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); }
ResponseFactory { public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
ResponseFactory { public String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack) { final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("ack", ack); velocityContext.put("updateContext", updateContext); return createResponse(TEMPLATE_ACK, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
@Test public void createHelpResponse() { final String response = subject.createHelpResponse(updateContext, origin); assertThat(response, containsString("" + "> From: Andre Kampert <[email protected]>\n" + "> Subject: delete route 194.39.132.0/24\n" + "> Date: Thu, 14 Jun 2012 10:04:42 +0200\n" + "> Reply-To: [email protected]\n" + "> Message-ID: <[email protected]>\n" + "\n" + "You have requested Help information from the RIPE NCC Database,\n" + "therefore the body of your message has been ignored.\n" + "\n" + "RIPE Database documentation is available at\n" + "\n" + "http: "\n" + "RIPE Database FAQ is available at\n" + "\n" + "http: "\n" + "RPSL RFCs are available at\n" + "\n" + "ftp: "ftp: "ftp: "\n" + "The RIPE Database is subject to Terms and Conditions:\n" + "http: "\n" + "For assistance or clarification please contact:\n" + "RIPE Database Administration <[email protected]>\n")); assertVersion(response); }
public String createHelpResponse(final UpdateContext updateContext, final Origin origin) { final VelocityContext velocityContext = new VelocityContext(); return createResponse(TEMPLATE_HELP, updateContext, velocityContext, origin); }
ResponseFactory { public String createHelpResponse(final UpdateContext updateContext, final Origin origin) { final VelocityContext velocityContext = new VelocityContext(); return createResponse(TEMPLATE_HELP, updateContext, velocityContext, origin); } }
ResponseFactory { public String createHelpResponse(final UpdateContext updateContext, final Origin origin) { final VelocityContext velocityContext = new VelocityContext(); return createResponse(TEMPLATE_HELP, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); }
ResponseFactory { public String createHelpResponse(final UpdateContext updateContext, final Origin origin) { final VelocityContext velocityContext = new VelocityContext(); return createResponse(TEMPLATE_HELP, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
ResponseFactory { public String createHelpResponse(final UpdateContext updateContext, final Origin origin) { final VelocityContext velocityContext = new VelocityContext(); return createResponse(TEMPLATE_HELP, updateContext, velocityContext, origin); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
@Test public void notification_success() { final RpslObject object1 = RpslObject.parse("mntner: DEV-ROOT1-MNT"); final Update update1 = new Update(new Paragraph(object1.toString()), Operation.UNSPECIFIED, Lists.<String>newArrayList(), object1); final PreparedUpdate create1 = new PreparedUpdate(update1, null, object1, Action.CREATE); final RpslObject object2 = RpslObject.parse("mntner: DEV-ROOT2-MNT"); final Update update2 = new Update(new Paragraph(object2.toString()), Operation.UNSPECIFIED, Lists.<String>newArrayList(), object2); final PreparedUpdate create2 = new PreparedUpdate(update2, null, object2, Action.CREATE); final Notification notification = new Notification("[email protected]"); notification.add(Notification.Type.SUCCESS, create1, updateContext); notification.add(Notification.Type.SUCCESS, create2, updateContext); final ResponseMessage responseMessage = subject.createNotification(updateContext, origin, notification); assertNotification(responseMessage); assertThat(responseMessage.getSubject(), is("Notification of RIPE Database changes")); assertThat(responseMessage.getMessage(), containsString("" + "Some object(s) in RIPE Database that you either\n" + "maintain or you are listed in as to-be-notified have\n" + "been added, deleted or changed.\n")); assertThat(responseMessage.getMessage(), containsString("" + "---\n" + "OBJECT BELOW CREATED:\n" + "\n" + "mntner: DEV-ROOT1-MNT\n" + "\n" + "---\n" + "OBJECT BELOW CREATED:\n" + "\n" + "mntner: DEV-ROOT2-MNT\n")); }
public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
@Test public void notification_success_with_user_in_the_session() { when(updateContext.getUserSession()).thenReturn(new UserSession("[email protected]", "Test User", true,"2033-01-30T16:38:27.369+11:00")); final RpslObject object1 = RpslObject.parse("mntner: DEV-ROOT1-MNT"); final Update update1 = new Update(new Paragraph(object1.toString()), Operation.UNSPECIFIED, Lists.<String>newArrayList(), object1); final PreparedUpdate create1 = new PreparedUpdate(update1, null, object1, Action.CREATE); final Notification notification = new Notification("[email protected]"); notification.add(Notification.Type.SUCCESS, create1, updateContext); final ResponseMessage responseMessage = subject.createNotification(updateContext, origin, notification); assertNotification(responseMessage); assertThat(responseMessage.getMessage(), containsString("You can reply to this message to contact the person who made this change.\n")); }
public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
@Test public void notification_success_with_effective_sso_credentials() { when(updateContext.getUserSession()).thenReturn(new UserSession("[email protected]", "Test User", true,"2033-01-30T16:38:27.369+11:00")); final RpslObject object1 = RpslObject.parse("mntner: DEV-ROOT1-MNT"); final Update update1 = new Update(new Paragraph(object1.toString()), Operation.UNSPECIFIED, Lists.<String>newArrayList(), object1); final PreparedUpdate create1 = new PreparedUpdate(update1, null, object1, Action.CREATE); update1.setEffectiveCredential("[email protected]", Update.EffectiveCredentialType.SSO); final Notification notification = new Notification("[email protected]"); notification.add(Notification.Type.SUCCESS, create1, updateContext); final ResponseMessage responseMessage = subject.createNotification(updateContext, origin, notification); assertNotification(responseMessage); assertThat(responseMessage.getMessage(), containsString("" + "---\n" + "OBJECT BELOW CREATED:\n" + "\n" + "mntner: DEV-ROOT1-MNT\n" + "\n" + "Changed by SSO account: [email protected]\n"+ "\n" )); }
public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
@Test public void notification_success_with_effective_pgp_credentials() { final RpslObject object1 = RpslObject.parse("mntner: DEV-ROOT1-MNT"); final Update update1 = new Update(new Paragraph(object1.toString()), Operation.UNSPECIFIED, Lists.<String>newArrayList(), object1); final PreparedUpdate create1 = new PreparedUpdate(update1, null, object1, Action.CREATE); update1.setEffectiveCredential("PGP-KEY-123", Update.EffectiveCredentialType.PGP); final Notification notification = new Notification("[email protected]"); notification.add(Notification.Type.SUCCESS, create1, updateContext); final ResponseMessage responseMessage = subject.createNotification(updateContext, origin, notification); assertNotification(responseMessage); assertThat(responseMessage.getMessage(), containsString("" + "---\n" + "OBJECT BELOW CREATED:\n" + "\n" + "mntner: DEV-ROOT1-MNT\n" + "\n" + "Changed by PGP-KEY-123. You can find contact details for this key here:\n" + "https: "\n" )); }
public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
@Test public void notification_success_filter_auth() { final RpslObject object = RpslObject.parse("" + "mntner: DEV-MNT\n" + "auth: MD5-PW $1$YmPozTxJ$s3eGZRVrKVGdSDTeEZJu "source: RIPE" ); final Update update = new Update(new Paragraph(object.toString()), Operation.UNSPECIFIED, Lists.<String>newArrayList(), object); final PreparedUpdate create = new PreparedUpdate(update, null, object, Action.CREATE); final Notification notification = new Notification("[email protected]"); notification.add(Notification.Type.SUCCESS, create, updateContext); final ResponseMessage responseMessage = subject.createNotification(updateContext, origin, notification); assertNotification(responseMessage); assertThat(responseMessage.getSubject(), is("Notification of RIPE Database changes")); assertThat(responseMessage.getMessage(), containsString("" + "Some object(s) in RIPE Database that you either\n" + "maintain or you are listed in as to-be-notified have\n" + "been added, deleted or changed.\n")); assertThat(responseMessage.getMessage(), containsString("" + "---\n" + "OBJECT BELOW CREATED:\n" + "\n" + "mntner: DEV-MNT\n" + "auth: MD5-PW # Filtered\n" + "source: RIPE # Filtered\n" + "")); }
public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
@Test public void transform_inetnum_prefix_with_comment() { final RpslObject rpslObject = RpslObject.parse("inetnum: 193/8 # Comment"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.toString(), is("inetnum: 193.0.0.0 - 193.255.255.255 # Comment\n")); verify(objectMessages).addMessage(result.getTypeAttribute(), ValidationMessages.attributeValueConverted("193/8", "193.0.0.0 - 193.255.255.255")); verify(objectMessages).addMessage(result.getTypeAttribute(), ValidationMessages.remarksReformatted()); verifyNoMoreInteractions(objectMessages); }
public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
@Test public void notification_success_reference() { final RpslObject object1 = RpslObject.parse("mntner: DEV-ROOT1-MNT"); final Update update1 = new Update(new Paragraph(object1.toString()), Operation.UNSPECIFIED, Lists.<String>newArrayList(), object1); final PreparedUpdate create1 = new PreparedUpdate(update1, null, object1, Action.CREATE); final RpslObject object2 = RpslObject.parse("mntner: DEV-ROOT2-MNT"); final Update update2 = new Update(new Paragraph(object2.toString()), Operation.UNSPECIFIED, Lists.<String>newArrayList(), object2); final PreparedUpdate create2 = new PreparedUpdate(update2, null, object2, Action.CREATE); final Notification notification = new Notification("[email protected]"); notification.add(Notification.Type.SUCCESS_REFERENCE, create1, updateContext); notification.add(Notification.Type.SUCCESS_REFERENCE, create2, updateContext); final ResponseMessage responseMessage = subject.createNotification(updateContext, origin, notification); assertNotification(responseMessage); assertThat(responseMessage.getSubject(), is("Notification of RIPE Database changes")); assertThat(responseMessage.getMessage(), containsString("" + "Some object(s) in RIPE Database added references to\n" + "objects you are listed in as to-be-notified.")); assertThat(responseMessage.getMessage(), containsString("" + "---\n" + "OBJECT BELOW CREATED:\n" + "\n" + "mntner: DEV-ROOT1-MNT\n" + "\n" + "---\n" + "OBJECT BELOW CREATED:\n" + "\n" + "mntner: DEV-ROOT2-MNT")); }
public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
@Test public void notification_auth_failed() { final RpslObject object1 = RpslObject.parse("mntner: DEV-ROOT1-MNT"); final Update update1 = new Update(new Paragraph(object1.toString()), Operation.UNSPECIFIED, Lists.<String>newArrayList(), object1); final PreparedUpdate create1 = new PreparedUpdate(update1, null, object1, Action.CREATE); final RpslObject object2 = RpslObject.parse("mntner: DEV-ROOT2-MNT"); final Update update2 = new Update(new Paragraph(object2.toString()), Operation.UNSPECIFIED, Lists.<String>newArrayList(), object2); final PreparedUpdate create2 = new PreparedUpdate(update2, null, object2, Action.CREATE); final Notification notification = new Notification("[email protected]"); notification.add(Notification.Type.FAILED_AUTHENTICATION, create1, updateContext); notification.add(Notification.Type.FAILED_AUTHENTICATION, create2, updateContext); final ResponseMessage responseMessage = subject.createNotification(updateContext, origin, notification); assertNotification(responseMessage); assertThat(responseMessage.getSubject(), is("RIPE Database updates, auth error notification")); assertThat(responseMessage.getMessage(), containsString("" + "Some objects in which you are referenced as a\n" + "maintainer were requested to be changed, but *failed*\n" + "the proper authorisation for any of the referenced\n" + "maintainers.")); assertThat(responseMessage.getMessage(), containsString("" + "---\n" + "CREATE REQUESTED FOR:\n" + "\n" + "mntner: DEV-ROOT1-MNT\n" + "\n" + "---\n" + "CREATE REQUESTED FOR:\n" + "\n" + "mntner: DEV-ROOT2-MNT")); }
public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
ResponseFactory { public ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification) { final String ssoUserEmail = updateContext.getUserSession() != null ? updateContext.getUserSession().getUsername() : ""; final VelocityContext velocityContext = new VelocityContext(); velocityContext.put("failedAuthentication", notification.getUpdates(Notification.Type.FAILED_AUTHENTICATION)); velocityContext.put("success", notification.getUpdates(Notification.Type.SUCCESS)); velocityContext.put("successReference", notification.getUpdates(Notification.Type.SUCCESS_REFERENCE)); velocityContext.put("ssoUser", ssoUserEmail); final String subject; if (notification.has(Notification.Type.FAILED_AUTHENTICATION)) { subject = "RIPE Database updates, auth error notification"; } else { subject = "Notification of RIPE Database changes"; } return new ResponseMessage(subject, createResponse(TEMPLATE_NOTIFICATION, updateContext, velocityContext, origin), ssoUserEmail); } @Autowired ResponseFactory( final DateTimeProvider dateTimeProvider, final ApplicationVersion applicationVersion, @Value("${whois.source}") final String source); String createExceptionResponse(final UpdateContext updateContext, final Origin origin); String createAckResponse(final UpdateContext updateContext, final Origin origin, final Ack ack); String createHelpResponse(final UpdateContext updateContext, final Origin origin); ResponseMessage createNotification(final UpdateContext updateContext, final Origin origin, final Notification notification); }
@Test public void testGetActions() { assertThat(subject.getActions(), containsInAnyOrder(Action.DELETE)); }
@Override public ImmutableList<Action> getActions() { return ACTIONS; }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired SetNotReferencedValidator(final RpslObjectDao objectDao); }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired SetNotReferencedValidator(final RpslObjectDao objectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired SetNotReferencedValidator(final RpslObjectDao objectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void testGetTypes() { assertThat(subject.getTypes(), containsInAnyOrder(ObjectType.AS_SET, ObjectType.ROUTE_SET, ObjectType.RTR_SET)); }
@Override public ImmutableList<ObjectType> getTypes() { return TYPES; }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired SetNotReferencedValidator(final RpslObjectDao objectDao); }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired SetNotReferencedValidator(final RpslObjectDao objectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired SetNotReferencedValidator(final RpslObjectDao objectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void set_that_has_incoming_references() { final RpslObject routeSet = RpslObject.parse("route-set: rs-AH"); when(update.getUpdatedObject()).thenReturn(routeSet); when(objectDao.findMemberOfByObjectTypeWithoutMbrsByRef(ObjectType.ROUTE_SET, "rs-AH")).thenReturn(Lists.newArrayList(new RpslObjectInfo(1, ObjectType.ROUTE, "192.168.0.1/32"))); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.objectInUse(routeSet)); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final List<RpslObjectInfo> incomingReferences = objectDao.findMemberOfByObjectTypeWithoutMbrsByRef(updatedObject.getType(), updatedObject.getKey().toString()); if (!incomingReferences.isEmpty()) { updateContext.addMessage(update, UpdateMessages.objectInUse(updatedObject)); } }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final List<RpslObjectInfo> incomingReferences = objectDao.findMemberOfByObjectTypeWithoutMbrsByRef(updatedObject.getType(), updatedObject.getKey().toString()); if (!incomingReferences.isEmpty()) { updateContext.addMessage(update, UpdateMessages.objectInUse(updatedObject)); } } }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final List<RpslObjectInfo> incomingReferences = objectDao.findMemberOfByObjectTypeWithoutMbrsByRef(updatedObject.getType(), updatedObject.getKey().toString()); if (!incomingReferences.isEmpty()) { updateContext.addMessage(update, UpdateMessages.objectInUse(updatedObject)); } } @Autowired SetNotReferencedValidator(final RpslObjectDao objectDao); }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final List<RpslObjectInfo> incomingReferences = objectDao.findMemberOfByObjectTypeWithoutMbrsByRef(updatedObject.getType(), updatedObject.getKey().toString()); if (!incomingReferences.isEmpty()) { updateContext.addMessage(update, UpdateMessages.objectInUse(updatedObject)); } } @Autowired SetNotReferencedValidator(final RpslObjectDao objectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final List<RpslObjectInfo> incomingReferences = objectDao.findMemberOfByObjectTypeWithoutMbrsByRef(updatedObject.getType(), updatedObject.getKey().toString()); if (!incomingReferences.isEmpty()) { updateContext.addMessage(update, UpdateMessages.objectInUse(updatedObject)); } } @Autowired SetNotReferencedValidator(final RpslObjectDao objectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void set_that_has_no_incoming_references() { final RpslObject asSet = RpslObject.parse("as-set: AS1325:AS-lopp"); when(update.getUpdatedObject()).thenReturn(asSet); when(objectDao.findMemberOfByObjectTypeWithoutMbrsByRef(ObjectType.AS_SET, "rs-AH")).thenReturn(Lists.<RpslObjectInfo>newArrayList()); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.objectInUse(asSet)); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final List<RpslObjectInfo> incomingReferences = objectDao.findMemberOfByObjectTypeWithoutMbrsByRef(updatedObject.getType(), updatedObject.getKey().toString()); if (!incomingReferences.isEmpty()) { updateContext.addMessage(update, UpdateMessages.objectInUse(updatedObject)); } }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final List<RpslObjectInfo> incomingReferences = objectDao.findMemberOfByObjectTypeWithoutMbrsByRef(updatedObject.getType(), updatedObject.getKey().toString()); if (!incomingReferences.isEmpty()) { updateContext.addMessage(update, UpdateMessages.objectInUse(updatedObject)); } } }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final List<RpslObjectInfo> incomingReferences = objectDao.findMemberOfByObjectTypeWithoutMbrsByRef(updatedObject.getType(), updatedObject.getKey().toString()); if (!incomingReferences.isEmpty()) { updateContext.addMessage(update, UpdateMessages.objectInUse(updatedObject)); } } @Autowired SetNotReferencedValidator(final RpslObjectDao objectDao); }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final List<RpslObjectInfo> incomingReferences = objectDao.findMemberOfByObjectTypeWithoutMbrsByRef(updatedObject.getType(), updatedObject.getKey().toString()); if (!incomingReferences.isEmpty()) { updateContext.addMessage(update, UpdateMessages.objectInUse(updatedObject)); } } @Autowired SetNotReferencedValidator(final RpslObjectDao objectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetNotReferencedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final List<RpslObjectInfo> incomingReferences = objectDao.findMemberOfByObjectTypeWithoutMbrsByRef(updatedObject.getType(), updatedObject.getKey().toString()); if (!incomingReferences.isEmpty()) { updateContext.addMessage(update, UpdateMessages.objectInUse(updatedObject)); } } @Autowired SetNotReferencedValidator(final RpslObjectDao objectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void testGetActions() { assertThat(subject.getActions(), containsInAnyOrder(Action.CREATE, Action.MODIFY)); }
@Override public ImmutableList<Action> getActions() { return ACTIONS; }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } PeeringSetAttributeMustBePresent(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void testGetTypes() { assertThat(subject.getTypes(), Matchers.contains(ObjectType.PEERING_SET, ObjectType.FILTER_SET)); }
@Override public ImmutableList<ObjectType> getTypes() { return TYPES; }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } PeeringSetAttributeMustBePresent(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void mpPeering_and_peering_present() { when(update.getType()).thenReturn(ObjectType.PEERING_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("peering-set: prng-ripe\ndescr: description\npeering: AS6845 at 194.102.255.254\nmp-peering: AS702:PRNG-AT-CUSTOMER")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.eitherSimpleOrComplex(ObjectType.PEERING_SET, "peering", "mp-peering")); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void mpPeering_nor_peering_present() { when(update.getType()).thenReturn(ObjectType.PEERING_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("peering-set: prng-ripe\ndescr: description")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.neitherSimpleOrComplex(ObjectType.PEERING_SET, "peering", "mp-peering")); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void transform_inet6num_no_change() { final RpslObject rpslObject = RpslObject.parse("inet6num: 2001:67c:20c4::/48"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.INET6NUM).toString(), is("2001:67c:20c4::/48")); verifyZeroInteractions(objectMessages); }
public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
@Test public void only_mpPeering_present() { when(update.getType()).thenReturn(ObjectType.PEERING_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("peering-set: prng-ripe\ndescr: description\nmp-peering: AS702:PRNG-AT-CUSTOMER")); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.eitherSimpleOrComplex(ObjectType.PEERING_SET, "peering", "mp-peering")); verify(updateContext, never()).addMessage(update, UpdateMessages.neitherSimpleOrComplex(ObjectType.PEERING_SET, "peering", "mp-peering")); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void only_peering_present() { when(update.getType()).thenReturn(ObjectType.PEERING_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("peering-set: prng-ripe\ndescr: description\npeering: AS6845 at 194.102.255.254")); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.eitherSimpleOrComplex(ObjectType.PEERING_SET, "peering", "mp-peering")); verify(updateContext, never()).addMessage(update, UpdateMessages.neitherSimpleOrComplex(ObjectType.PEERING_SET, "peering", "mp-peering")); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void filter_and_mpFilter_present() { when(update.getType()).thenReturn(ObjectType.FILTER_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("filter-set: prng-ripe\ndescr: description\nfilter: AS6845 at 194.102.255.254\nmp-filter: AS702:PRNG-AT-CUSTOMER")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.eitherSimpleOrComplex(ObjectType.FILTER_SET, "filter", "mp-filter")); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void mpFilter_nor_filter_present() { when(update.getType()).thenReturn(ObjectType.FILTER_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("filter-set: prng-ripe\ndescr: description")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.neitherSimpleOrComplex(ObjectType.FILTER_SET, "filter", "mp-filter")); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void only_mpFilter_present() { when(update.getType()).thenReturn(ObjectType.FILTER_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("filter-set: prng-ripe\ndescr: description\nmp-filter: AS702:PRNG-AT-CUSTOMER")); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.eitherSimpleOrComplex(ObjectType.FILTER_SET, "filter", "mp-filter")); verify(updateContext, never()).addMessage(update, UpdateMessages.neitherSimpleOrComplex(ObjectType.FILTER_SET, "filter", "mp-filter")); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void only_filter_present() { when(update.getType()).thenReturn(ObjectType.FILTER_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("filter-set: prng-ripe\ndescr: description\nfilter: AS6845 at 194.102.255.254")); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.eitherSimpleOrComplex(ObjectType.FILTER_SET, "filter", "mp-filter")); verify(updateContext, never()).addMessage(update, UpdateMessages.neitherSimpleOrComplex(ObjectType.FILTER_SET, "filter", "mp-filter")); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
PeeringSetAttributeMustBePresent implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final ObjectType objectType = update.getType(); final List<AttributeType> attributeTypes = attributeMap.get(objectType); final AttributeType simpleAttribute = attributeTypes.get(0); final List<RpslAttribute> simpleAttributes = updatedObject.findAttributes(simpleAttribute); final AttributeType complexAttribute = attributeTypes.get(1); final List<RpslAttribute> extendedAttributes = updatedObject.findAttributes(complexAttribute); if (simpleAttributes.isEmpty() && extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.neitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } if (!simpleAttributes.isEmpty() && !extendedAttributes.isEmpty()) { updateContext.addMessage(update, UpdateMessages.eitherSimpleOrComplex(objectType, simpleAttribute.getName(), complexAttribute.getName())); } } PeeringSetAttributeMustBePresent(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void getActions() { assertThat(subject.getActions(), containsInAnyOrder(Action.CREATE)); }
@Override public ImmutableList<Action> getActions() { return ACTIONS; }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void getTypes() { assertThat(subject.getTypes(), containsInAnyOrder(ObjectType.AS_SET, ObjectType.FILTER_SET, ObjectType.PEERING_SET, ObjectType.ROUTE_SET, ObjectType.RTR_SET)); }
@Override public ImmutableList<ObjectType> getTypes() { return TYPES; }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_missing_parent() { when(update.getType()).thenReturn(ObjectType.FILTER_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("filter-set: FLTR-RIPE:FLTR-ALLOCBNDR:FLTR-IPV6:fltr-something")); when(objectDao.getByKeys(eq(ObjectType.FILTER_SET), anyCollection())).thenReturn(Lists.<RpslObject>newArrayList()); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.parentObjectNotFound("FLTR-RIPE:FLTR-ALLOCBNDR:FLTR-IPV6")); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_no_hiearchy() { when(update.getType()).thenReturn(ObjectType.FILTER_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("filter-set: FLTR-ND")); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void transform_inet6num_leading_zeroes() { final RpslObject rpslObject = RpslObject.parse("inet6num: 2001:067c:20c4::/48"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.INET6NUM).toString(), is("2001:67c:20c4::/48")); verify(objectMessages).addMessage(result.getTypeAttribute(), ValidationMessages.attributeValueConverted("2001:067c:20c4::/48", "2001:67c:20c4::/48")); verifyNoMoreInteractions(objectMessages); }
public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
@Test public void validate_autnum_lookup_does_not_exist() { when(update.getType()).thenReturn(ObjectType.AS_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("as-set: AS101:AS-TEST")); when(objectDao.getByKeys(eq(ObjectType.AUT_NUM), anyCollection())).thenReturn(Lists.<RpslObject>newArrayList()); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.parentObjectNotFound("AS101")); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_autnum_lookup_does_not_exist_with_override() { when(updateSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getType()).thenReturn(ObjectType.AS_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("as-set: AS101:AS-TEST")); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_autnum_lookup_exists_but_is_not_authenticated() { when(update.getType()).thenReturn(ObjectType.AS_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("as-set: AS101:AS-TEST")); when(objectDao.getByKeys(eq(ObjectType.AUT_NUM), anyCollection())).thenReturn(Lists.<RpslObject>newArrayList(RpslObject.parse("aut-num: AS101"))); when(authenticationModule.authenticate(eq(update), eq(updateContext), anyList())).thenReturn(Lists.<RpslObject>newArrayList()); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.parentAuthenticationFailed(RpslObject.parse("aut-num: AS101"), AttributeType.MNT_BY, Lists.<RpslObject>newArrayList())); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_autnum_lookup_exists_and_is_authenticated() { when(update.getType()).thenReturn(ObjectType.AS_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("as-set: AS101:AS-TEST")); when(objectDao.getByKeys(eq(ObjectType.AUT_NUM), anyCollection())).thenReturn(Lists.<RpslObject>newArrayList(RpslObject.parse("aut-num: AS101\nmnt-by: TEST-MNT"))); when(authenticationModule.authenticate(eq(update), eq(updateContext), anyList())).thenReturn(Lists.<RpslObject>newArrayList(RpslObject.parse("mntner: TEST-MNT"))); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_routeset_against_autnum() { when(update.getType()).thenReturn(ObjectType.ROUTE_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("route-set: As101:RS-ROUTESET")); when(objectDao.getByKeys(eq(ObjectType.AUT_NUM), anyCollection())).thenReturn(Lists.<RpslObject>newArrayList(RpslObject.parse("aut-num: AS101\nmnt-by: TEST-MNT"))); when(authenticationModule.authenticate(eq(update), eq(updateContext), anyList())).thenReturn(Lists.<RpslObject>newArrayList(RpslObject.parse("mntner: TEST-MNT"))); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_routeset_against_parent() { when(update.getType()).thenReturn(ObjectType.ROUTE_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("route-set: RS-PARENT:RS-CHILD")); when(objectDao.getByKeys(eq(ObjectType.ROUTE_SET), anyCollection())).thenReturn(Lists.<RpslObject>newArrayList(RpslObject.parse("route-set: RS-PARENT\nmnt-lower: TEST-MNT"))); when(authenticationModule.authenticate(eq(update), eq(updateContext), anyList())).thenReturn(Lists.<RpslObject>newArrayList(RpslObject.parse("mntner: TEST-MNT"))); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_routeset_against_parent_not_authenticated() { when(update.getType()).thenReturn(ObjectType.ROUTE_SET); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("route-set: RS-PARENT:RS-CHILD")); when(objectDao.getByKeys(eq(ObjectType.ROUTE_SET), anyCollection())).thenReturn(Lists.<RpslObject>newArrayList(RpslObject.parse("route-set: RS-PARENT\nmnt-by: TEST-MNT"))); when(authenticationModule.authenticate(eq(update), eq(updateContext), anyList())).thenReturn(Lists.<RpslObject>newArrayList()); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.parentAuthenticationFailed(RpslObject.parse("route-set: RS-PARENT"), AttributeType.MNT_BY, Lists.<RpslObject>newArrayList())); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SetnameMustExistValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (updateContext.getSubject(update).hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final String key = update.getUpdatedObject().getTypeAttribute().getCleanValue().toString(); final int lastColon = key.lastIndexOf(':'); if (lastColon < 0) { return; } final CIString parentKey = ciString(key.substring(0, lastColon)); final RpslObject parent = CollectionHelper.uniqueResult( objectDao.getByKeys(findObjectType(update.getType(), parentKey), Collections.singleton(parentKey))); if (parent == null) { updateContext.addMessage(update, UpdateMessages.parentObjectNotFound(parentKey)); return; } final List<RpslObject> referencedMaintainers = findMaintainers(parent); final List<RpslObject> authenticatedMaintainers = authenticationModule.authenticate(update, updateContext, referencedMaintainers); if (authenticatedMaintainers.isEmpty()) { updateContext.addMessage(update, UpdateMessages.parentAuthenticationFailed(parent, findAttributeType(parent), referencedMaintainers)); } } @Autowired SetnameMustExistValidator(final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void getActions() { assertThat(subject.getActions().size(), is(2)); assertThat(subject.getActions().contains(Action.MODIFY), is(true)); assertThat(subject.getActions().contains(Action.CREATE), is(true)); }
@Override public ImmutableList<Action> getActions() { return ACTIONS; }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void getTypes() { assertThat(subject.getTypes().size(), is(1)); assertThat(subject.getTypes().get(0), is(ObjectType.ORGANISATION)); }
@Override public ImmutableList<ObjectType> getTypes() { return TYPES; }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_is_override() { when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); subject.validate(update, updateContext); verify(updateContext).getSubject(any(UpdateContainer.class)); verifyNoMoreInteractions(update); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void transform_inet6num_uppercase() { final RpslObject rpslObject = RpslObject.parse("inet6num: 2001:67C:20C4::/48"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.INET6NUM).toString(), is("2001:67c:20c4::/48")); verify(objectMessages).addMessage(result.getTypeAttribute(), ValidationMessages.attributeValueConverted("2001:67C:20C4::/48", "2001:67c:20c4::/48")); verifyNoMoreInteractions(objectMessages); }
public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
@Test public void status_other() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("organisation: ORG-TST-RIPE\norg-type: other")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgtype_has_not_changed() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("organisation: ORG-TST-RIPE\norg-type: RIR")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); when(update.getReferenceObject()).thenReturn(RpslObject.parse("organisation: ORG-TST-RIPE\norg-type: RIR")); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void not_auth_by_powermntner() { final RpslObject rpslObject = RpslObject.parse("organisation: ORG-TST-RIPE\norg-type: RIR"); when(update.getUpdatedObject()).thenReturn(rpslObject); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); when(update.getReferenceObject()).thenReturn(RpslObject.parse("organisation: ORG-TST-RIPE\norg-type: LIR")); when(update.getAction()).thenReturn(Action.MODIFY); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext).addMessage(update, rpslObject.findAttribute(AttributeType.ORG_TYPE), UpdateMessages.invalidMaintainerForOrganisationType("RIR")); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgtype_has_changed_auth_by_powermntner() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("organisation: ORG-TST-RIPE\norg-type: RIR")); when(updateContext.getSubject(update)).thenReturn(authenticationSubject); when(update.getReferenceObject()).thenReturn(RpslObject.parse("organisation: ORG-TST-RIPE\norg-type: LIR")); when(update.getAction()).thenReturn(Action.MODIFY); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrganisationTypeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)) { return; } final RpslAttribute orgTypeAttribute = update.getUpdatedObject().findAttribute(AttributeType.ORG_TYPE); final CIString orgType = orgTypeAttribute.getCleanValue(); if ((OrgType.OTHER != OrgType.getFor(orgType)) && orgTypeHasChanged(update) && !subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { updateContext.addMessage(update, orgTypeAttribute, UpdateMessages.invalidMaintainerForOrganisationType(orgType)); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void getActions() { assertThat(subject.getActions(), contains(Action.MODIFY)); }
@Override public ImmutableList<Action> getActions() { return ACTIONS; }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void getTypes() { assertThat(subject.getTypes(), contains(ObjectType.ORGANISATION)); }
@Override public ImmutableList<ObjectType> getTypes() { return TYPES; }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgname_not_changed() { when(update.getReferenceObject()).thenReturn(ORIGINAL_ORG); when(update.getUpdatedObject()).thenReturn(UPDATED_ORG_SAME_NAME); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgname_changed_not_referenced_at_all() { when(update.getReferenceObject()).thenReturn(ORIGINAL_ORG); when(update.getUpdatedObject()).thenReturn(UPDATED_ORG_NEW_NAME); when(updateDao.getReferences(ORIGINAL_ORG)).thenReturn(Collections.EMPTY_SET); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgname_changed_for_lir() { presetOverrideAuthentication(); when(update.getReferenceObject()).thenReturn(ORIGINAL_LIR); when(update.getUpdatedObject()).thenReturn(UPDATED_LIR); presetReferrers(REFERRER_MNT_BY_RS, REFERRER_MNT_BY_LEGACY); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgname_changed_not_referenced_by_resource() { when(update.getReferenceObject()).thenReturn(ORIGINAL_ORG); when(update.getUpdatedObject()).thenReturn(UPDATED_ORG_NEW_NAME); when(updateDao.getReferences(ORIGINAL_ORG)).thenReturn(Sets.newHashSet(new RpslObjectInfo(5, ObjectType.PERSON, "TEST-NIC"))); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void transform_inet6num_trailing_zero() { final RpslObject rpslObject = RpslObject.parse("inet6num: 2001:67c:20c4::0/48"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.INET6NUM).toString(), is("2001:67c:20c4::/48")); verify(objectMessages).addMessage(result.getTypeAttribute(), ValidationMessages.attributeValueConverted("2001:67c:20c4::0/48", "2001:67c:20c4::/48")); verifyNoMoreInteractions(objectMessages); }
public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
@Test public void orgname_changed_referenced_by_resource_without_RSmntner__no_RSmntner_auth() { when(update.getReferenceObject()).thenReturn(ORIGINAL_ORG); when(update.getUpdatedObject()).thenReturn(UPDATED_ORG_NEW_NAME); presetReferrers(REFERRER_MNT_BY_USER); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("TEST-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgname_changed_referenced_by_resource_with_RSmntner__no_RSmntner_auth() { when(update.getReferenceObject()).thenReturn(ORIGINAL_ORG); when(update.getUpdatedObject()).thenReturn(UPDATED_ORG_NEW_NAME); when(maintainers.isRsMaintainer(Sets.newHashSet(CIString.ciString("RIPE-NCC-HM-MNT")))).thenReturn(true); presetReferrers(REFERRER_MNT_BY_RS); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext).addMessage(update, UPDATED_ORG_NEW_NAME.findAttribute(AttributeType.ORG_NAME), UpdateMessages.cantChangeOrgName()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgname_changed_referenced_by_resource_with_LEGACY_mntner__no_LEGACY_mntner_auth() { when(update.getReferenceObject()).thenReturn(ORIGINAL_ORG); when(update.getUpdatedObject()).thenReturn(UPDATED_ORG_NEW_NAME); when(maintainers.isRsMaintainer(Sets.newHashSet(CIString.ciString("RIPE-NCC-LEGACY-MNT")))).thenReturn(true); presetReferrers(REFERRER_MNT_BY_LEGACY); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext).addMessage(update, UPDATED_ORG_NEW_NAME.findAttribute(AttributeType.ORG_NAME), UpdateMessages.cantChangeOrgName()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-LEGACY-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgname_changed_referenced_by_resource_with_RS_and_LEGACY_mntner__no_LEGACY_mntner_auth() { presetOverrideAuthentication(); when(update.getReferenceObject()).thenReturn(ORIGINAL_ORG); when(update.getUpdatedObject()).thenReturn(UPDATED_ORG_NEW_NAME); presetReferrers(REFERRER_MNT_BY_RS, REFERRER_MNT_BY_LEGACY); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(update, UPDATED_ORG_NEW_NAME.findAttribute(AttributeType.ORG_NAME), UpdateMessages.cantChangeOrgName()); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgname_changed_referenced_by_resource_with_RSmntner__RSmaintainer_auth() { presetOverrideAuthentication(); when(update.getReferenceObject()).thenReturn(ORIGINAL_ORG); when(update.getUpdatedObject()).thenReturn(UPDATED_ORG_NEW_NAME); presetReferrers(REFERRER_MNT_BY_RS); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgname_changed_referenced_by_resource_with_LEGACY_mntner__LEGACY_maintainer_auth() { presetRsAuthentication(); when(update.getReferenceObject()).thenReturn(ORIGINAL_ORG); when(update.getUpdatedObject()).thenReturn(UPDATED_ORG_NEW_NAME); presetReferrers(REFERRER_MNT_BY_LEGACY); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgname_changed_referenced_by_resource_with_RSmntner__auth_by_override() { presetOverrideAuthentication(); when(update.getReferenceObject()).thenReturn(ORIGINAL_ORG); when(update.getUpdatedObject()).thenReturn(UPDATED_ORG_NEW_NAME); presetReferrers(REFERRER_MNT_BY_RS); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgname_changed_referenced_by_resource_with_LEGACY_mntner__auth_by_override() { presetOverrideAuthentication(); when(update.getReferenceObject()).thenReturn(ORIGINAL_ORG); when(update.getUpdatedObject()).thenReturn(UPDATED_ORG_NEW_NAME); presetReferrers(REFERRER_MNT_BY_LEGACY); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgname_changed_referenced_by_resource_with_RS_and_LEGACY_mntner__auth_by_override() { presetOverrideAuthentication(); when(update.getReferenceObject()).thenReturn(ORIGINAL_ORG); when(update.getUpdatedObject()).thenReturn(UPDATED_ORG_NEW_NAME); presetReferrers(REFERRER_MNT_BY_RS, REFERRER_MNT_BY_LEGACY); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<RpslAttribute>anyObject(), Matchers.<Message>anyObject()); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void orgname_changed_referenced_by_resource_with_RSmntner_change_is_case_sensitive() { when(update.getReferenceObject()).thenReturn(ORIGINAL_ORG); when(update.getUpdatedObject()).thenReturn(UPDATED_ORG_CASE_CHANGE); when(maintainers.isRsMaintainer(Sets.newHashSet(CIString.ciString("RIPE-NCC-HM-MNT")))).thenReturn(true); presetReferrers(REFERRER_MNT_BY_RS); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(updateContext).addMessage(update, ORIGINAL_ORG.findAttribute(AttributeType.ORG_NAME), UpdateMessages.cantChangeOrgName()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
OrgNameNotChangedValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); if (isLir(originalObject)) { return; } if (orgNameDidntChange(originalObject, updatedObject)) { return; } final Subject subject = updateContext.getSubject(update); if (alreadyHasAllPossibleAuthorisations(subject)) { return; } if (isReferencedByRsMaintainedResource(originalObject)) { final RpslAttribute orgNameAttribute = updatedObject.findAttribute(AttributeType.ORG_NAME); updateContext.addMessage(update, orgNameAttribute, UpdateMessages.cantChangeOrgName()); } } @Autowired OrgNameNotChangedValidator(final RpslObjectUpdateDao objectUpdateDao, final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void transform_inet6num_prefix_with_comment() { final RpslObject rpslObject = RpslObject.parse("inet6num: 2001:67c:20c4::0/48 # Comment"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.toString(), is("inet6num: 2001:67c:20c4::/48 # Comment\n")); verify(objectMessages).addMessage(result.getTypeAttribute(), ValidationMessages.attributeValueConverted("2001:67c:20c4::0/48", "2001:67c:20c4::/48")); verify(objectMessages).addMessage(result.getTypeAttribute(), ValidationMessages.remarksReformatted()); verifyNoMoreInteractions(objectMessages); }
public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
@Test public void has_no_abusec() { when(update.getUpdatedObject()).thenReturn(OTHER_ORG_WITHOUT_ABUSE_C); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void references_role_without_abuse_mailbox() { when(update.getUpdatedObject()).thenReturn(OTHER_ORG_WITH_ABUSE_C); when(objectDao.getByKey(eq(ObjectType.ROLE), eq(CIString.ciString("AB-NIC")))).thenReturn(ROLE_WITHOUT_ABUSE_MAILBOX); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.abuseMailboxRequired("AB-NIC", update.getUpdatedObject().getType())); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void references_role_with_abuse_mailbox() { when(update.getUpdatedObject()).thenReturn(OTHER_ORG_WITH_ABUSE_C); when(objectDao.getByKey(eq(ObjectType.ROLE), eq(CIString.ciString("AB-NIC")))).thenReturn(ROLE_WITH_ABUSE_MAILBOX); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void references_person_instead_of_role() { when(update.getUpdatedObject()).thenReturn(OTHER_ORG_WITH_ABUSE_C); when(objectDao.getByKey(eq(ObjectType.ROLE), eq(CIString.ciString("AB-NIC")))).thenThrow(new EmptyResultDataAccessException(1)); when(objectDao.getByKey(eq(ObjectType.PERSON), eq(CIString.ciString("AB-NIC")))).thenReturn(PERSON_WITHOUT_ABUSE_MAILBOX); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.abuseCPersonReference()); verify(updateContext, never()).addMessage(update, UpdateMessages.abuseMailboxRequired("nic-hdl: AB-NIC", update.getUpdatedObject().getType())); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void reference_not_found() { when(update.getUpdatedObject()).thenReturn(OTHER_ORG_WITH_ABUSE_C); when(objectDao.getByKey(eq(ObjectType.ROLE), eq(CIString.ciString("AB-NIC")))).thenThrow(new EmptyResultDataAccessException(1)); when(objectDao.getByKey(eq(ObjectType.PERSON), eq(CIString.ciString("AB-NIC")))).thenThrow(new EmptyResultDataAccessException(1)); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void remove_abuse_contact_LIR_org() { when(update.getReferenceObject()).thenReturn(LIR_ORG_WITH_ABUSE_C); when(update.getUpdatedObject()).thenReturn(LIR_ORG_WITHOUT_ABUSE_C); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.abuseContactNotRemovable()); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void allow_remove_abuse_contact_when_non_LIR_no_referencing_objects() { when(update.getReferenceObject()).thenReturn(OTHER_ORG_WITH_ABUSE_C); when(update.getUpdatedObject()).thenReturn(OTHER_ORG_WITHOUT_ABUSE_C); when(updateDao.getReferences(update.getUpdatedObject())).thenReturn(Collections.EMPTY_SET); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void allow_remove_abusec_when_referencing_object_is_not_resource() { final RpslObject referencingPerson = RpslObject.parse( "person: A Person\n" + "address: Address 1\n" + "phone: +31 20 535 4444\n" + "nic-hdl: DUMY-RIPE\n" + "org: ORG-1\n" + "mnt-by: A_NON_RS_MAINTAINER\n" + "source: RIPE"); final RpslObjectInfo info = new RpslObjectInfo(1, ObjectType.PERSON, "AS6"); when(update.getReferenceObject()).thenReturn(OTHER_ORG_WITH_ABUSE_C); when(update.getUpdatedObject()).thenReturn(OTHER_ORG_WITHOUT_ABUSE_C); when(updateDao.getReferences(update.getUpdatedObject())).thenReturn(Sets.newHashSet(info)); when(objectDao.getById(1)).thenReturn(referencingPerson); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); verifyZeroInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void allow_remove_abuse_contact_when_referencing_resources_is_not_rs_maintained() { final RpslObjectInfo info = new RpslObjectInfo(1, ObjectType.AUT_NUM, "AS6"); when(update.getReferenceObject()).thenReturn(OTHER_ORG_WITH_ABUSE_C); when(update.getUpdatedObject()).thenReturn(OTHER_ORG_WITHOUT_ABUSE_C); when(updateDao.getReferences(update.getUpdatedObject())).thenReturn(Sets.newHashSet(info)); when(objectDao.getById(info.getObjectId())).thenReturn(RESOURCE_NOT_RS_MAINTAINED); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); verify(maintainers).isRsMaintainer(ciSet("A_NON_RS_MAINTAINER")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void do_not_allow_remove_abuse_contact_when_a_referencing_resource_is_rs_maintained() { final RpslObjectInfo info = new RpslObjectInfo(1, ObjectType.AUT_NUM, "AS6"); when(update.getReferenceObject()).thenReturn(OTHER_ORG_WITH_ABUSE_C); when(update.getUpdatedObject()).thenReturn(OTHER_ORG_WITHOUT_ABUSE_C); when(updateDao.getReferences(update.getUpdatedObject())).thenReturn(Sets.newHashSet(info)); when(objectDao.getById(info.getObjectId())).thenReturn(RESOURCE_RS_MAINTAINED); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.abuseContactNotRemovable()); verify(maintainers).isRsMaintainer(ciSet("AN_RS_MAINTAINER")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }
AbuseValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); if (updatedObject == null) { return; } validateAbuseC(updatedObject, update, updateContext); validateAbuseCRemoved(updatedObject, update, updateContext); } @Autowired AbuseValidator(final RpslObjectDao objectDao, final RpslObjectUpdateDao updateDao, final Maintainers maintainers); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); }