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 transform_inet6num_change() { final RpslObject rpslObject = RpslObject.parse("inet6num: 2001::/8"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.INET6NUM).toString(), is("2000::/8")); verify(objectMessages).addMessage(result.getTypeAttribute(), ValidationMessages.attributeValueConverted("2001::/8", "2000::/8")); 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 getActions() { assertThat(subject.getActions().size(), is(1)); assertTrue(subject.getActions().contains(Action.MODIFY)); }
@Override public ImmutableList<Action> getActions() { return ACTIONS; }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
LirUserMaintainedAttributesValidator 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(); }
LirUserMaintainedAttributesValidator 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)); assertTrue(subject.getTypes().contains(ObjectType.ORGANISATION)); }
@Override public ImmutableList<ObjectType> getTypes() { return TYPES; }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
LirUserMaintainedAttributesValidator 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(); }
LirUserMaintainedAttributesValidator 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_of_non_lir() { when(update.getReferenceObject()).thenReturn(NON_LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(NON_LIR_ORG_CHANGED); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_address() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ADDRESS); subject.validate(update, updateContext); verify(updateContext).getSubject(update); verify(update).getReferenceObject(); verify(update).getUpdatedObject(); verify(updateContext).addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(AttributeType.ADDRESS)); verifyNoMoreInteractions(update); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_phone() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_PHONE); subject.validate(update, updateContext); verify(updateContext).getSubject(update); verify(update).getReferenceObject(); verify(update).getUpdatedObject(); verify(updateContext).addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(AttributeType.PHONE)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_fax() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_FAX); subject.validate(update, updateContext); verify(updateContext).getSubject(update); verify(update).getReferenceObject(); verify(update).getUpdatedObject(); verify(updateContext).addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(AttributeType.FAX_NO)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_email() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_EMAIL); subject.validate(update, updateContext); verify(updateContext).getSubject(update); verify(update).getReferenceObject(); verify(update).getUpdatedObject(); verify(updateContext).addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(AttributeType.E_MAIL)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_org_name() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ORG_NAME); subject.validate(update, updateContext); verify(updateContext).getSubject(update); verify(update).getReferenceObject(); verify(update).getUpdatedObject(); verify(updateContext).addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(AttributeType.ORG_NAME)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_org_name_case_sensitive() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ORG_NAME_CASE_SENSITIVE); subject.validate(update, updateContext); verify(updateContext).getSubject(update); verify(update).getReferenceObject(); verify(update).getUpdatedObject(); verify(updateContext).addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(AttributeType.ORG_NAME)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirUserMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (! isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); USER_MANAGED_IN_PORTAL_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedinLirPortal(attributeType)); } }); } @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, Action.MODIFY)); }
@Override public ImmutableList<Action> getActions() { return ACTIONS; }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
AbuseCNoLimitWarningValidator 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(); }
AbuseCNoLimitWarningValidator 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 transform_nserver_no_not() { final RpslObject rpslObject = RpslObject.parse("" + "domain: 17.45.212.in-addr.arpa\n" + "nserver: hostname.nu\n"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.NSERVER).toString(), is("hostname.nu")); 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 getTypes() { assertThat(subject.getTypes(), containsInAnyOrder(ObjectType.ROLE)); }
@Override public ImmutableList<ObjectType> getTypes() { return TYPES; }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
AbuseCNoLimitWarningValidator 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(); }
AbuseCNoLimitWarningValidator 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 role_has_added_abuse_mailbox_create() { final RpslObject role = RpslObject.parse("role: Some Role\nnic-hdl: TEST-NIC\nabuse-mailbox: [email protected]"); when(update.hasOriginalObject()).thenReturn(false); when(update.getReferenceObject()).thenReturn(role); when(update.getUpdatedObject()).thenReturn(role); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.abuseCNoLimitWarning()); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } } }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } } }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void role_has_added_abuse_mailbox_modify() { when(update.hasOriginalObject()).thenReturn(true); when(update.getReferenceObject()).thenReturn(RpslObject.parse("role: Some Role\nnic-hdl: TEST-NIC")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("role: Some Role\nnic-hdl: TEST-NIC\nabuse-mailbox: [email protected]")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.abuseCNoLimitWarning()); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } } }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } } }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void role_has_not_added_abuse_mailbox() { when(update.hasOriginalObject()).thenReturn(true); when(update.getReferenceObject()).thenReturn(RpslObject.parse("role: Some Role\nnic-hdl: TEST-NIC\nabuse-mailbox: [email protected]")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("role: Some Role\nnic-hdl: TEST-NIC\nabuse-mailbox: [email protected]")); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(update, UpdateMessages.abuseCNoLimitWarning()); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } } }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } } }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AbuseCNoLimitWarningValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getUpdatedObject().containsAttribute(AttributeType.ABUSE_MAILBOX) && (!update.hasOriginalObject() || !update.getReferenceObject().containsAttribute(AttributeType.ABUSE_MAILBOX))) { updateContext.addMessage(update, UpdateMessages.abuseCNoLimitWarning()); } } @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)); assertTrue(subject.getActions().contains(Action.CREATE)); assertTrue(subject.getActions().contains(Action.MODIFY)); }
@Override public ImmutableList<Action> getActions() { return ACTIONS; }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired LirMntByAttributeCountValidator(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().size(), is(1)); assertTrue(subject.getTypes().contains(ObjectType.ORGANISATION)); }
@Override public ImmutableList<ObjectType> getTypes() { return TYPES; }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_not_lir_with_single_mntner() { when(update.getReferenceObject()).thenReturn(NON_LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(NON_LIR_ORG_SINGLE_USER_MNTNER); subject.validate(update, updateContext); verify(update).getReferenceObject(); verifyNoMoreInteractions(update); verifyZeroInteractions(maintainers, updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_not_lir_with_multiple_mntner() { when(update.getReferenceObject()).thenReturn(NON_LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(NON_LIR_ORG_MULTIPLE_USER_MNTNER); subject.validate(update, updateContext); verify(update).getReferenceObject(); verifyNoMoreInteractions(update); verifyZeroInteractions(maintainers, updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_lir_with_single_mntner() { when(maintainers.isRsMaintainer(ciString("MNT1-LIR"))).thenReturn(false); when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_SINGLE_USER_MNTNER); subject.validate(update, updateContext); verify(maintainers).isRsMaintainer(ciString("MNT1-LIR")); verifyNoMoreInteractions(maintainers); verify(update).getReferenceObject(); verify(update).getUpdatedObject(); verifyNoMoreInteractions(update); verifyZeroInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_lir_with_multiple_mntner() { when(maintainers.isRsMaintainer(ciString("MNT1-LIR"))).thenReturn(false); when(maintainers.isRsMaintainer(ciString("MNT2-LIR"))).thenReturn(false); when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_MULTIPLE_USER_MNTNER); subject.validate(update, updateContext); verify(maintainers).isRsMaintainer(ciString("MNT1-LIR")); verify(maintainers).isRsMaintainer(ciString("MNT2-LIR")); verifyNoMoreInteractions(maintainers); verify(update).getReferenceObject(); verify(update).getUpdatedObject(); verify(updateContext).addMessage(update, UpdateMessages.multipleUserMntBy(ImmutableList.of(ciString("MNT1-LIR"), ciString("MNT2-LIR")))); verifyNoMoreInteractions(update); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByAttributeCountValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); final Collection<CIString> userMntner = filterUserMntner(updatedObject); if (userMntner.size() > 1) { updateContext.addMessage(update, UpdateMessages.multipleUserMntBy(userMntner)); } } @Autowired LirMntByAttributeCountValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void transform_nserver_with_dot() { final RpslObject rpslObject = RpslObject.parse("" + "domain: 17.45.212.in-addr.arpa\n" + "nserver: hostname.nu.\n"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.NSERVER).toString(), is("hostname.nu")); verify(objectMessages).addMessage(result.findAttribute(AttributeType.NSERVER), ValidationMessages.attributeValueConverted("hostname.nu.", "hostname.nu")); 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 isExportDir_empty() { assertThat(subject.isExportDir(folder.getRoot()), Matchers.is(true)); }
public boolean isExportDir(final File dir) { final File[] files = dir.listFiles(); if (files == null) { return false; } for (final File file : files) { if (file.isFile()) { return false; } final String fileName = file.getName(); if (! (fileName.equals(externalExportDir) || fileName.equals(internalExportDir) || fileName.equals(legacyExternalExportDir))) { return false; } } return true; }
ExportFileWriterFactory { public boolean isExportDir(final File dir) { final File[] files = dir.listFiles(); if (files == null) { return false; } for (final File file : files) { if (file.isFile()) { return false; } final String fileName = file.getName(); if (! (fileName.equals(externalExportDir) || fileName.equals(internalExportDir) || fileName.equals(legacyExternalExportDir))) { return false; } } return true; } }
ExportFileWriterFactory { public boolean isExportDir(final File dir) { final File[] files = dir.listFiles(); if (files == null) { return false; } for (final File file : files) { if (file.isFile()) { return false; } final String fileName = file.getName(); if (! (fileName.equals(externalExportDir) || fileName.equals(internalExportDir) || fileName.equals(legacyExternalExportDir))) { return false; } } return true; } @Autowired ExportFileWriterFactory(final DummifierNrtm dummifierNrtm, final DummifierCurrent dummifierCurrent, @Value("${dir.rpsl.export.internal}") final String internalExportDir, @Value("${dir.rpsl.export.external}") final String externalExportDir, @Value("${dir.rpsl.export.external.legacy}") final String legacyExternalExportDir, @Value("${whois.source}") final String source, @Value("${whois.nonauth.source}") final String nonAuthSource); }
ExportFileWriterFactory { public boolean isExportDir(final File dir) { final File[] files = dir.listFiles(); if (files == null) { return false; } for (final File file : files) { if (file.isFile()) { return false; } final String fileName = file.getName(); if (! (fileName.equals(externalExportDir) || fileName.equals(internalExportDir) || fileName.equals(legacyExternalExportDir))) { return false; } } return true; } @Autowired ExportFileWriterFactory(final DummifierNrtm dummifierNrtm, final DummifierCurrent dummifierCurrent, @Value("${dir.rpsl.export.internal}") final String internalExportDir, @Value("${dir.rpsl.export.external}") final String externalExportDir, @Value("${dir.rpsl.export.external.legacy}") final String legacyExternalExportDir, @Value("${whois.source}") final String source, @Value("${whois.nonauth.source}") final String nonAuthSource); List<ExportFileWriter> createExportFileWriters(final File baseDir, final int lastSerial); boolean isExportDir(final File dir); }
ExportFileWriterFactory { public boolean isExportDir(final File dir) { final File[] files = dir.listFiles(); if (files == null) { return false; } for (final File file : files) { if (file.isFile()) { return false; } final String fileName = file.getName(); if (! (fileName.equals(externalExportDir) || fileName.equals(internalExportDir) || fileName.equals(legacyExternalExportDir))) { return false; } } return true; } @Autowired ExportFileWriterFactory(final DummifierNrtm dummifierNrtm, final DummifierCurrent dummifierCurrent, @Value("${dir.rpsl.export.internal}") final String internalExportDir, @Value("${dir.rpsl.export.external}") final String externalExportDir, @Value("${dir.rpsl.export.external.legacy}") final String legacyExternalExportDir, @Value("${whois.source}") final String source, @Value("${whois.nonauth.source}") final String nonAuthSource); List<ExportFileWriter> createExportFileWriters(final File baseDir, final int lastSerial); boolean isExportDir(final File dir); }
@Test public void getActions() { assertThat(subject.getActions().size(), is(1)); assertTrue(subject.getActions().contains(Action.MODIFY)); }
@Override public ImmutableList<Action> getActions() { return ACTIONS; }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
LirRipeMaintainedAttributesValidator 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(); }
LirRipeMaintainedAttributesValidator 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)); assertTrue(subject.getTypes().contains(ObjectType.ORGANISATION)); }
@Override public ImmutableList<ObjectType> getTypes() { return TYPES; }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
LirRipeMaintainedAttributesValidator 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(); }
LirRipeMaintainedAttributesValidator 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_of_non_lir() { when(update.getReferenceObject()).thenReturn(NON_LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(NON_LIR_ORG_CHANGED); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_mntby() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_MNT_BY); subject.validate(update, updateContext); verify(updateContext).getSubject(update); verify(update).getReferenceObject(); verify(update).getUpdatedObject(); verify(updateContext).addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_org() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ORG); subject.validate(update, updateContext); verify(updateContext).getSubject(update); verify(update).getReferenceObject(); verify(update).getUpdatedObject(); verify(updateContext).addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.ORG)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_org_type() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ORG_TYPE); subject.validate(update, updateContext); verify(updateContext).getSubject(update); verify(update).getReferenceObject(); verify(update).getUpdatedObject(); verify(updateContext).addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.ORG_TYPE)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_address_with_override() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ADDRESS); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_phone_with_override() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_PHONE); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_fax_with_override() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_FAX); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_email_with_override() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_EMAIL); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void transform_nserver_glue_ipv4() { final RpslObject rpslObject = RpslObject.parse("" + "domain: 17.45.212.in-addr.arpa\n" + "nserver: hostname.nu 10.0.0.0\n"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.NSERVER).toString(), is("hostname.nu 10.0.0.0")); 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 update_of_org_name_with_override() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ORG_NAME); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_mntby_with_override() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_MNT_BY); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_org_with_override() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ORG); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_org_type_with_override() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ORG_TYPE); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_abuse_mailbox_with_override() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(false); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ABUSE_MAILBOX); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_address_with_powermntner() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ADDRESS); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_phone_with_powermntner() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(LIR_ORG_PHONE); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_fax_with_powermntner() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(LIR_ORG_FAX); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_email_with_powermntner() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(LIR_ORG_EMAIL); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_org_name_with_powermntner() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ORG_NAME); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void transform_nserver_glue_ipv4_prefix() { final RpslObject rpslObject = RpslObject.parse("" + "domain: 17.45.212.in-addr.arpa\n" + "nserver: hostname.nu 10.0.0.0/32\n"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.NSERVER).toString(), is("hostname.nu 10.0.0.0")); verify(objectMessages).addMessage(result.findAttribute(AttributeType.NSERVER), ValidationMessages.attributeValueConverted("hostname.nu 10.0.0.0/32", "hostname.nu 10.0.0.0")); 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 update_of_mntby_with_powermntner() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(LIR_ORG_MNT_BY); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_org_with_powermntner() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ORG); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_org_type_with_powermntner() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ORG_TYPE); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void update_of_abuse_mailbox_with_powermntner() { when(update.getReferenceObject()).thenReturn(LIR_ORG); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.ALLOC_MAINTAINER)).thenReturn(true); when(update.getUpdatedObject()).thenReturn(LIR_ORG_ABUSE_MAILBOX); subject.validate(update, updateContext); verify(updateContext).getSubject(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) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirRipeMaintainedAttributesValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.ALLOC_MAINTAINER)) { return; } final RpslObject originalObject = update.getReferenceObject(); if (!isLir(originalObject)) { return; } final RpslObject updatedObject = update.getUpdatedObject(); RIPE_NCC_MANAGED_ATTRIBUTES.forEach(attributeType -> { if (haveAttributesChanged(originalObject, updatedObject, attributeType)) { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(attributeType)); } }); } @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.CREATE, Action.MODIFY)); }
@Override public ImmutableList<Action> getActions() { return ACTIONS; }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @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.INET6NUM)); }
@Override public ImmutableList<ObjectType> getTypes() { return TYPES; }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_no_aggregated_by_lir() { final RpslObject object = RpslObject.parse("" + "inet6num: 2001:0658:021A::/48\n" + "status: ASSIGNED"); when(update.getUpdatedObject()).thenReturn(object); when(update.getAction()).thenReturn(Action.CREATE); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_no_aggregated_by_lir_with_assignment_size() { final RpslObject object = RpslObject.parse("" + "inet6num: 2001:0658:021A::/48\n" + "status: ASSIGNED\n" + "assignment-size: 64"); when(update.getUpdatedObject()).thenReturn(object); when(update.getAction()).thenReturn(Action.CREATE); subject.validate(update, updateContext); verify(updateContext).addMessage(update, object.findAttribute(AttributeType.ASSIGNMENT_SIZE), UpdateMessages.attributeAssignmentSizeNotAllowed()); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_no_aggregated_by_lir_update_with_assignment_size() { final RpslObject referenceObject = RpslObject.parse("" + "inet6num: 2001:0658:021A::/48\n" + "status: ASSIGNED"); final RpslObject updatedObject = RpslObject.parse("" + "inet6num: 2001:0658:021A::/48\n" + "status: ASSIGNED\n" + "assignment-size: 64\n"+ "assignment-size: 32"); when(update.getAction()).thenReturn(Action.MODIFY); when(update.getReferenceObject()).thenReturn(referenceObject); when(update.getUpdatedObject()).thenReturn(updatedObject); subject.validate(update, updateContext); final List<RpslAttribute> assignmentSizeAttributes = updatedObject.findAttributes(AttributeType.ASSIGNMENT_SIZE); verify(updateContext).addMessage(update, assignmentSizeAttributes.get(0), UpdateMessages.attributeAssignmentSizeNotAllowed()); verify(updateContext).addMessage(update, assignmentSizeAttributes.get(1), UpdateMessages.attributeAssignmentSizeNotAllowed()); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_parent_assignment_size() { final RpslObject object = RpslObject.parse("" + "inet6num: 2001:0658:021A::/48\n" + "status: AGGREGATED-BY-LIR\n" + "assignment-size: 64"); final Ipv6Resource key = Ipv6Resource.parse("2001:0658:021A::/48"); final RpslObject parent = RpslObject.parse("" + "inet6num: 2001:0658:021A::/32\n" + "status: AGGREGATED-BY-LIR\n" + "assignment-size: 40"); final Ipv6Entry ipv6Entry = new Ipv6Entry(Ipv6Resource.parse(parent.getKey()), 1); when(update.getAction()).thenReturn(Action.CREATE); when(ipv6Tree.findFirstLessSpecific(key)).thenReturn(Lists.newArrayList(ipv6Entry)); when(rpslObjectDao.getById(1)).thenReturn(parent); when(update.getUpdatedObject()).thenReturn(object); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.invalidPrefixLength(Ipv6Resource.parse(object.getKey()), 40)); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void transform_nserver_glue_ipv6() { final RpslObject rpslObject = RpslObject.parse("" + "domain: 17.45.212.in-addr.arpa\n" + "nserver: hostname.nu FFAA::0\n"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.NSERVER).toString(), is("hostname.nu ffaa::")); verify(objectMessages).addMessage(result.findAttribute(AttributeType.NSERVER), ValidationMessages.attributeValueConverted("hostname.nu FFAA::0", "hostname.nu ffaa::")); 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_aggregatedByLir_in_parent_and_grandparent() { final Ipv6Resource key = Ipv6Resource.parse("2001:0658:021A::/48"); final RpslObject object = RpslObject.parse("" + "inet6num: 2001:0658:021A::/48\n" + "status: AGGREGATED-BY-LIR\n" + "assignment-size: 64"); final RpslObject parent = RpslObject.parse("" + "inet6num: 2001:0658:021A::/32\n" + "status: AGGREGATED-BY-LIR\n" + "assignment-size: 48"); final RpslObject grandParent = RpslObject.parse("" + "inet6num: 2001:0658:021A::/16\n" + "status: AGGREGATED-BY-LIR\n" + "assignment-size: 32"); final Ipv6Entry ipv6EntryParent = new Ipv6Entry(Ipv6Resource.parse(parent.getKey()), 1); final Ipv6Entry ipv6EntryGrandParent = new Ipv6Entry(Ipv6Resource.parse(grandParent.getKey()), 2); when(update.getAction()).thenReturn(Action.CREATE); when(ipv6Tree.findFirstLessSpecific(key)).thenReturn(Lists.newArrayList(ipv6EntryParent)); when(ipv6Tree.findAllLessSpecific(key)).thenReturn(Lists.newArrayList(ipv6EntryParent, ipv6EntryGrandParent)); when(rpslObjectDao.getById(1)).thenReturn(parent); when(rpslObjectDao.getById(2)).thenReturn(grandParent); when(update.getUpdatedObject()).thenReturn(object); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.tooManyAggregatedByLirInHierarchy()); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_aggregatedByLir_in_parent_and_child() { final Ipv6Resource key = Ipv6Resource.parse("2001:0658:021A::/48"); final RpslObject object = RpslObject.parse("" + "inet6num: 2001:0658:021A::/48\n" + "status: AGGREGATED-BY-LIR\n" + "assignment-size: 64"); final RpslObject parent = RpslObject.parse("" + "inet6num: 2001:0658:021A::/32\n" + "status: AGGREGATED-BY-LIR\n" + "assignment-size: 48"); final RpslObject child = RpslObject.parse("" + "inet6num: 2001:0658:021A::/64\n" + "status: AGGREGATED-BY-LIR\n" + "assignment-size: 128"); final Ipv6Entry ipv6EntryParent = new Ipv6Entry(Ipv6Resource.parse(parent.getKey()), 1); final Ipv6Entry ipv6EntryChild = new Ipv6Entry(Ipv6Resource.parse(child.getKey()), 2); when(update.getAction()).thenReturn(Action.CREATE); when(ipv6Tree.findFirstLessSpecific(key)).thenReturn(Lists.newArrayList(ipv6EntryParent)); when(ipv6Tree.findAllLessSpecific(key)).thenReturn(Lists.newArrayList(ipv6EntryParent)); when(ipv6Tree.findFirstMoreSpecific(key)).thenReturn(Lists.newArrayList(ipv6EntryChild)); when(rpslObjectDao.getById(1)).thenReturn(parent); when(rpslObjectDao.getById(2)).thenReturn(child); when(update.getUpdatedObject()).thenReturn(object); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.tooManyAggregatedByLirInHierarchy()); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_aggregatedByLir_in_child_and_grandchild() { final Ipv6Resource key = Ipv6Resource.parse("2001:0658:021A::/48"); final RpslObject object = RpslObject.parse("" + "inet6num: 2001:0658:021A::/48\n" + "status: AGGREGATED-BY-LIR\n" + "assignment-size: 64"); final RpslObject parent = RpslObject.parse("" + "inet6num: 2001:0658:021A::/32\n" + "status: ALLOCATED-BY-RIR"); final RpslObject child = RpslObject.parse("" + "inet6num: 2001:0658:021A::/64\n" + "status: AGGREGATED-BY-LIR\n" + "assignment-size: 68"); final RpslObject grandChild = RpslObject.parse("" + "inet6num: 2001:0658:021A::/68\n" + "status: AGGREGATED-BY-LIR\n" + "assignment-size: 128"); final Ipv6Entry ipv6EntryParent = new Ipv6Entry(Ipv6Resource.parse(parent.getKey()), 1); final Ipv6Entry ipv6EntryChild = new Ipv6Entry(Ipv6Resource.parse(child.getKey()), 2); final Ipv6Entry ipv6EntryGrandChild = new Ipv6Entry(Ipv6Resource.parse(grandChild.getKey()), 3); when(ipv6Tree.findFirstLessSpecific(key)).thenReturn(Lists.newArrayList(ipv6EntryParent)); when(ipv6Tree.findAllLessSpecific(key)).thenReturn(Lists.newArrayList(ipv6EntryParent)); when(ipv6Tree.findFirstMoreSpecific(key)).thenReturn(Lists.newArrayList(ipv6EntryChild)); when(ipv6Tree.findFirstMoreSpecific(ipv6EntryChild.getKey())).thenReturn(Lists.newArrayList(ipv6EntryGrandChild)); when(rpslObjectDao.getById(1)).thenReturn(parent); when(rpslObjectDao.getById(2)).thenReturn(child); when(rpslObjectDao.getById(3)).thenReturn(grandChild); when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(object); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.tooManyAggregatedByLirInHierarchy()); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void validate_child_prefix_length() { final Ipv6Resource key = Ipv6Resource.parse("2001:0658:021A::/48"); final RpslObject object = RpslObject.parse("" + "inet6num: 2001:0658:021A::/48\n" + "status: AGGREGATED-BY-LIR\n" + "assignment-size: 64"); final RpslObject parent = RpslObject.parse("" + "inet6num: 2001:0658:021A::/32\n" + "status: ALLOCATED-BY-RIR"); final RpslObject child = RpslObject.parse("" + "inet6num: 2001:0658:021A::/128\n" + "status: ASSIGNED"); final Ipv6Entry ipv6EntryParent = new Ipv6Entry(Ipv6Resource.parse(parent.getKey()), 1); final Ipv6Entry ipv6EntryChild = new Ipv6Entry(Ipv6Resource.parse(child.getKey()), 2); when(rpslObjectDao.getById(1)).thenReturn(parent); when(rpslObjectDao.getById(2)).thenReturn(child); when(ipv6Tree.findFirstLessSpecific(key)).thenReturn(Lists.newArrayList(ipv6EntryParent)); when(ipv6Tree.findAllLessSpecific(key)).thenReturn(Lists.newArrayList(ipv6EntryParent)); when(ipv6Tree.findFirstMoreSpecific(key)).thenReturn(Lists.newArrayList(ipv6EntryChild)); when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(object); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.invalidChildPrefixLength()); verifyNoMoreInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void modify_assignmentSize_has_not_changed() { when(update.getAction()).thenReturn(Action.MODIFY); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inet6num: ffee::/48\nassignment-size: 48\nstatus:AGGREGATED-BY-LIR")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: ffee::/48\nassignment-size: 48\nstatus:AGGREGATED-BY-LIR")); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void modify_assignmentSize_has_changed() { when(update.getAction()).thenReturn(Action.MODIFY); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inet6num: ffee::/48\nstatus:AGGREGATED-BY-LIR")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: ffee::/48\nassignment-size: 48\nstatus:AGGREGATED-BY-LIR")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.cantChangeAssignmentSize()); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void create_has_assSize_when_it_should_not() { when(update.getAction()).thenReturn(Action.CREATE); final RpslObject rpslObject = RpslObject.parse("inet6num: ffee::/48\nassignment-size: 48\nstatus:ALLOCATED-BY-LIR"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verify(updateContext).addMessage(update, rpslObject.findAttribute(AttributeType.ASSIGNMENT_SIZE), UpdateMessages.attributeAssignmentSizeNotAllowed()); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void create_has_no_assSize_when_it_should_not() { when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: ffee::/48\nstatus:ALLOCATED-BY-LIR")); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void create_succeeds() { when(update.getAction()).thenReturn(Action.CREATE); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inet6num: ffee::/48\nstatus:ASSIGNED")); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
AggregatedByLirStatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction()== CREATE) { validateCreate(update, updateContext); } else { validateModify(update, updateContext); } } @Autowired AggregatedByLirStatusValidator(final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @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(CREATE, MODIFY)); }
@Override public ImmutableList<Action> getActions() { return ACTIONS; }
SponsoringOrgValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
SponsoringOrgValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired SponsoringOrgValidator(final RpslObjectDao objectDao, final Maintainers maintainers); }
SponsoringOrgValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired SponsoringOrgValidator(final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SponsoringOrgValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired SponsoringOrgValidator(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_route_no_change() { final RpslObject rpslObject = RpslObject.parse("" + "route: 212.166.64.0/19\n" + "origin: AS12321"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.ROUTE).toString(), is("212.166.64.0/19")); 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 getTypes() { assertThat(subject.getTypes(), containsInAnyOrder(INETNUM, INET6NUM, AUT_NUM)); }
@Override public ImmutableList<ObjectType> getTypes() { return TYPES; }
SponsoringOrgValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
SponsoringOrgValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired SponsoringOrgValidator(final RpslObjectDao objectDao, final Maintainers maintainers); }
SponsoringOrgValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired SponsoringOrgValidator(final RpslObjectDao objectDao, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
SponsoringOrgValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired SponsoringOrgValidator(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 delete_inetnum_w_legacy_not_allowed_under_unspecified_w_non_rs_maintainer() { when(update.getAction()).thenReturn(Action.DELETE); when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.newArrayList(new Ipv4Entry(Ipv4Resource.parse("0/0"), 1))); when(objectDao.getById(1)).thenReturn(RpslObject.parse("" + "inetnum: 0.0.0.0 - 255.255.255.255\n" + "status: ALLOCATED UNSPECIFIED")); when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("" + "inetnum: 192.0/24\n" + "status: LEGACY\n" + "mnt-by: TEST-MNT\n" + "password: update")); subject.validate(update, updateContext); verify(updateContext, times(1)).addMessage(update, UpdateMessages.inetnumStatusLegacy()); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction() == DELETE) { if (update.getType().equals(INETNUM)) { validateDelete(update, updateContext, ipv4Tree); } else { validateDelete(update, updateContext, ipv6Tree); } } else { validateModify(update, updateContext); } }
StatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction() == DELETE) { if (update.getType().equals(INETNUM)) { validateDelete(update, updateContext, ipv4Tree); } else { validateDelete(update, updateContext, ipv6Tree); } } else { validateModify(update, updateContext); } } }
StatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction() == DELETE) { if (update.getType().equals(INETNUM)) { validateDelete(update, updateContext, ipv4Tree); } else { validateDelete(update, updateContext, ipv6Tree); } } else { validateModify(update, updateContext); } } @Autowired StatusValidator( final RpslObjectDao objectDao, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final Maintainers maintainers); }
StatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction() == DELETE) { if (update.getType().equals(INETNUM)) { validateDelete(update, updateContext, ipv4Tree); } else { validateDelete(update, updateContext, ipv6Tree); } } else { validateModify(update, updateContext); } } @Autowired StatusValidator( final RpslObjectDao objectDao, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
StatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction() == DELETE) { if (update.getType().equals(INETNUM)) { validateDelete(update, updateContext, ipv4Tree); } else { validateDelete(update, updateContext, ipv6Tree); } } else { validateModify(update, updateContext); } } @Autowired StatusValidator( final RpslObjectDao objectDao, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void modify_status_change() { when(update.getAction()).thenReturn(Action.MODIFY); when(update.getReferenceObject()).thenReturn(RpslObject.parse("" + "inetnum: 192.0/24\n" + "status: ASSIGNED PI")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("" + "inetnum: 192.0/24\n" + "status: ASSIGNED PA")); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.statusChange()); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction() == DELETE) { if (update.getType().equals(INETNUM)) { validateDelete(update, updateContext, ipv4Tree); } else { validateDelete(update, updateContext, ipv6Tree); } } else { validateModify(update, updateContext); } }
StatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction() == DELETE) { if (update.getType().equals(INETNUM)) { validateDelete(update, updateContext, ipv4Tree); } else { validateDelete(update, updateContext, ipv6Tree); } } else { validateModify(update, updateContext); } } }
StatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction() == DELETE) { if (update.getType().equals(INETNUM)) { validateDelete(update, updateContext, ipv4Tree); } else { validateDelete(update, updateContext, ipv6Tree); } } else { validateModify(update, updateContext); } } @Autowired StatusValidator( final RpslObjectDao objectDao, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final Maintainers maintainers); }
StatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction() == DELETE) { if (update.getType().equals(INETNUM)) { validateDelete(update, updateContext, ipv4Tree); } else { validateDelete(update, updateContext, ipv6Tree); } } else { validateModify(update, updateContext); } } @Autowired StatusValidator( final RpslObjectDao objectDao, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
StatusValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { if (update.getAction() == DELETE) { if (update.getType().equals(INETNUM)) { validateDelete(update, updateContext, ipv4Tree); } else { validateDelete(update, updateContext, ipv6Tree); } } else { validateModify(update, updateContext); } } @Autowired StatusValidator( final RpslObjectDao objectDao, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void is_inside_range() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum:192.0.0.0 - 192.0.255.255\n" + "mnt-routes: DEV-MNT {192.0.0.0/24}"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void is_inside_range_ipv6() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum:2a00:c00::/32\n" + "mnt-routes: QSC-NOC {2a00:c00::/48}"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void is_inside_range_multiple() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum:192.0.0.0 - 192.0.255.255\n" + "mnt-routes: DEV-MNT1 {192.0.0.0/24}\n" + "mnt-routes: DEV-MNT2 {192.0.0.0/32}"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void is_inside_range_multiple_ipv6() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum:2a00:c00::/32\n" + "mnt-routes: QSC-NOC {2a00:c00::/48}\n" + "mnt-routes: QSC-NOC {2a00:c00::/64}"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void any_range() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum:192.0.0.0 - 192.0.255.255\n" + "mnt-routes: DEV-MNT ANY"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void any_range_ipv6() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum:2a00:c00::/32\n" + "mnt-routes: DEV-MNT ANY"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verifyZeroInteractions(updateContext); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void ipv6_range_with_ipv4() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum:192.0.0.0 - 192.0.255.255\n" + "mnt-routes: DEV-MNT {::0/128^+}"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verify(updateContext).addMessage(any(PreparedUpdate.class), eq(rpslObject.findAttribute(AttributeType.MNT_ROUTES)), eq(UpdateMessages.invalidIpv4Address("::/128"))); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void transform_route_leading_zeroes() { final RpslObject rpslObject = RpslObject.parse("" + "route: 212.166.064.000/19\n" + "origin: AS12321"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.ROUTE).toString(), is("212.166.64.0/19")); verify(objectMessages).addMessage(result.getTypeAttribute(), ValidationMessages.attributeValueConverted("212.166.064.000/19", "212.166.64.0/19")); 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 ipv4_range_with_ipv6() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum:2a00:c00::/32\n" + "mnt-routes: DEV-MNT {192.0.0.0/24}"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verify(updateContext).addMessage(any(PreparedUpdate.class), eq(rpslObject.findAttribute(AttributeType.MNT_ROUTES)), eq(UpdateMessages.invalidIpv6Address("192.0.0.0/24"))); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void is_outside_range() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum:192.0.0.0 - 192.0.0.255\n" + "mnt-routes: DEV-MNT {192.0.0.0/16}"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verify(updateContext).addMessage(any(PreparedUpdate.class), eq(rpslObject.findAttribute(AttributeType.MNT_ROUTES)), eq(UpdateMessages.invalidRouteRange("192.0.0.0/16"))); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void is_outside_range_ipv6() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum:2a00:c00::/32\n" + "mnt-routes: DEV-MNT {2a00:c00::/16}"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verify(updateContext).addMessage(any(PreparedUpdate.class), eq(rpslObject.findAttribute(AttributeType.MNT_ROUTES)), eq(UpdateMessages.invalidRouteRange("2a00:c00::/16"))); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void is_outside_range_multiple() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum:192.0.0.0 - 192.0.0.255\n" + "mnt-routes: DEV-MNT {192.0.0.0/16,192.0.0.0/8}"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verify(updateContext).addMessage(any(PreparedUpdate.class), eq(rpslObject.findAttribute(AttributeType.MNT_ROUTES)), eq(UpdateMessages.invalidRouteRange("192.0.0.0/16"))); verify(updateContext).addMessage(any(PreparedUpdate.class), eq(rpslObject.findAttribute(AttributeType.MNT_ROUTES)), eq(UpdateMessages.invalidRouteRange("192.0.0.0/8"))); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void is_outside_range_multiple_ipv6() { final RpslObject rpslObject = RpslObject.parse("" + "inetnum:2a00:c00::/32\n" + "mnt-routes: DEV-MNT {2a00:c00::/24,2a00:c00::/16}"); when(update.getUpdatedObject()).thenReturn(rpslObject); subject.validate(update, updateContext); verify(updateContext).addMessage(any(PreparedUpdate.class), eq(rpslObject.findAttribute(AttributeType.MNT_ROUTES)), eq(UpdateMessages.invalidRouteRange("2a00:c00::/24"))); verify(updateContext).addMessage(any(PreparedUpdate.class), eq(rpslObject.findAttribute(AttributeType.MNT_ROUTES)), eq(UpdateMessages.invalidRouteRange("2a00:c00::/16"))); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final IpInterval<?> ipInterval = IpInterval.parse(updatedObject.getKey()); for (final RpslAttribute attribute : updatedObject.findAttributes(AttributeType.MNT_ROUTES)) { final MntRoutes mntRoutes = MntRoutes.parse(attribute.getCleanValue()); if (mntRoutes.isAnyRange()) { return; } for (final AddressPrefixRange addressPrefixRange : mntRoutes.getAddressPrefixRanges()) { final AddressPrefixRange.BoundaryCheckResult boundaryCheckResult = addressPrefixRange.checkWithinBounds(ipInterval); switch (boundaryCheckResult) { case IPV4_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv6Address(addressPrefixRange.getIpInterval().toString())); break; case IPV6_EXPECTED: updateContext.addMessage(update, attribute, UpdateMessages.invalidIpv4Address(addressPrefixRange.getIpInterval().toString())); break; case NOT_IN_BOUNDS: updateContext.addMessage(update, attribute, UpdateMessages.invalidRouteRange(addressPrefixRange.toString())); break; default: break; } } } } @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void supports() { final List<ObjectType> supportedTypes = subject.getTypes(); assertThat(supportedTypes, containsInAnyOrder(ObjectType.INETNUM, ObjectType.INET6NUM)); }
@Override public ImmutableList<ObjectType> getTypes() { return TYPES; }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
MntRouteRangeValidator 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(); }
MntRouteRangeValidator 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 supports_actions_create_modify() { final List<Action> actions = subject.getActions(); assertThat(actions.size(), is(2)); assertThat(actions.contains(Action.CREATE), is(true)); assertThat(actions.contains(Action.MODIFY), is(true)); }
@Override public ImmutableList<Action> getActions() { return ACTIONS; }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
MntRouteRangeValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
MntRouteRangeValidator 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(); }
MntRouteRangeValidator 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 getActions() { assertThat(subject.getActions(), contains(Action.MODIFY)); }
@Override public ImmutableList<Action> getActions() { return ACTIONS; }
LirMntByValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } }
LirMntByValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired LirMntByValidator(final Maintainers maintainers); }
LirMntByValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByValidator implements BusinessRuleValidator { @Override public ImmutableList<Action> getActions() { return ACTIONS; } @Autowired LirMntByValidator(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(), containsInAnyOrder(ObjectType.INETNUM, ObjectType.INET6NUM)); }
@Override public ImmutableList<ObjectType> getTypes() { return TYPES; }
LirMntByValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } }
LirMntByValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired LirMntByValidator(final Maintainers maintainers); }
LirMntByValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByValidator implements BusinessRuleValidator { @Override public ImmutableList<ObjectType> getTypes() { return TYPES; } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void modify_mntby_on_inetnum_with_lir() { final RpslObject rpslOriginalObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT"); final RpslObject rpslUpdatedlObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST2-MNT"); when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(update.getReferenceObject()).thenReturn(rpslOriginalObject); when(update.getUpdatedObject()).thenReturn(rpslUpdatedlObject); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void transform_route_short_prefix() { final RpslObject rpslObject = RpslObject.parse("" + "route: 15/8\n" + "origin: AS12321"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.ROUTE).toString(), is("15.0.0.0/8")); verify(objectMessages).addMessage(result.getTypeAttribute(), ValidationMessages.attributeValueConverted("15/8", "15.0.0.0/8")); 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 modify_mntby_on_inetnum_with_rs() { final RpslObject rpslOriginalObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT"); final RpslObject rpslUpdatedlObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST2-MNT"); when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(true); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(update.getReferenceObject()).thenReturn(rpslOriginalObject); when(update.getUpdatedObject()).thenReturn(rpslUpdatedlObject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void modify_mntby_on_inetnum_with_override() { final RpslObject rpslOriginalObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT"); final RpslObject rpslUpdatedlObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST2-MNT"); when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getReferenceObject()).thenReturn(rpslOriginalObject); when(update.getUpdatedObject()).thenReturn(rpslUpdatedlObject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void mntby_unchanged() { final RpslObject rpslOriginalObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT"); final RpslObject rpslUpdatedlObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT"); when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(update.getReferenceObject()).thenReturn(rpslOriginalObject); when(update.getUpdatedObject()).thenReturn(rpslUpdatedlObject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void modify_mntby_remove_rs_mntner_on_inetnum_with_lir() { final RpslObject rpslOriginalObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT"); final RpslObject rpslUpdatedlObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: TEST-MNT"); when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(update.getReferenceObject()).thenReturn(rpslOriginalObject); when(update.getUpdatedObject()).thenReturn(rpslUpdatedlObject); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void modify_mntby_remove_own_mntner_on_inetnum_with_lir() { final RpslObject rpslOriginalObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT"); final RpslObject rpslUpdatedlObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n"); when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(update.getReferenceObject()).thenReturn(rpslOriginalObject); when(update.getUpdatedObject()).thenReturn(rpslUpdatedlObject); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void modify_mntby_multiple_on_inetnum_with_lir() { final RpslObject rpslOriginalObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n" + "mnt-by: TEST2-MNT"); final RpslObject rpslUpdatedlObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST4-MNT"); when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(update.getReferenceObject()).thenReturn(rpslOriginalObject); when(update.getUpdatedObject()).thenReturn(rpslUpdatedlObject); subject.validate(update, updateContext); verify(updateContext).addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT", "TEST2-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void modify_mntby_add_lir_mntner_on_inetnum_with_rs() { final RpslObject rpslOriginalObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n"); final RpslObject rpslUpdatedlObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n"); when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(true); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(update.getReferenceObject()).thenReturn(rpslOriginalObject); when(update.getUpdatedObject()).thenReturn(rpslUpdatedlObject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void modify_mntby_add_lir_mntner_on_inetnum_with_override() { final RpslObject rpslOriginalObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n"); final RpslObject rpslUpdatedlObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n"); when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getReferenceObject()).thenReturn(rpslOriginalObject); when(update.getUpdatedObject()).thenReturn(rpslUpdatedlObject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void modify_mntby_delete_lir_mntner_on_inetnum_with_rs() { final RpslObject rpslOriginalObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n"); final RpslObject rpslUpdatedlObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n"); when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(true); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(false); when(update.getReferenceObject()).thenReturn(rpslOriginalObject); when(update.getUpdatedObject()).thenReturn(rpslUpdatedlObject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
@Test public void modify_mntby_delete_lir_mntner_on_inetnum_with_override() { final RpslObject rpslOriginalObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n" + "mnt-by: TEST-MNT\n"); final RpslObject rpslUpdatedlObject = RpslObject.parse("" + "inetnum: 192.168.0.0 - 192.169.255.255\n" + "status: ALLOCATED PA\n" + "mnt-by: RIPE-NCC-HM-MNT\n"); when(authenticationSubject.hasPrincipal(Principal.RS_MAINTAINER)).thenReturn(false); when(authenticationSubject.hasPrincipal(Principal.OVERRIDE_MAINTAINER)).thenReturn(true); when(update.getReferenceObject()).thenReturn(rpslOriginalObject); when(update.getUpdatedObject()).thenReturn(rpslUpdatedlObject); subject.validate(update, updateContext); verify(updateContext, never()).addMessage(Matchers.<Update>anyObject(), Matchers.<Message>anyObject()); verify(maintainers).isRsMaintainer(ciSet("RIPE-NCC-HM-MNT", "TEST-MNT")); verifyNoMoreInteractions(maintainers); }
@Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }
LirMntByValidator implements BusinessRuleValidator { @Override public void validate(final PreparedUpdate update, final UpdateContext updateContext) { final Subject subject = updateContext.getSubject(update); final RpslObject originalObject = update.getReferenceObject(); final RpslObject updatedObject = update.getUpdatedObject(); final boolean rsMaintained = maintainers.isRsMaintainer(originalObject.getValuesForAttribute(AttributeType.MNT_BY)); if (mntByChanged(originalObject, updatedObject) && rsMaintained && isAllocation(originalObject)) { if (subject.hasPrincipal(Principal.OVERRIDE_MAINTAINER) || subject.hasPrincipal(Principal.RS_MAINTAINER)) { return; } else { updateContext.addMessage(update, UpdateMessages.canOnlyBeChangedByRipeNCC(AttributeType.MNT_BY)); } } } @Autowired LirMntByValidator(final Maintainers maintainers); @Override void validate(final PreparedUpdate update, final UpdateContext updateContext); @Override ImmutableList<Action> getActions(); @Override ImmutableList<ObjectType> getTypes(); }