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 authenticate_modify_original_object_has_no_mntby_delete() { final RpslObject original = RpslObject.parse("person: Mr Hubbard\nnic-hdl: TEST-NIC"); final RpslObject updated = RpslObject.parse("person: Mr Hubbard\nnic-hdl: TEST-NIC\nmnt-by: TEST-MNT"); when(update.getAction()).thenReturn(Action.DELETE); when(update.getReferenceObject()).thenReturn(original); when(update.getUpdatedObject()).thenReturn(updated); when(update.getType()).thenReturn(ObjectType.PERSON); verifyZeroInteractions(rpslObjectDao, credentialValidators); final List<RpslObject> authenticate = subject.authenticate(update, updateContext); assertThat(authenticate, hasSize(0)); verifyZeroInteractions(maintainers); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { try { return authenticateMntBy(update, updateContext); } catch (AuthenticationFailedException e) { return authenticateByAddressSpaceHolder(update, updateContext, e); } }
MntByAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { try { return authenticateMntBy(update, updateContext); } catch (AuthenticationFailedException e) { return authenticateByAddressSpaceHolder(update, updateContext, e); } } }
MntByAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { try { return authenticateMntBy(update, updateContext); } catch (AuthenticationFailedException e) { return authenticateByAddressSpaceHolder(update, updateContext, e); } } @Autowired MntByAuthentication(final Maintainers maintainers, final AuthenticationModule authenticationModule, final RpslObjectDao rpslObjectDao, final SsoTranslator ssoTranslator, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); }
MntByAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { try { return authenticateMntBy(update, updateContext); } catch (AuthenticationFailedException e) { return authenticateByAddressSpaceHolder(update, updateContext, e); } } @Autowired MntByAuthentication(final Maintainers maintainers, final AuthenticationModule authenticationModule, final RpslObjectDao rpslObjectDao, final SsoTranslator ssoTranslator, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
MntByAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { try { return authenticateMntBy(update, updateContext); } catch (AuthenticationFailedException e) { return authenticateByAddressSpaceHolder(update, updateContext, e); } } @Autowired MntByAuthentication(final Maintainers maintainers, final AuthenticationModule authenticationModule, final RpslObjectDao rpslObjectDao, final SsoTranslator ssoTranslator, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void authenticate_mnt_by_fails_delete_with_rs_maintainer() { final RpslObject inetnum = RpslObject.parse("" + "inetnum: 193.0.0.0\n" + "mnt-by: DEV1-MNT\n" + "mnt-by: RS-MNT\n"); when(update.getAction()).thenReturn(Action.DELETE); when(update.getReferenceObject()).thenReturn(inetnum); when(update.getUpdatedObject()).thenReturn(inetnum); when(update.getType()).thenReturn(inetnum.getType()); final RpslObject maintainer = RpslObject.parse("mntner: DEV1-MNT\n"); final ArrayList<RpslObject> mntByCandidates = Lists.newArrayList(maintainer); when(rpslObjectDao.getByKeys(ObjectType.MNTNER, ciSet("DEV1-MNT", "RS-MNT"))).thenReturn(mntByCandidates); when(credentialValidators.authenticate(update, updateContext, mntByCandidates)).thenReturn(Lists.<RpslObject>newArrayList()); try { subject.authenticate(update, updateContext); fail("Expected exception"); } catch (AuthenticationFailedException e) { assertThat(e.getAuthenticationMessages(), contains(UpdateMessages.authenticationFailed(inetnum, AttributeType.MNT_BY, Lists.newArrayList(maintainer)))); } verifyZeroInteractions(maintainers); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { try { return authenticateMntBy(update, updateContext); } catch (AuthenticationFailedException e) { return authenticateByAddressSpaceHolder(update, updateContext, e); } }
MntByAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { try { return authenticateMntBy(update, updateContext); } catch (AuthenticationFailedException e) { return authenticateByAddressSpaceHolder(update, updateContext, e); } } }
MntByAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { try { return authenticateMntBy(update, updateContext); } catch (AuthenticationFailedException e) { return authenticateByAddressSpaceHolder(update, updateContext, e); } } @Autowired MntByAuthentication(final Maintainers maintainers, final AuthenticationModule authenticationModule, final RpslObjectDao rpslObjectDao, final SsoTranslator ssoTranslator, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); }
MntByAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { try { return authenticateMntBy(update, updateContext); } catch (AuthenticationFailedException e) { return authenticateByAddressSpaceHolder(update, updateContext, e); } } @Autowired MntByAuthentication(final Maintainers maintainers, final AuthenticationModule authenticationModule, final RpslObjectDao rpslObjectDao, final SsoTranslator ssoTranslator, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
MntByAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { try { return authenticateMntBy(update, updateContext); } catch (AuthenticationFailedException e) { return authenticateByAddressSpaceHolder(update, updateContext, e); } } @Autowired MntByAuthentication(final Maintainers maintainers, final AuthenticationModule authenticationModule, final RpslObjectDao rpslObjectDao, final SsoTranslator ssoTranslator, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void exact_match_route_without_mntRoutes_succeeds() { final RpslObject existingRoute = RpslObject.parse("" + "route: 192.91.244.0/23\n" + "origin: AS12\n" + "mnt-by: TEST-MNT"); final Ipv4Resource existingRouteResource = Ipv4Resource.parse(existingRoute.getTypeAttribute().getCleanValue()); final Ipv4RouteEntry existingRouteEntry = new Ipv4RouteEntry(existingRouteResource, 1, "AS12"); when(routeTree.findExactOrFirstLessSpecific(routeResource)).thenReturn(Lists.newArrayList(existingRouteEntry)); when(objectDao.getById(1)).thenReturn(existingRoute); final RpslObject maintainer = RpslObject.parse("mntner: TEST-MNT\n"); final ArrayList<RpslObject> candidates = Lists.newArrayList(maintainer); when(objectDao.getByKeys(ObjectType.MNTNER, ciSet("TEST-MNT"))).thenReturn(candidates); when(authenticationModule.authenticate(update, updateContext, candidates)).thenReturn(candidates); final List<RpslObject> authenticatedMaintainers = subject.authenticate(update, updateContext); assertThat(authenticatedMaintainers, contains(maintainer)); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void exact_match_route_without_mntRoutes_fails() { final RpslObject existingRoute = RpslObject.parse("" + "route: 192.91.244.0/23\n" + "origin: AS12\n" + "mnt-by: TEST-MNT"); final Ipv4Resource existingRouteResource = Ipv4Resource.parse(existingRoute.getTypeAttribute().getCleanValue()); final Ipv4RouteEntry existingRouteEntry = new Ipv4RouteEntry(existingRouteResource, 1, "AS12"); when(routeTree.findExactOrFirstLessSpecific(routeResource)).thenReturn(Lists.newArrayList(existingRouteEntry)); when(objectDao.getById(1)).thenReturn(existingRoute); final RpslObject maintainer = RpslObject.parse("mntner: TEST-MNT\n"); final ArrayList<RpslObject> candidates = Lists.newArrayList(maintainer); when(objectDao.getByKeys(ObjectType.MNTNER, ciSet("TEST-MNT"))).thenReturn(candidates); when(authenticationModule.authenticate(update, updateContext, candidates)).thenReturn(Collections.<RpslObject>emptyList()); try { subject.authenticate(update, updateContext); fail("Expected authentication exception"); } catch (AuthenticationFailedException e) { assertThat(e.getAuthenticationMessages(), contains(UpdateMessages.authenticationFailed(existingRoute, AttributeType.MNT_BY, candidates))); } }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void exact_match_route_with_mntRoutes_succeeds() { final RpslObject existingRoute = RpslObject.parse("" + "route: 192.91.244.0/23\n" + "origin: AS12\n" + "mnt-routes: ROUTES-MNT\n" + "mnt-by: TEST-MNT"); final Ipv4Resource existingRouteResource = Ipv4Resource.parse(existingRoute.getTypeAttribute().getCleanValue()); final Ipv4RouteEntry existingRouteEntry = new Ipv4RouteEntry(existingRouteResource, 1, "AS12"); when(routeTree.findExactOrFirstLessSpecific(routeResource)).thenReturn(Lists.newArrayList(existingRouteEntry)); when(objectDao.getById(1)).thenReturn(existingRoute); final RpslObject maintainer = RpslObject.parse("mntner: ROUTES-MNT\n"); final ArrayList<RpslObject> candidates = Lists.newArrayList(maintainer); when(objectDao.getByKeys(ObjectType.MNTNER, ciSet("ROUTES-MNT"))).thenReturn(candidates); when(authenticationModule.authenticate(update, updateContext, candidates)).thenReturn(candidates); final List<RpslObject> authenticatedMaintainers = subject.authenticate(update, updateContext); assertThat(authenticatedMaintainers, contains(maintainer)); verify(objectDao, never()).getByKeys(ObjectType.MNTNER, ciSet("TEST-MNT")); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void exact_match_route_with_mntRoutes_fails() { final RpslObject existingRoute = RpslObject.parse("" + "route: 192.91.244.0/23\n" + "origin: AS12\n" + "mnt-routes: ROUTES-MNT\n" + "mnt-by: TEST-MNT"); final Ipv4Resource existingRouteResource = Ipv4Resource.parse(existingRoute.getTypeAttribute().getCleanValue()); final Ipv4RouteEntry existingRouteEntry = new Ipv4RouteEntry(existingRouteResource, 1, "AS12"); when(routeTree.findExactOrFirstLessSpecific(routeResource)).thenReturn(Lists.newArrayList(existingRouteEntry)); when(objectDao.getById(1)).thenReturn(existingRoute); final RpslObject maintainer = RpslObject.parse("mntner: ROUTES-MNT\n"); final ArrayList<RpslObject> candidates = Lists.newArrayList(maintainer); when(objectDao.getByKeys(ObjectType.MNTNER, ciSet("ROUTES-MNT"))).thenReturn(candidates); when(authenticationModule.authenticate(update, updateContext, candidates)).thenReturn(Collections.<RpslObject>emptyList()); try { subject.authenticate(update, updateContext); fail("Expected authentication exception"); } catch (AuthenticationFailedException e) { assertThat(e.getAuthenticationMessages(), contains(UpdateMessages.authenticationFailed(existingRoute, AttributeType.MNT_ROUTES, candidates))); } }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void transform_keys_domain_with_trailing_dot() { final RpslObject rpslObject = RpslObject.parse("domain: 17.45.212.in-addr.arpa."); final CIString result = attributeSanitizer.sanitizeKey(rpslObject); assertThat(result.toString(), is("17.45.212.in-addr.arpa")); }
public CIString sanitizeKey(final RpslObject originalObject) { final List<RpslAttribute> keyRelatedAttributes = getKeyRelatedAttributes(originalObject); return new RpslObject(sanitizeKeyAttributes(keyRelatedAttributes)).getKey(); }
AttributeSanitizer { public CIString sanitizeKey(final RpslObject originalObject) { final List<RpslAttribute> keyRelatedAttributes = getKeyRelatedAttributes(originalObject); return new RpslObject(sanitizeKeyAttributes(keyRelatedAttributes)).getKey(); } }
AttributeSanitizer { public CIString sanitizeKey(final RpslObject originalObject) { final List<RpslAttribute> keyRelatedAttributes = getKeyRelatedAttributes(originalObject); return new RpslObject(sanitizeKeyAttributes(keyRelatedAttributes)).getKey(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); }
AttributeSanitizer { public CIString sanitizeKey(final RpslObject originalObject) { final List<RpslAttribute> keyRelatedAttributes = getKeyRelatedAttributes(originalObject); return new RpslObject(sanitizeKeyAttributes(keyRelatedAttributes)).getKey(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
AttributeSanitizer { public CIString sanitizeKey(final RpslObject originalObject) { final List<RpslAttribute> keyRelatedAttributes = getKeyRelatedAttributes(originalObject); return new RpslObject(sanitizeKeyAttributes(keyRelatedAttributes)).getKey(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
@Test public void less_specific_match_route_with_mntRoutes_fails() { final RpslObject existingRoute = RpslObject.parse("" + "route: 192.91/16\n" + "origin: AS12\n" + "mnt-lower: LOWER-MNT\n" + "mnt-by: TEST-MNT"); final Ipv4Resource existingRouteResource = Ipv4Resource.parse(existingRoute.getTypeAttribute().getCleanValue()); final Ipv4RouteEntry existingRouteEntry = new Ipv4RouteEntry(existingRouteResource, 1, "AS12"); when(routeTree.findExactOrFirstLessSpecific(routeResource)).thenReturn(Lists.newArrayList(existingRouteEntry)); when(objectDao.getById(1)).thenReturn(existingRoute); final RpslObject maintainer = RpslObject.parse("mntner: LOWER-MNT\n"); final ArrayList<RpslObject> candidates = Lists.newArrayList(maintainer); when(objectDao.getByKeys(ObjectType.MNTNER, ciSet("LOWER-MNT"))).thenReturn(candidates); when(authenticationModule.authenticate(update, updateContext, candidates)).thenReturn(Collections.<RpslObject>emptyList()); try { subject.authenticate(update, updateContext); fail("Expected authentication exception"); } catch (AuthenticationFailedException e) { assertThat(e.getAuthenticationMessages(), contains(UpdateMessages.authenticationFailed(existingRoute, AttributeType.MNT_LOWER, candidates))); } }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void less_specific_match_inetnum_with_mntRoutes_fails() { final RpslObject existingRoute = RpslObject.parse("" + "route: 192.91/16\n" + "origin: AS12\n" + "mnt-lower: LOWER-MNT\n" + "mnt-by: TEST-MNT"); final Ipv4Resource existingRouteResource = Ipv4Resource.parse(existingRoute.getTypeAttribute().getCleanValue()); when(routeTree.findExactOrFirstLessSpecific(routeResource)).thenReturn(Collections.<Ipv4RouteEntry>emptyList()); when(ipv4Tree.findExactOrFirstLessSpecific(routeResource)).thenReturn(Lists.newArrayList(new Ipv4Entry(existingRouteResource, 1))); when(objectDao.getById(1)).thenReturn(existingRoute); final RpslObject maintainer = RpslObject.parse("mntner: LOWER-MNT\n"); final ArrayList<RpslObject> candidates = Lists.newArrayList(maintainer); when(objectDao.getByKeys(ObjectType.MNTNER, ciSet("LOWER-MNT"))).thenReturn(candidates); when(authenticationModule.authenticate(update, updateContext, candidates)).thenReturn(Collections.<RpslObject>emptyList()); try { subject.authenticate(update, updateContext); fail("Expected authentication exception"); } catch (AuthenticationFailedException e) { assertThat(e.getAuthenticationMessages(), contains(UpdateMessages.authenticationFailed(existingRoute, AttributeType.MNT_LOWER, candidates))); } }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void no_match_ipObject() { when(routeTree.findExactOrFirstLessSpecific(routeResource)).thenReturn(Collections.<Ipv4RouteEntry>emptyList()); when(ipv4Tree.findExactOrFirstLessSpecific(routeResource)).thenReturn(Collections.<Ipv4Entry>emptyList()); when(authenticationModule.authenticate(eq(update), eq(updateContext), anyListOf(RpslObject.class))).thenReturn(Collections.<RpslObject>emptyList()); try { subject.authenticate(update, updateContext); fail("Expected authentication exception"); } catch (AuthenticationFailedException e) { assertThat(e.getAuthenticationMessages(), contains(UpdateMessages.authenticationFailed(routeObject, AttributeType.ROUTE, Collections.<RpslObject>emptyList()))); } }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void less_specific_match_route6_without_mntRoutes_fails() { final RpslObject route6Object = RpslObject.parse("" + "route6: acac::0/32\n" + "origin: AS12\n" + "mnt-routes: ROUTE-MNT"); final Ipv6Resource route6Resource = Ipv6Resource.parse(route6Object.getTypeAttribute().getCleanValue()); when(update.getUpdatedObject()).thenReturn(route6Object); final RpslObject existingRoute = RpslObject.parse("" + "route6: acac::0/16\n" + "origin: AS12\n" + "mnt-lower: LOWER-MNT\n" + "mnt-by: TEST-MNT"); final Ipv6Resource existingRouteResource = Ipv6Resource.parse(existingRoute.getTypeAttribute().getCleanValue()); final Ipv6RouteEntry existingRouteEntry = new Ipv6RouteEntry(existingRouteResource, 1, "AS12"); when(route6Tree.findExactOrFirstLessSpecific(route6Resource)).thenReturn(Lists.newArrayList(existingRouteEntry)); when(objectDao.getById(1)).thenReturn(existingRoute); final RpslObject maintainer = RpslObject.parse("mntner: LOWER-MNT\n"); final ArrayList<RpslObject> candidates = Lists.newArrayList(maintainer); when(objectDao.getByKeys(ObjectType.MNTNER, ciSet("LOWER-MNT"))).thenReturn(candidates); when(authenticationModule.authenticate(update, updateContext, candidates)).thenReturn(Collections.<RpslObject>emptyList()); try { subject.authenticate(update, updateContext); fail("Expected authentication exception"); } catch (AuthenticationFailedException e) { assertThat(e.getAuthenticationMessages(), contains(UpdateMessages.authenticationFailed(existingRoute, AttributeType.MNT_LOWER, candidates))); } }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
RouteIpAddressAuthentication extends RouteAuthentication { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject updatedObject = update.getUpdatedObject(); final RpslAttribute typeAttribute = updatedObject.getTypeAttribute(); final IpInterval addressPrefix = IpInterval.parse(typeAttribute.getCleanValue()); final List<RpslObject> ipObjects = getIpObjects(addressPrefix); if (ipObjects.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), Collections.<RpslObject>emptyList()); } final Set<RpslObject> allCandidates = Sets.newLinkedHashSet(); final List<Message> authenticationMessages = Lists.newArrayList(); for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_ROUTES)) { final List<RpslObject> candidates = getCandidatesForMntRoutesAuthentication(ipObject, update); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_ROUTES, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { final IpInterval ipInterval = IpInterval.parse(ipObject.getTypeAttribute().getCleanValue()); if (!addressPrefix.equals(ipInterval) && ipObject.containsAttribute(AttributeType.MNT_LOWER)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_LOWER)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_LOWER, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } for (final RpslObject ipObject : ipObjects) { if (ipObject.containsAttribute(AttributeType.MNT_BY)) { final List<RpslObject> candidates = objectDao.getByKeys(ObjectType.MNTNER, ipObject.getValuesForAttribute(AttributeType.MNT_BY)); allCandidates.addAll(candidates); final List<RpslObject> authenticated = authenticationModule.authenticate(update, updateContext, candidates); if (authenticated.isEmpty()) { authenticationMessages.add(UpdateMessages.authenticationFailed(ipObject, AttributeType.MNT_BY, candidates)); } else { return authenticated; } } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, allCandidates); } throw new AuthenticationFailedException(UpdateMessages.authenticationFailed(updatedObject, typeAttribute.getType(), Collections.<RpslObject>emptyList()), allCandidates); } @Autowired RouteIpAddressAuthentication(final AuthenticationModule authenticationModule, final RpslObjectDao objectDao, final Ipv4RouteTree ipv4RouteTree, final Ipv4Tree ipv4Tree, final Ipv6RouteTree ipv6RouteTree, final Ipv6Tree ipv6Tree); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void supports_create_domain() { when(update.getAction()).thenReturn(Action.CREATE); when(update.getType()).thenReturn(ObjectType.DOMAIN); assertThat(subject.supports(update), is(true)); }
@Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); } }
DomainAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void supports_modify_domain() { when(update.getAction()).thenReturn(Action.MODIFY); when(update.getType()).thenReturn(ObjectType.DOMAIN); assertThat(subject.supports(update), is(false)); }
@Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); } }
DomainAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void supports_create_inetnum() { when(update.getAction()).thenReturn(Action.CREATE); when(update.getType()).thenReturn(ObjectType.INETNUM); assertThat(subject.supports(update), is(false)); }
@Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); } }
DomainAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.DOMAIN)); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void authenticate_enum_domain() { final RpslObject rpslObject = RpslObject.parse("domain: 2.1.2.1.5.5.5.2.0.2.1.e164.arpa"); when(update.getUpdatedObject()).thenReturn(rpslObject); final List<RpslObject> authenticated = subject.authenticate(update, updateContext); assertThat(authenticated, hasSize(0)); verifyZeroInteractions(ipv4Tree, ipv6Tree, objectDao); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void authenticate_ipv4_domain_no_parent() { final RpslObject rpslObject = RpslObject.parse("domain: 255.255.193.in-addr.arpa"); when(update.getUpdatedObject()).thenReturn(rpslObject); when(ipv4Tree.findExactOrFirstLessSpecific(Ipv4Resource.parse("193.255.255.0/24"))).thenReturn(Collections.<Ipv4Entry>emptyList()); try { subject.authenticate(update, updateContext); fail("Expected exception"); } catch (AuthenticationFailedException ignored) { assertThat(ignored.getAuthenticationMessages(), contains(UpdateMessages.authenticationFailed(rpslObject, AttributeType.DOMAIN, Collections.<RpslObject>emptySet()))); } verify(ipv4Tree).findExactOrFirstLessSpecific(any(Ipv4Resource.class)); verifyZeroInteractions(ipv6Tree, objectDao); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void authenticate_ipv6_domain_no_parent() { final RpslObject rpslObject = RpslObject.parse("domain: 0.0.0.0.8.f.7.0.1.0.0.2.ip6.arpa"); when(update.getUpdatedObject()).thenReturn(rpslObject); when(ipv6Tree.findExactOrFirstLessSpecific(Ipv6Resource.parse("2001:7f8::/48"))).thenReturn(Collections.<Ipv6Entry>emptyList()); try { subject.authenticate(update, updateContext); fail("Expected exception"); } catch (AuthenticationFailedException ignored) { assertThat(ignored.getAuthenticationMessages(), contains(UpdateMessages.authenticationFailed(rpslObject, AttributeType.DOMAIN, Collections.<RpslObject>emptySet()))); } verify(ipv6Tree).findExactOrFirstLessSpecific(any(Ipv6Resource.class)); verifyZeroInteractions(ipv4Tree, objectDao); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void transform_ds_rdata_no_change() { final RpslObject rpslObject = RpslObject.parse("" + "domain: 17.45.212.in-addr.arpa\n" + "ds-rdata: 52314 5 1 93B5837D4E5C063A3728FAA72BA64068F89B39DF"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.DS_RDATA).toString(), is("52314 5 1 93B5837D4E5C063A3728FAA72BA64068F89B39DF")); 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 authenticate_ipv6_domain_multiple_parents() { final RpslObject rpslObject = RpslObject.parse("domain: 0.0.0.0.8.f.7.0.1.0.0.2.ip6.arpa"); when(update.getUpdatedObject()).thenReturn(rpslObject); when(ipv6Tree.findExactOrFirstLessSpecific(Ipv6Resource.parse("2001:7f8::/48"))).thenReturn(Lists.newArrayList( new Ipv6Entry(Ipv6Resource.parse("2001:7f8::/32"), 1), new Ipv6Entry(Ipv6Resource.parse("2001:7f8::/32"), 2))); try { subject.authenticate(update, updateContext); fail("Expected exception"); } catch (AuthenticationFailedException ignored) { assertThat(ignored.getAuthenticationMessages(), contains(UpdateMessages.authenticationFailed(rpslObject, AttributeType.DOMAIN, Collections.<RpslObject>emptySet()))); } verify(ipv6Tree).findExactOrFirstLessSpecific(any(Ipv6Resource.class)); verifyZeroInteractions(ipv4Tree, objectDao); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
DomainAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final RpslObject rpslObject = update.getUpdatedObject(); final CIString domainString = rpslObject.getKey(); final Domain domain = Domain.parse(domainString); if (domain.getType() == Domain.Type.E164) { return Collections.emptyList(); } final IpInterval<?> reverseIp = domain.getReverseIp(); if (reverseIp instanceof Ipv4Resource) { return authenticate(update, updateContext, reverseIp, ipv4Tree); } else if (reverseIp instanceof Ipv6Resource) { return authenticate(update, updateContext, reverseIp, ipv6Tree); } throw new IllegalArgumentException("Unexpected reverse ip: " + reverseIp); } @Autowired DomainAuthentication(final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao objectDao, final AuthenticationModule authenticationModule); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void supports_update_with_new_org_references() { when(update.getNewValues(AttributeType.ORG)).thenReturn(ciSet("ORG2")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("organisation: ORG1\norg: ORG1")); assertThat(subject.supports(update), is(true)); }
@Override public boolean supports(final PreparedUpdate update) { return !update.getNewValues(AttributeType.ORG).isEmpty(); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return !update.getNewValues(AttributeType.ORG).isEmpty(); } }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return !update.getNewValues(AttributeType.ORG).isEmpty(); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return !update.getNewValues(AttributeType.ORG).isEmpty(); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return !update.getNewValues(AttributeType.ORG).isEmpty(); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void no_difference_in_org_refs_is_not_supported() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("organisation: ORG1\norg: ORG1")); when(update.getReferenceObject()).thenReturn(RpslObject.parse("organisation: ORG1\norg: ORG1")); assertThat(subject.supports(update), is(false)); }
@Override public boolean supports(final PreparedUpdate update) { return !update.getNewValues(AttributeType.ORG).isEmpty(); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return !update.getNewValues(AttributeType.ORG).isEmpty(); } }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return !update.getNewValues(AttributeType.ORG).isEmpty(); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return !update.getNewValues(AttributeType.ORG).isEmpty(); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return !update.getNewValues(AttributeType.ORG).isEmpty(); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void authentication_succeeds() { when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\norg: ORG1")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\norg: ORG2")); final RpslObject organisation = RpslObject.parse("organisation: ORG1\nmnt-ref: REF-MNT"); final List<RpslObject> organisations = Lists.newArrayList(organisation); when(rpslObjectDao.getByKeys(eq(ObjectType.ORGANISATION), anyList())).thenReturn(organisations); final RpslObject maintainer = RpslObject.parse("mntner: REF-MNT"); when(rpslObjectDao.getByKey(ObjectType.MNTNER, "REF-MNT")).thenReturn(maintainer); final ArrayList<RpslObject> candidates = Lists.newArrayList(maintainer); when(credentialValidators.authenticate(eq(update), eq(updateContext), anyList())).thenReturn(candidates); final List<RpslObject> result = subject.authenticate(update, updateContext); assertThat(result.size(), is(1)); assertThat(result.get(0), is(maintainer)); verifyZeroInteractions(updateContext); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); } }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test(expected = AuthenticationFailedException.class) public void no_mntnerref_found() { when(update.getType()).thenReturn(ObjectType.PERSON); when(update.getReferenceObject()).thenReturn(RpslObject.parse("person: Some One\nnetname: NETNAME\nnic-hdl: TEST-NIC\norg: ORG1")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("person: Some One\nnetname: NETNAME\nnic-hdl: TEST-NIC\norg: ORG2")); final RpslObject organisation = RpslObject.parse("organisation: ORG2"); final List<RpslObject> organisations = Lists.newArrayList(organisation); when(rpslObjectDao.getByKeys(eq(ObjectType.ORGANISATION), anyList())).thenReturn(organisations); when(credentialValidators.authenticate(eq(update), eq(updateContext), anyList())).thenReturn(Lists.<RpslObject>newArrayList()); subject.authenticate(update, updateContext); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); } }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test(expected = AuthenticationFailedException.class) public void mntnerref_does_not_exist() { when(update.getType()).thenReturn(ObjectType.INETNUM); when(update.getReferenceObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\norg: ORG1")); when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24\norg: ORG2")); final RpslObject organisation = RpslObject.parse("organisation: ORG1\nmnt-ref: REF-MNT"); final List<RpslObject> organisations = Lists.newArrayList(organisation); when(rpslObjectDao.getByKeys(eq(ObjectType.ORGANISATION), anyList())).thenReturn(organisations); final RpslObject maintainer = RpslObject.parse("mntner: REF-MNT"); when(rpslObjectDao.getByKey(ObjectType.MNTNER, "REF-MNT")).thenThrow(EmptyResultDataAccessException.class); when(credentialValidators.authenticate(eq(update), eq(updateContext), anyList())).thenReturn(Lists.<RpslObject>newArrayList()); subject.authenticate(update, updateContext); verify(updateContext).addMessage(eq(update), UpdateMessages.nonexistantMntRef("ORG1", "REF-MNT")); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); } }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
OrgRefAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final List<Message> authenticationMessages = Lists.newArrayList(); final Map<RpslObject, List<RpslObject>> candidatesForOrganisations = getCandidatesForOrganisations(update, updateContext); final Set<RpslObject> authenticatedOrganisations = Sets.newLinkedHashSet(); for (final Map.Entry<RpslObject, List<RpslObject>> organisationEntry : candidatesForOrganisations.entrySet()) { final List<RpslObject> candidates = organisationEntry.getValue(); final List<RpslObject> authenticatedBy = credentialValidators.authenticate(update, updateContext, candidates); if (authenticatedBy.isEmpty()) { final RpslObject organisation = organisationEntry.getKey(); authenticationMessages.add(UpdateMessages.authenticationFailed(organisation, AttributeType.MNT_REF, candidates)); } else { authenticatedOrganisations.addAll(authenticatedBy); } } if (!authenticationMessages.isEmpty()) { throw new AuthenticationFailedException(authenticationMessages, Sets.newLinkedHashSet(Iterables.concat(candidatesForOrganisations.values()))); } return Lists.newArrayList(authenticatedOrganisations); } @Autowired OrgRefAuthentication(final AuthenticationModule credentialValidators, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void supports_creating_inetnum() { when(update.getAction()).thenReturn(Action.CREATE); when(update.getType()).thenReturn(ObjectType.INETNUM); assertThat(subject.supports(update), is(true)); }
@Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); } }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void supports_creating_inet6num() { when(update.getAction()).thenReturn(Action.CREATE); when(update.getType()).thenReturn(ObjectType.INET6NUM); assertThat(subject.supports(update), is(true)); }
@Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); } }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void does_not_support_modifying() { when(update.getAction()).thenReturn(Action.MODIFY); when(update.getType()).thenReturn(ObjectType.INETNUM); assertThat(subject.supports(update), is(false)); }
@Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); } }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public boolean supports(final PreparedUpdate update) { return update.getAction().equals(Action.CREATE) && (update.getType().equals(ObjectType.INETNUM) || update.getType().equals(ObjectType.INET6NUM)); } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void authenticate_mntlower_inetnum_succeeds() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24")); final RpslObject parent = RpslObject.parse("inetnum: 192.0/16\nmnt-lower: LWR-MNT"); when(rpslObjectDao.getById(anyInt())).thenReturn(parent); when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.newArrayList(ipv4Entry)); final RpslObject lowerMaintainer = RpslObject.parse("mntner: LWR-MNT"); final ArrayList<RpslObject> lowerMaintainers = Lists.newArrayList(lowerMaintainer); when(rpslObjectDao.getByKeys(ObjectType.MNTNER, parent.getValuesForAttribute(AttributeType.MNT_LOWER))).thenReturn(lowerMaintainers); when(authenticationModule.authenticate(update, updateContext, lowerMaintainers)).thenReturn(lowerMaintainers); final List<RpslObject> result = subject.authenticate(update, updateContext); assertThat(result.size(), is(1)); assertThat(result.get(0), is(lowerMaintainer)); verifyZeroInteractions(updateContext); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void transform_ds_rdata_remove_spaces() { final RpslObject rpslObject = RpslObject.parse("" + "domain: 17.45.212.in-addr.arpa\n" + "ds-rdata: 52314 5 1 93B5837D4E5C063 A3728FAA72BA64 068F89B39DF"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.DS_RDATA).toString(), is("52314 5 1 93B5837D4E5C063A3728FAA72BA64068F89B39DF")); verify(objectMessages).addMessage(result.findAttribute(AttributeType.DS_RDATA), ValidationMessages.attributeValueConverted("52314 5 1 93B5837D4E5C063 A3728FAA72BA64 068F89B39DF", "52314 5 1 93B5837D4E5C063A3728FAA72BA64068F89B39DF")); 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 authenticate_mntby_inetnum_succeeds() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24")); final RpslObject parent = RpslObject.parse("inetnum: 192.0/16\nmnt-by: TEST-MNT"); when(rpslObjectDao.getById(anyInt())).thenReturn(parent); when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.newArrayList(ipv4Entry)); final RpslObject maintainer = RpslObject.parse("mntner: TEST-MNT"); final ArrayList<RpslObject> maintainers = Lists.newArrayList(maintainer); when(rpslObjectDao.getByKeys(ObjectType.MNTNER, parent.getValuesForAttribute(AttributeType.MNT_BY))).thenReturn(maintainers); when(authenticationModule.authenticate(update, updateContext, maintainers)).thenReturn(maintainers); final List<RpslObject> result = subject.authenticate(update, updateContext); assertThat(result.size(), is(1)); assertThat(result.get(0), is(maintainer)); verifyZeroInteractions(updateContext); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test(expected = AuthenticationFailedException.class) public void authenticate_mntlower_inetnum_fails() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: 192.0/24")); final RpslObject parent = RpslObject.parse("inetnum: 192.0/16\nmnt-lower: LWR-MNT"); when(rpslObjectDao.getById(anyInt())).thenReturn(parent); when(ipv4Tree.findFirstLessSpecific(any(Ipv4Resource.class))).thenReturn(Lists.newArrayList(ipv4Entry)); final RpslObject maintainer = RpslObject.parse("mntner: LWR-MNT"); final ArrayList<RpslObject> maintainers = Lists.newArrayList(maintainer); when(rpslObjectDao.getByKeys(ObjectType.MNTNER, parent.getValuesForAttribute(AttributeType.MNT_LOWER))).thenReturn(maintainers); when(authenticationModule.authenticate(update, updateContext, maintainers)).thenReturn(Lists.<RpslObject>newArrayList()); subject.authenticate(update, updateContext); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void authenticate_mntlower_inet6num_succeeds() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: fe80::/32")); final RpslObject parent = RpslObject.parse("inetnum: fe80::/16\nmnt-lower: LWR-MNT"); when(rpslObjectDao.getById(anyInt())).thenReturn(parent); when(ipv6Tree.findFirstLessSpecific(any(Ipv6Resource.class))).thenReturn(Lists.newArrayList(ipv6Entry)); final RpslObject maintainer = RpslObject.parse("mntner: LWR-MNT"); final ArrayList<RpslObject> maintainers = Lists.newArrayList(maintainer); when(rpslObjectDao.getByKeys(ObjectType.MNTNER, parent.getValuesForAttribute(AttributeType.MNT_LOWER))).thenReturn(maintainers); when(authenticationModule.authenticate(update, updateContext, maintainers)).thenReturn(Lists.<RpslObject>newArrayList(maintainer)); final List<RpslObject> result = subject.authenticate(update, updateContext); assertThat(result.size(), is(1)); assertThat(result.get(0), is(maintainer)); verifyZeroInteractions(updateContext); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void parent_not_found() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: fe80::/32")); when(ipv6Tree.findFirstLessSpecific(any(Ipv6Resource.class))).thenReturn(Lists.<Ipv6Entry>newArrayList()); List<RpslObject> rpslObjects = subject.authenticate(update, updateContext); assertThat(rpslObjects, is(empty())); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void more_than_one_parent_found() { when(update.getUpdatedObject()).thenReturn(RpslObject.parse("inetnum: fe80::/32")); when(ipv6Tree.findFirstLessSpecific(any(Ipv6Resource.class))).thenReturn(Lists.<Ipv6Entry>newArrayList(ipv6Entry, ipv6Entry)); List<RpslObject> rpslObjects = subject.authenticate(update, updateContext); assertThat(rpslObjects, is(empty())); }
@Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
InetnumAuthentication extends AuthenticationStrategyBase { @Override public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext) { final IpInterval ipInterval = IpInterval.parse(update.getUpdatedObject().getKey()); IpEntry ipEntry; try { ipEntry = getParentEntry(ipInterval); } catch (IllegalArgumentException e) { return Collections.emptyList(); } final RpslObject parentObject = rpslObjectDao.getById(ipEntry.getObjectId()); AttributeType attributeType = AttributeType.MNT_LOWER; Collection<CIString> maintainerKeys = parentObject.getValuesForAttribute(attributeType); if (maintainerKeys.isEmpty()) { attributeType = AttributeType.MNT_BY; maintainerKeys = parentObject.getValuesForAttribute(attributeType); } final List<RpslObject> maintainers = rpslObjectDao.getByKeys(ObjectType.MNTNER, maintainerKeys); final List<RpslObject> authenticatedBy = authenticationModule.authenticate(update, updateContext, maintainers); if (authenticatedBy.isEmpty()) { throw new AuthenticationFailedException(UpdateMessages.parentAuthenticationFailed(parentObject, attributeType, maintainers), maintainers); } return authenticatedBy; } @Autowired InetnumAuthentication(final AuthenticationModule authenticationModule, final Ipv4Tree ipv4Tree, final Ipv6Tree ipv6Tree, final RpslObjectDao rpslObjectDao); @Override boolean supports(final PreparedUpdate update); @Override List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext); }
@Test public void authentication_success() { boolean result = subject.hasValidCredential(update, updateContext, Sets.newHashSet(offeredCredential), knownCredential); assertThat(result, is(true)); }
@Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; }
X509CredentialValidator implements CredentialValidator<X509Credential, X509Credential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; } }
X509CredentialValidator implements CredentialValidator<X509Credential, X509Credential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; } @Autowired X509CredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, final LoggerContext loggerContext); }
X509CredentialValidator implements CredentialValidator<X509Credential, X509Credential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; } @Autowired X509CredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, final LoggerContext loggerContext); @Override Class<X509Credential> getSupportedCredentials(); @Override Class<X509Credential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential); }
X509CredentialValidator implements CredentialValidator<X509Credential, X509Credential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; } @Autowired X509CredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, final LoggerContext loggerContext); @Override Class<X509Credential> getSupportedCredentials(); @Override Class<X509Credential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential); }
@Test public void authentication_keycert_not_found() throws Exception { when(rpslObjectDao.getByKey(ObjectType.KEY_CERT, "X509-1")).thenThrow(new EmptyResultDataAccessException(1)); boolean result = subject.hasValidCredential(update, updateContext, Sets.newHashSet(offeredCredential), knownCredential); assertThat(result, is(false)); }
@Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; }
X509CredentialValidator implements CredentialValidator<X509Credential, X509Credential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; } }
X509CredentialValidator implements CredentialValidator<X509Credential, X509Credential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; } @Autowired X509CredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, final LoggerContext loggerContext); }
X509CredentialValidator implements CredentialValidator<X509Credential, X509Credential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; } @Autowired X509CredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, final LoggerContext loggerContext); @Override Class<X509Credential> getSupportedCredentials(); @Override Class<X509Credential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential); }
X509CredentialValidator implements CredentialValidator<X509Credential, X509Credential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; } @Autowired X509CredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, final LoggerContext loggerContext); @Override Class<X509Credential> getSupportedCredentials(); @Override Class<X509Credential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential); }
@Test public void authentication_keycert_is_invalid() throws Exception { when(rpslObjectDao.getByKey(ObjectType.KEY_CERT, "X509-1")).thenAnswer(new Answer<RpslObject>() { @Override public RpslObject answer(InvocationOnMock invocation) throws Throwable { return RpslObject.parse( "key-cert: AUTO-1\n" + "method: X509\n" + "mnt-by: OWNER-MNT\n" + "source: TEST\n"); } }); boolean result = subject.hasValidCredential(update, updateContext, Sets.newHashSet(offeredCredential), knownCredential); assertThat(result, is(false)); }
@Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; }
X509CredentialValidator implements CredentialValidator<X509Credential, X509Credential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; } }
X509CredentialValidator implements CredentialValidator<X509Credential, X509Credential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; } @Autowired X509CredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, final LoggerContext loggerContext); }
X509CredentialValidator implements CredentialValidator<X509Credential, X509Credential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; } @Autowired X509CredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, final LoggerContext loggerContext); @Override Class<X509Credential> getSupportedCredentials(); @Override Class<X509Credential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential); }
X509CredentialValidator implements CredentialValidator<X509Credential, X509Credential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential) { for (final X509Credential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { log(update, String.format("Successfully validated with keycert: %s", knownCredential.getKeyId())); return true; } } return false; } @Autowired X509CredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, final LoggerContext loggerContext); @Override Class<X509Credential> getSupportedCredentials(); @Override Class<X509Credential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<X509Credential> offeredCredentials, final X509Credential knownCredential); }
@Test public void supportedCredentials() { assertThat(subject.getSupportedCredentials(), Is.<Class<SsoCredential>>is(SsoCredential.class)); }
@Override public Class<SsoCredential> getSupportedCredentials() { return SsoCredential.class; }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public Class<SsoCredential> getSupportedCredentials() { return SsoCredential.class; } }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public Class<SsoCredential> getSupportedCredentials() { return SsoCredential.class; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public Class<SsoCredential> getSupportedCredentials() { return SsoCredential.class; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); @Override Class<SsoCredential> getSupportedCredentials(); @Override Class<SsoCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential); }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public Class<SsoCredential> getSupportedCredentials() { return SsoCredential.class; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); @Override Class<SsoCredential> getSupportedCredentials(); @Override Class<SsoCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential); }
@Test public void hasValidCredential() { final UserSession offered = new UserSession("[email protected]", "Test User", true, "2033-01-30T16:38:27.369+11:00"); offered.setUuid("testuuid"); final SsoCredential offeredCredential = (SsoCredential)SsoCredential.createOfferedCredential(offered); final SsoCredential knownCredential = SsoCredential.createKnownCredential("testuuid"); final boolean hasValidCredential = subject.hasValidCredential( preparedUpdate, updateContext, Collections.singletonList(offeredCredential), knownCredential); assertThat(hasValidCredential, is(true)); }
@Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); @Override Class<SsoCredential> getSupportedCredentials(); @Override Class<SsoCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential); }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); @Override Class<SsoCredential> getSupportedCredentials(); @Override Class<SsoCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential); }
@Test public void transform_ds_rdata_remove_parentheses() { final RpslObject rpslObject = RpslObject.parse("" + "domain: 17.45.212.in-addr.arpa\n" + "ds-rdata: 52314 5 1 ( 93B5837D4E5C063A3728FAA72BA64068F89B39DF )"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.DS_RDATA).toString(), is("52314 5 1 93B5837D4E5C063A3728FAA72BA64068F89B39DF")); verify(objectMessages).addMessage(result.findAttribute(AttributeType.DS_RDATA), ValidationMessages.attributeValueConverted("52314 5 1 ( 93B5837D4E5C063A3728FAA72BA64068F89B39DF )", "52314 5 1 93B5837D4E5C063A3728FAA72BA64068F89B39DF")); 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 setsEffectiveCredential() { final UserSession offered = new UserSession("[email protected]", "Test User", true, "2033-01-30T16:38:27.369+11:00"); offered.setUuid("testuuid"); final SsoCredential offeredCredential = (SsoCredential)SsoCredential.createOfferedCredential(offered); final SsoCredential knownCredential = SsoCredential.createKnownCredential("testuuid"); subject.hasValidCredential( preparedUpdate, updateContext, Collections.singletonList(offeredCredential), knownCredential); assertThat(update.getEffectiveCredential(), is("[email protected]" )); assertThat(update.getEffectiveCredentialType(), is(Update.EffectiveCredentialType.SSO)); }
@Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); @Override Class<SsoCredential> getSupportedCredentials(); @Override Class<SsoCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential); }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); @Override Class<SsoCredential> getSupportedCredentials(); @Override Class<SsoCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential); }
@Test public void hasNoOfferedCredentials() { final UserSession offered = new UserSession("[email protected]", "Test User", true, "2033-01-30T16:38:27.369+11:00"); offered.setUuid("testuuid"); final SsoCredential knownCredential = SsoCredential.createKnownCredential("testuuid"); final boolean hasValidCredential = subject.hasValidCredential( preparedUpdate, updateContext, Collections.<SsoCredential>emptyList(), knownCredential); assertThat(hasValidCredential, is(false)); }
@Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); @Override Class<SsoCredential> getSupportedCredentials(); @Override Class<SsoCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential); }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); @Override Class<SsoCredential> getSupportedCredentials(); @Override Class<SsoCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential); }
@Test public void noCheckForUserInactivity() { final UserSession offered = new UserSession("[email protected]", "Test User", false, "2033-01-30T16:38:27.369+11:00"); offered.setUuid("testuuid"); final SsoCredential offeredCredential = (SsoCredential)SsoCredential.createOfferedCredential(offered); final SsoCredential knownCredential = SsoCredential.createKnownCredential("testuuid"); final boolean hasValidCredential = subject.hasValidCredential( preparedUpdate, updateContext, Collections.singletonList(offeredCredential), knownCredential); assertThat(hasValidCredential, is(true)); }
@Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); @Override Class<SsoCredential> getSupportedCredentials(); @Override Class<SsoCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential); }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); @Override Class<SsoCredential> getSupportedCredentials(); @Override Class<SsoCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential); }
@Test public void noCorrectCredential() { final UserSession offered = new UserSession("[email protected]", "Test User", false, "2033-01-30T16:38:27.369+11:00"); offered.setUuid("offereduuid"); final SsoCredential offeredCredential = (SsoCredential)SsoCredential.createOfferedCredential(offered); final SsoCredential knownCredential = SsoCredential.createKnownCredential("testuuid"); final boolean hasValidCredential = subject.hasValidCredential( preparedUpdate, updateContext, Collections.singletonList(offeredCredential), knownCredential); assertThat(hasValidCredential, is(false)); }
@Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); @Override Class<SsoCredential> getSupportedCredentials(); @Override Class<SsoCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential); }
SsoCredentialValidator implements CredentialValidator<SsoCredential, SsoCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential) { for (SsoCredential offered : offeredCredentials) { if (offered.getOfferedUserSession().getUuid().equals(knownCredential.getKnownUuid())) { log(update, String.format("Validated %s with RIPE NCC Access for user: %s.", update.getFormattedKey(), offered.getOfferedUserSession().getUsername())); update.getUpdate().setEffectiveCredential(offered.getOfferedUserSession().getUsername(), Update.EffectiveCredentialType.SSO); return true; } } return false; } @Autowired SsoCredentialValidator(final LoggerContext loggerContext); @Override Class<SsoCredential> getSupportedCredentials(); @Override Class<SsoCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<SsoCredential> offeredCredentials, final SsoCredential knownCredential); }
@Test public void authenticate_finds_all_candidates() { when(credentialValidator.hasValidCredential(any(PreparedUpdate.class), any(UpdateContext.class), anyCollection(), any(PasswordCredential.class))).thenReturn(true); final RpslObject mntner1 = RpslObject.parse("mntner: TEST-MNT\nauth: MD5-PWsomething"); final RpslObject mntner2 = RpslObject.parse("mntner: TEST2-MNT\nauth: MD5-PWsomethingElse"); final RpslObject mntner3 = RpslObject.parse("mntner: TEST3-MNT"); final List<RpslObject> result = subject.authenticate(update, updateContext, Lists.newArrayList(mntner1, mntner2, mntner3)); assertThat(result.size(), is(2)); assertThat(result.contains(mntner1), is(true)); assertThat(result.contains(mntner2), is(true)); assertThat(result.contains(mntner3), is(false)); }
@CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } @Autowired AuthenticationModule(final LoggerContext loggerContext, final CredentialValidator<? extends Credential, ? extends Credential>... credentialValidators); }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } @Autowired AuthenticationModule(final LoggerContext loggerContext, final CredentialValidator<? extends Credential, ? extends Credential>... credentialValidators); @CallerSensitive List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers); }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } @Autowired AuthenticationModule(final LoggerContext loggerContext, final CredentialValidator<? extends Credential, ? extends Credential>... credentialValidators); @CallerSensitive List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers); }
@Test public void authenticate_mixed_case_auth_line() { when(credentialValidator.hasValidCredential(any(PreparedUpdate.class), any(UpdateContext.class), anyCollection(), any(PasswordCredential.class))).thenReturn(true); final RpslObject mntner = RpslObject.parse("mntner: TEST-MNT\nauth: Md5-pW something"); final List<RpslObject> result = subject.authenticate(update, updateContext, Lists.newArrayList(mntner)); assertThat(result, hasSize(1)); assertThat(result.contains(mntner), is(true)); }
@CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } @Autowired AuthenticationModule(final LoggerContext loggerContext, final CredentialValidator<? extends Credential, ? extends Credential>... credentialValidators); }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } @Autowired AuthenticationModule(final LoggerContext loggerContext, final CredentialValidator<? extends Credential, ? extends Credential>... credentialValidators); @CallerSensitive List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers); }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } @Autowired AuthenticationModule(final LoggerContext loggerContext, final CredentialValidator<? extends Credential, ? extends Credential>... credentialValidators); @CallerSensitive List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers); }
@Test public void authenticate_fails() { when(credentialValidator.hasValidCredential(any(PreparedUpdate.class), any(UpdateContext.class), anyCollection(), any(PasswordCredential.class))).thenReturn(false); final RpslObject mntner = RpslObject.parse("mntner: TEST-MNT\nauth: MD5-PW $1$d9fKeTr2$Si7YudNf4rUGmR71n/cqk/"); final List<RpslObject> result = subject.authenticate(update, updateContext, Lists.newArrayList(mntner)); assertThat(result, hasSize(0)); }
@CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } @Autowired AuthenticationModule(final LoggerContext loggerContext, final CredentialValidator<? extends Credential, ? extends Credential>... credentialValidators); }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } @Autowired AuthenticationModule(final LoggerContext loggerContext, final CredentialValidator<? extends Credential, ? extends Credential>... credentialValidators); @CallerSensitive List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers); }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } @Autowired AuthenticationModule(final LoggerContext loggerContext, final CredentialValidator<? extends Credential, ? extends Credential>... credentialValidators); @CallerSensitive List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers); }
@Test public void authenticate_sso_credential_checked_first() { when(credentialValidator.hasValidCredential(any(PreparedUpdate.class), any(UpdateContext.class), anyCollection(), any(PasswordCredential.class))).thenReturn(false); when(ssoCredentialValidator.hasValidCredential(any(PreparedUpdate.class), any(UpdateContext.class), anyCollection(), any(SsoCredential.class))).thenAnswer( new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { verify(credentialValidator, never()).hasValidCredential(any(PreparedUpdate.class), any(UpdateContext.class), anyCollection(), any(PasswordCredential.class)); return false; } }); final RpslObject maintainer = RpslObject.parse( "mntner: OWNER-MNT\n" + "descr: Owner Maintainer\n" + "admin-c: TP1-TEST\n" + "upd-to: [email protected]\n" + "auth: MD5-PW $1$d9fKeTr2$Si7YudNf4rUGmR71n/cqk/ #test\n" + "auth: SSO [email protected]\n" + "mnt-by: OWNER-MNT\n" + "source: TEST"); subject.authenticate(update, updateContext, Collections.singletonList(maintainer)); }
@CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } @Autowired AuthenticationModule(final LoggerContext loggerContext, final CredentialValidator<? extends Credential, ? extends Credential>... credentialValidators); }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } @Autowired AuthenticationModule(final LoggerContext loggerContext, final CredentialValidator<? extends Credential, ? extends Credential>... credentialValidators); @CallerSensitive List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers); }
AuthenticationModule { @CallerSensitive public List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers) { final Credentials offered = update.getCredentials(); boolean passwordRemovedRemark = false; loggerContext.logAuthenticationStrategy(update.getUpdate(), getCaller(), maintainers); final List<RpslObject> authenticatedCandidates = Lists.newArrayList(); for (final RpslObject maintainer : maintainers) { if (hasValidCredentialForCandidate(update, updateContext, offered, maintainer)) { authenticatedCandidates.add(maintainer); } else { if (hasPasswordRemovedRemark(maintainer)) { passwordRemovedRemark = true; } } } if (authenticatedCandidates.isEmpty() && passwordRemovedRemark) { updateContext.addMessage(update, UpdateMessages.oldPasswordsRemoved()); } return authenticatedCandidates; } @Autowired AuthenticationModule(final LoggerContext loggerContext, final CredentialValidator<? extends Credential, ? extends Credential>... credentialValidators); @CallerSensitive List<RpslObject> authenticate(final PreparedUpdate update, final UpdateContext updateContext, final Collection<RpslObject> maintainers); }
@Test public void supports() { assertEquals(PasswordCredential.class, subject.getSupportedCredentials()); }
@Override public Class<PasswordCredential> getSupportedCredentials() { return PasswordCredential.class; }
PasswordCredentialValidator implements CredentialValidator<PasswordCredential, PasswordCredential> { @Override public Class<PasswordCredential> getSupportedCredentials() { return PasswordCredential.class; } }
PasswordCredentialValidator implements CredentialValidator<PasswordCredential, PasswordCredential> { @Override public Class<PasswordCredential> getSupportedCredentials() { return PasswordCredential.class; } @Autowired PasswordCredentialValidator(LoggerContext loggerContext); }
PasswordCredentialValidator implements CredentialValidator<PasswordCredential, PasswordCredential> { @Override public Class<PasswordCredential> getSupportedCredentials() { return PasswordCredential.class; } @Autowired PasswordCredentialValidator(LoggerContext loggerContext); @Override Class<PasswordCredential> getSupportedCredentials(); @Override Class<PasswordCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PasswordCredential> offeredCredentials, final PasswordCredential knownCredential); }
PasswordCredentialValidator implements CredentialValidator<PasswordCredential, PasswordCredential> { @Override public Class<PasswordCredential> getSupportedCredentials() { return PasswordCredential.class; } @Autowired PasswordCredentialValidator(LoggerContext loggerContext); @Override Class<PasswordCredential> getSupportedCredentials(); @Override Class<PasswordCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PasswordCredential> offeredCredentials, final PasswordCredential knownCredential); }
@Test public void setsEffectiveCredential() { final String message = "-----BEGIN PGP SIGNED MESSAGE-----\n" + "Hash: SHA1\n" + "\n" + "inetnum: 213.168.127.96 - 213.168.127.10\n" + "netname: NETNAME\n" + "descr: Description\n" + "country: DE\n" + "admin-c: TEST-RIPE\n" + "tech-c: TEST-RIPE\n" + "status: ASSIGNED PA\n" + "mnt-by: TEST-MNT\n" + "mnt-lower: TEST-MNT\n" + "source: RIPE\n" + "delete: reason\n" + "-----BEGIN PGP SIGNATURE-----\n" + "Version: GnuPG v1\n" + "Comment: GPGTools - http: "\n" + "iQEcBAEBAgAGBQJWTc5TAAoJELvMuy1XY5UNorkIAJsWhjbTcPBLCtug50Hkp0ty\n" + "6hMMVWfIS92fGFzpUKkS3fTnUXkTwsaF0+KQRSHEa6pobMXsP5MCl0SPJaVY4FTz\n" + "CtlpTHQ1avld/o281Y44wGmN/JFcGml8cnpY9/wseNS2OogemJ1ZQdd9Y4zNuCNX\n" + "YS5y2jXLQyuLEzmhg423+b4IqeVZBHdWX43tituzk5phy9U2ZuVAnxLQWvNt0QZC\n" + "v6g0Rig345U3rn0aRCAAFz6C/Al1QbRt5dsH3vQ/lQfiCBoR0A1x9ttsUkB7oCdJ\n" + "P4eeAXVVIZIqCPKBmNo2fRoDJW5Ly1YEAIASp1pjh0h/kDfJwPQc+mqOQ1CRwgQ=\n" + "=KPdC\n" + "-----END PGP SIGNATURE-----"; final PgpCredential offeredCredential = PgpCredential.createOfferedCredential(message, Charset.forName("ISO-8859-7")); final PgpCredential knownCredential = PgpCredential.createKnownCredential("PGPKEY-5763950D"); final Update update = createUpdate(); when(preparedUpdate.getUpdate()).thenReturn(update); when(rpslObjectDao.getByKey(ObjectType.KEY_CERT, KEYCERT_OBJECT.getKey().toString())).thenReturn(KEYCERT_OBJECT); subject.hasValidCredential(preparedUpdate, updateContext, Sets.newHashSet(offeredCredential), knownCredential); MatcherAssert.assertThat(update.getEffectiveCredential(), Is.is(knownCredential.getKeyId())); MatcherAssert.assertThat(update.getEffectiveCredentialType(), Is.is(Update.EffectiveCredentialType.PGP)); }
@Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } @Autowired PgpCredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, LoggerContext loggerContext); }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } @Autowired PgpCredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, LoggerContext loggerContext); @Override Class<PgpCredential> getSupportedCredentials(); @Override Class<PgpCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential); }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } @Autowired PgpCredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, LoggerContext loggerContext); @Override Class<PgpCredential> getSupportedCredentials(); @Override Class<PgpCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential); }
@Test public void transform_ds_rdata_remove_spaces_and_parentheses() { final RpslObject rpslObject = RpslObject.parse("" + "domain: 17.45.212.in-addr.arpa\n" + "ds-rdata: 52314 5 1 ( 93B5837D4E5C063 A3728FAA72BA64 068F89B39DF )"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.DS_RDATA).toString(), is("52314 5 1 93B5837D4E5C063A3728FAA72BA64068F89B39DF")); verify(objectMessages).addMessage(result.findAttribute(AttributeType.DS_RDATA), ValidationMessages.attributeValueConverted("52314 5 1 ( 93B5837D4E5C063 A3728FAA72BA64 068F89B39DF )", "52314 5 1 93B5837D4E5C063A3728FAA72BA64068F89B39DF")); 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 authenticateSignatureVerifyFailed() throws Exception { final PgpCredential offeredCredential = PgpCredential.createOfferedCredential("" + "-----BEGIN PGP SIGNED MESSAGE-----\n" + "Hash: SHA1\n\n" + "inetnum: 213.168.127.96 - 213.168.127.103\n" + "-----BEGIN PGP SIGNATURE-----\n" + "Version: GnuPG v1.4.11 (MingW32) - WinPT 1.4.3\n" + "Charset: UTF-8\n" + "Comment: GnuPT 2.7.2\n\n" + "iEYEARECAAYFAk+r2BgACgkQesVNFxdpXQoLPQCgq4dt/+PymmQZ8/AX+0HJfbGL\n" + "LEwAn2zxSKmMKSLZVbRLxwgVhDQGn+5o\n" + "=g9vN\n" + "-----END PGP SIGNATURE-----\n"); final PgpCredential knownCredential = PgpCredential.createKnownCredential("PGPKEY-5763950D"); when(rpslObjectDao.getByKey(ObjectType.KEY_CERT, KEYCERT_OBJECT.getKey().toString())).thenReturn(KEYCERT_OBJECT); assertThat(subject.hasValidCredential(preparedUpdate, updateContext, Sets.newHashSet(offeredCredential), knownCredential), is(false)); }
@Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } @Autowired PgpCredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, LoggerContext loggerContext); }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } @Autowired PgpCredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, LoggerContext loggerContext); @Override Class<PgpCredential> getSupportedCredentials(); @Override Class<PgpCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential); }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } @Autowired PgpCredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, LoggerContext loggerContext); @Override Class<PgpCredential> getSupportedCredentials(); @Override Class<PgpCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential); }
@Test public void authenticateKeycertNotFound() throws Exception { final String message = "-----BEGIN PGP SIGNED MESSAGE-----\n" + "Hash: SHA1\n" + "\n" + "inetnum: 213.168.127.96 - 213.168.127.10\n" + "netname: NETNAME\n" + "descr: Description\n" + "country: DE\n" + "admin-c: TEST-RIPE\n" + "tech-c: TEST-RIPE\n" + "status: ASSIGNED PA\n" + "mnt-by: TEST-MNT\n" + "mnt-lower: TEST-MNT\n" + "source: RIPE\n" + "delete: reason\n" + "-----BEGIN PGP SIGNATURE-----\n" + "Version: GnuPG v1\n" + "Comment: GPGTools - http: "\n" + "iQEcBAEBAgAGBQJWTc9CAAoJELvMuy1XY5UNl2oH/2i2JeUvWsrOF/FAxJsvCUMG\n" + "4KqGWJKb1/Sdgp3NJbtrqoZo54+vdI3f0Oqb6q5nspTQJntfA0uq08GFbwcOHA5T\n" + "9fgyh0BVE/OFNUY336r+Gr8Sf9sfLWVgAIUNhe5hyUeoqSD+zcp0buYE/HFLp4Yh\n" + "EVoOSHSGdSpRtkErE3eMYEjYCle7zJhC3MDnauWYYHQzZVJEvQ8mnEi3fZd+OetL\n" + "XnngoRCUa3z3J8tFx0GYNNxP+YA24+gJf+BuJqxX86N0Nua8ZZqzR+AkbAffvXwv\n" + "HR3C5Mn2WOXspKRfdevzV34k4x/SzqFa1qGoF62AKmY5pLMX8XSvU4WV4zjOEDU=\n" + "=UgWC\n" + "-----END PGP SIGNATURE-----"; final PgpCredential offeredCredential = PgpCredential.createOfferedCredential(message); final PgpCredential knownCredential = PgpCredential.createKnownCredential("PGPKEY-5763950D"); when(rpslObjectDao.getByKey(ObjectType.KEY_CERT, KEYCERT_OBJECT.getKey().toString())).thenThrow(new EmptyResultDataAccessException(1)); assertThat(subject.hasValidCredential(preparedUpdate, updateContext, Sets.newHashSet(offeredCredential), knownCredential), is(false)); }
@Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } @Autowired PgpCredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, LoggerContext loggerContext); }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } @Autowired PgpCredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, LoggerContext loggerContext); @Override Class<PgpCredential> getSupportedCredentials(); @Override Class<PgpCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential); }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } @Autowired PgpCredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, LoggerContext loggerContext); @Override Class<PgpCredential> getSupportedCredentials(); @Override Class<PgpCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential); }
@Test public void authenticateKnownCredentialIsInvalid() { final String message = "-----BEGIN PGP SIGNED MESSAGE-----\n" + "Hash: SHA1\n" + "\n" + "inetnum: 213.168.127.96 - 213.168.127.10\n" + "netname: NETNAME\n" + "descr: Description\n" + "country: DE\n" + "admin-c: TEST-RIPE\n" + "tech-c: TEST-RIPE\n" + "status: ASSIGNED PA\n" + "mnt-by: TEST-MNT\n" + "mnt-lower: TEST-MNT\n" + "source: RIPE\n" + "delete: reason\n" + "-----BEGIN PGP SIGNATURE-----\n" + "Version: GnuPG v1\n" + "Comment: GPGTools - http: "\n" + "iQEcBAEBAgAGBQJWTdB6AAoJELvMuy1XY5UN96QIAJjssbJrKuJvWmgq/iTYjHYz\n" + "iq3qJGprdxM0G+OErsydLmG5R7BhW6aLmV/H07Ap84T9KUniGm+sWgAHJdC0Eb/n\n" + "cf+8sC7hy5Fkmwabam52Ncr+c4mEuR7Tt2s0bfm2x+IgFb/doMoJjCydYk5FQKL/\n" + "QzhgR3whwhftsrSgj2MAD2VDVo7HsvD1Otp/hVLISdnPQuR6i9wRp7gipn+QSdp/\n" + "PBK/UzdvUGItTM/wCoekEcwh41plq7VepL6rbA2NXe9x65rvMprEhL0ulQVP8YXZ\n" + "9LF/bGg8YGezpktt8iFnLKsOCek74mSdVi70xTNsc4sq9mNfdBXrsZstNHvDJ+E=\n" + "=Pr87\n" + "-----END PGP SIGNATURE-----"; final PgpCredential offeredCredential = PgpCredential.createOfferedCredential(message); final PgpCredential knownCredential = PgpCredential.createKnownCredential("PGPKEY-5763950D"); final RpslObject emptyKeycertObject = new RpslObjectBuilder(KEYCERT_OBJECT).removeAttributeType(AttributeType.CERTIF).get(); when(rpslObjectDao.getByKey(ObjectType.KEY_CERT, emptyKeycertObject.getKey().toString())).thenReturn(emptyKeycertObject); assertThat(subject.hasValidCredential(preparedUpdate, updateContext, Sets.newHashSet(offeredCredential), knownCredential), is(false)); }
@Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } @Autowired PgpCredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, LoggerContext loggerContext); }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } @Autowired PgpCredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, LoggerContext loggerContext); @Override Class<PgpCredential> getSupportedCredentials(); @Override Class<PgpCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential); }
PgpCredentialValidator implements CredentialValidator<PgpCredential, PgpCredential> { @Override public boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential) { for (final PgpCredential offeredCredential : offeredCredentials) { if (verifySignedMessage(update, updateContext, offeredCredential, knownCredential)) { update.getUpdate().setEffectiveCredential(knownCredential.getKeyId(), Update.EffectiveCredentialType.PGP); return true; } } return false; } @Autowired PgpCredentialValidator(final RpslObjectDao rpslObjectDao, final DateTimeProvider dateTimeProvider, LoggerContext loggerContext); @Override Class<PgpCredential> getSupportedCredentials(); @Override Class<PgpCredential> getSupportedOfferedCredentialType(); @Override boolean hasValidCredential(final PreparedUpdate update, final UpdateContext updateContext, final Collection<PgpCredential> offeredCredentials, final PgpCredential knownCredential); }
@Test public void create_input_has_no_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.CREATE); final RpslObject input = TEMPLATE; final RpslObject updatedObject = subject.generateAttributes(null, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_ACTION)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_ACTION)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void create_input_has_wrong_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.CREATE); when(overrideOptions.isSkipLastModified()).thenReturn(false); final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject updatedObject = subject.generateAttributes(null, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_ACTION)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_ACTION)); testHelper.assertAttributeMessage(updatedObject.findAttribute(AttributeType.CREATED), ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.CREATED)); testHelper.assertAttributeMessage(updatedObject.findAttribute(AttributeType.LAST_MODIFIED), ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.LAST_MODIFIED)); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void create_input_has_double_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.CREATE); when(overrideOptions.isSkipLastModified()).thenReturn(false); final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject updatedObject = subject.generateAttributes(null, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_ACTION)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_ACTION)); testHelper.assertAttributeMessage(updatedObject.findAttribute(AttributeType.CREATED), ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.CREATED), 2); testHelper.assertAttributeMessage(updatedObject.findAttribute(AttributeType.LAST_MODIFIED), ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.LAST_MODIFIED), 2); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void create_input_has_right_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.CREATE); when(overrideOptions.isSkipLastModified()).thenReturn(false); final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_ACTION)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_ACTION)) .get(); final RpslObject updatedObject = subject.generateAttributes(null, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_ACTION)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_ACTION)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void modify_original_has_no_timestamps_input_has_no_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.MODIFY); when(overrideOptions.isSkipLastModified()).thenReturn(false); final RpslObject original = TEMPLATE; final RpslObject input = TEMPLATE; final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.containsAttribute(AttributeType.CREATED), is(false)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_ACTION)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void modify_original_has_timestamps_input_has_no_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.MODIFY); when(overrideOptions.isSkipLastModified()).thenReturn(false); final RpslObject original = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject input = TEMPLATE; final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_PAST)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_ACTION)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Ignore("TP: remove defensive code. all attributes have timestamps") @Test public void modify_original_has_no_timestamps_input_has_wrong_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.MODIFY); when(overrideOptions.isSkipLastModified()).thenReturn(false); final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_OTHER)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_OTHER)) .get(); final RpslObject updatedObject = subject.generateAttributes(TEMPLATE, input, update, updateContext); assertThat(updatedObject.containsAttribute(AttributeType.CREATED), is(false)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_ACTION)); testHelper.assertAttributeMessage( ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.CREATED)); testHelper.assertAttributeMessage(updatedObject.findAttribute(AttributeType.LAST_MODIFIED), ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.LAST_MODIFIED)); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void transform_person() { final RpslObject rpslObject = RpslObject.parse("" + "person: Test Person\n" + "nic-hdl: TP1-RIPE"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result, is(rpslObject)); 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 modify_original_has_no_timestamps_input_has_right_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.MODIFY); when(overrideOptions.isSkipLastModified()).thenReturn(false); final RpslObject original = TEMPLATE; final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_ACTION)) .get(); final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.containsAttribute(AttributeType.CREATED), is(false)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_ACTION)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void modify_original_has_timestamps_input_has_wrong_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.MODIFY); when(overrideOptions.isSkipLastModified()).thenReturn(false); final RpslObject original = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_OTHER)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_OTHER)) .get(); final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_PAST)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_ACTION)); testHelper.assertAttributeMessage(updatedObject.findAttribute(AttributeType.CREATED), ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.CREATED)); testHelper.assertAttributeMessage(updatedObject.findAttribute(AttributeType.LAST_MODIFIED), ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.LAST_MODIFIED)); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void modify_original_has_timestamps_input_has_right_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.MODIFY); when(overrideOptions.isSkipLastModified()).thenReturn(false); final RpslObject original = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_ACTION)) .get(); final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_PAST)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_ACTION)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void delete_original_has_no_timestamps_input_has_no_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.DELETE); final RpslObject original = TEMPLATE; final RpslObject input = TEMPLATE; final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.containsAttribute(AttributeType.CREATED), is(false)); assertThat(updatedObject.containsAttribute(AttributeType.LAST_MODIFIED), is(false)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void delete_original_has_timestamps_input_has_no_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.DELETE); final RpslObject original = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject input = TEMPLATE; final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_PAST)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_PAST)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void delete_original_has_timestamps_input_has_wrong_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.DELETE); final RpslObject original = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_OTHER)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_OTHER)) .get(); final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_PAST)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_PAST)); testHelper.assertAttributeMessage(updatedObject.findAttribute(AttributeType.CREATED), ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.CREATED)); testHelper.assertAttributeMessage(updatedObject.findAttribute(AttributeType.LAST_MODIFIED), ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.LAST_MODIFIED)); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void delete_original_has_timestamps_input_has_right_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.DELETE); final RpslObject original = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_PAST)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_PAST)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Ignore("TP: remove defensive code. all attributes have timestamps") @Test public void delete_original_no_timestamps_input_has_wrong_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.DELETE); final RpslObject original = TEMPLATE; final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_OTHER)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_OTHER)) .get(); final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.containsAttribute(AttributeType.CREATED), is(false)); assertThat(updatedObject.containsAttribute(AttributeType.LAST_MODIFIED), is(false)); testHelper.assertAttributeMessage( ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.CREATED)); testHelper.assertAttributeMessage( ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.LAST_MODIFIED)); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Ignore("TP: remove defensive code. all attributes have timestamps") @Test public void delete_original_no_timestamps_input_has_right_timestamps() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.DELETE); final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject updatedObject = subject.generateAttributes(TEMPLATE, input, update, updateContext); assertThat(updatedObject.containsAttribute(AttributeType.CREATED), is(false)); assertThat(updatedObject.containsAttribute(AttributeType.LAST_MODIFIED), is(false)); testHelper.assertAttributeMessage( ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.CREATED)); testHelper.assertAttributeMessage( ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.LAST_MODIFIED)); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void create_input_has_no_timestamps_skipLastModified() { testDateTimeProvider.setTime(actionTime()); when(overrideOptions.isSkipLastModified()).thenReturn(true); when(updateContext.getAction(update)).thenReturn(Action.CREATE); final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject updatedObject = subject.generateAttributes(null, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_ACTION)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_ACTION)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void transform_inetnum_no_change() { final RpslObject rpslObject = RpslObject.parse("inetnum: 193.0.0.0 - 193.255.255.255"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result, is(rpslObject)); 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 modify_original_has_timestamps_input_has_no_timestamps_skipLastModified() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.MODIFY); when(overrideOptions.isSkipLastModified()).thenReturn(true); final RpslObject original = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject input = TEMPLATE; final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_PAST)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_PAST)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void modify_original_has_timestamps_input_has_wrong_timestamps_skipLastModified() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.MODIFY); when(overrideOptions.isSkipLastModified()).thenReturn(true); final RpslObject original = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_OTHER)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_OTHER)) .get(); final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_PAST)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_PAST)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void modify_original_has_timestamps_input_has_right_timestamps_skipLastModified() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.MODIFY); when(overrideOptions.isSkipLastModified()).thenReturn(true); final RpslObject original = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject input = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_PAST)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_PAST)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void delete_original_has_timestamps_input_has_no_timestamps_skipLastModified() { testDateTimeProvider.setTime(actionTime()); when(updateContext.getAction(update)).thenReturn(Action.DELETE); when(overrideOptions.isSkipLastModified()).thenReturn(true); final RpslObject original = new RpslObjectBuilder(TEMPLATE) .addAttributeSorted(new RpslAttribute(AttributeType.CREATED, TIMESTAMP_STRING_PAST)) .addAttributeSorted(new RpslAttribute(AttributeType.LAST_MODIFIED, TIMESTAMP_STRING_PAST)) .get(); final RpslObject input = TEMPLATE; final RpslObject updatedObject = subject.generateAttributes(original, input, update, updateContext); assertThat(updatedObject.findAttribute(AttributeType.CREATED).getValue(), is(TIMESTAMP_STRING_PAST)); assertThat(updatedObject.findAttribute(AttributeType.LAST_MODIFIED).getValue(), is(TIMESTAMP_STRING_PAST)); testHelper.assertNoMessages(); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
TimestampAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { final Action action = updateContext.getAction(update); if (action == Action.CREATE || action == Action.MODIFY || action == Action.DELETE) { final RpslObjectBuilder builder = new RpslObjectBuilder(updatedObject); boolean addWarningsFlag = !updateContext.getPreparedUpdate(update).getOverrideOptions().isSkipLastModified(); generateTimestampAttributes(builder, originalObject, updatedObject, update, updateContext, addWarningsFlag); return builder.get(); } return updatedObject; } @Autowired TimestampAttributeGenerator(final DateTimeProvider dateTimeProvider); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void generate_attributes_for_x509_certificate() { final RpslObject keycert = RpslObject.parse( "key-cert: X509-1\n" + "certif: -----BEGIN CERTIFICATE-----\n" + "certif: MIIC8DCCAlmgAwIBAgICBIQwDQYJKoZIhvcNAQEEBQAwXjELMAkGA1UEBhMCTkwx\n" + "certif: ETAPBgNVBAoTCFJJUEUgTkNDMR0wGwYDVQQLExRSSVBFIE5DQyBMSVIgTmV0d29y\n" + "certif: azEdMBsGA1UEAxMUUklQRSBOQ0MgTElSIFJvb3QgQ0EwHhcNMDQwOTI3MTI1NDAx\n" + "certif: WhcNMDUwOTI3MTI1NDAxWjBsMQswCQYDVQQGEwJOTDERMA8GA1UEChMIUklQRSBO\n" + "certif: Q0MxEDAOBgNVBAsTB01lbWJlcnMxGTAXBgNVBAMTEHp6LmV4YW1wbGUuZGVuaXMx\n" + "certif: HTAbBgkqhkiG9w0BCQEWDmRlbmlzQHJpcGUubmV0MFwwDQYJKoZIhvcNAQEBBQAD\n" + "certif: SwAwSAJBAKdZEYY0pCb5updB808+y8CjNsnraQ/3sBL3/184TqD4AE/TSOdZJ2oU\n" + "certif: HmEpfm6ECkbHOJ1NtMwRjAbkk/rWiBMCAwEAAaOB8jCB7zAJBgNVHRMEAjAAMBEG\n" + "certif: CWCGSAGG+EIBAQQEAwIFoDALBgNVHQ8EBAMCBeAwGgYJYIZIAYb4QgENBA0WC1JJ\n" + "certif: UEUgTkNDIENBMB0GA1UdDgQWBBQk0+qAmXPImzyVTOGARwNPHAX0GTCBhgYDVR0j\n" + "certif: BH8wfYAUI8r2d8CnSt174cfhUw2KNga3Px6hYqRgMF4xCzAJBgNVBAYTAk5MMREw\n" + "certif: DwYDVQQKEwhSSVBFIE5DQzEdMBsGA1UECxMUUklQRSBOQ0MgTElSIE5ldHdvcmsx\n" + "certif: HTAbBgNVBAMTFFJJUEUgTkNDIExJUiBSb290IENBggEAMA0GCSqGSIb3DQEBBAUA\n" + "certif: A4GBAAxojauJHRm3XtPfOCe4B5iz8uVt/EeKhM4gjHGJrUbkAlftLJYUe2Vx8HcH\n" + "certif: O4b+9E098Rt6MfFF+1dYNz7/NgiIpR7BlmdWzPCyhfgxJxTM9m9B7B/6noDU+aaf\n" + "certif: w0L5DyjKGe0dbjMKtaDdgQhxj8aBHNnQVbS9Oqhvmc65XgNi\n" + "certif: -----END CERTIFICATE-----\n" + "mnt-by: UPD-MNT\n" + "source: TEST\n"); when(keyWrapperFactory.createKeyWrapper(keycert, update, updateContext)).thenReturn(X509CertificateWrapper.parse(keycert)); final RpslObject updatedObject = subject.generateAttributes(keycert, update, updateContext); validateAttributeType(updatedObject, AttributeType.METHOD, "X509"); validateAttributeType(updatedObject, AttributeType.FINGERPR, "E7:0F:3B:D4:2F:DD:F5:84:3F:4C:D2:98:78:F3:10:3D"); validateAttributeType(updatedObject, AttributeType.OWNER, "/C=NL/O=RIPE NCC/OU=Members/CN=zz.example.denis/[email protected]"); validateMessages(); }
public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void generate_attributes_for_pgp_certificate() throws Exception { final RpslObject keycert = RpslObject.parse( "key-cert: PGPKEY-5763950D\n" + "certif: -----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "certif: Version: GnuPG v1.4.12 (Darwin)\n" + "certif: \n" + "certif: mQENBFC0yvUBCACn2JKwa5e8Sj3QknEnD5ypvmzNWwYbDhLjmD06wuZxt7Wpgm4+\n" + "certif: yO68swuow09jsrh2DAl2nKQ7YaODEipis0d4H2i0mSswlsC7xbmpx3dRP/yOu4WH\n" + "certif: 2kZciQYxC1NY9J3CNIZxgw6zcghJhtm+LT7OzPS8s3qp+w5nj+vKY09A+BK8yHBN\n" + "certif: E+VPeLOAi+D97s+Da/UZWkZxFJHdV+cAzQ05ARqXKXeadfFdbkx0Eq2R0RZm9R+L\n" + "certif: A9tPUhtw5wk1gFMsN7c5NKwTUQ/0HTTgA5eyKMnTKAdwhIY5/VDxUd1YprnK+Ebd\n" + "certif: YNZh+L39kqoUL6lqeu0dUzYp2Ll7R2IURaXNABEBAAG0I25vcmVwbHlAcmlwZS5u\n" + "certif: ZXQgPG5vcmVwbHlAcmlwZS5uZXQ+iQE4BBMBAgAiBQJQtMr1AhsDBgsJCAcDAgYV\n" + "certif: CAIJCgsEFgIDAQIeAQIXgAAKCRC7zLstV2OVDdjSCACYAyyWr83Df/zzOWGP+qMF\n" + "certif: Vukj8xhaM5f5MGb9FjMKClo6ezT4hLjQ8hfxAAZxndwAXoz46RbDUsAe/aBwdwKB\n" + "certif: 0owcacoaxUd0i+gVEn7CBHPVUfNIuNemcrf1N7aqBkpBLf+NINZ2+3c3t14k1BGe\n" + "certif: xCInxEqHnq4zbUmunCNYjHoKbUj6Aq7janyC7W1MIIAcOY9/PvWQyf3VnERQImgt\n" + "certif: 0fhiekCr6tRbANJ4qFoJQSM/ACoVkpDvb5PHZuZXf/v+XB1DV7gZHjJeZA+Jto5Z\n" + "certif: xrmS5E+HEHVBO8RsBOWDlmWCcZ4k9olxp7/z++mADXPprmLaK8vjQmiC2q/KOTVA\n" + "certif: uQENBFC0yvUBCADTYI6i4baHAkeY2lR2rebpTu1nRHbIET20II8/ZmZDK8E2Lwyv\n" + "certif: eWold6pAWDq9E23J9xAWL4QUQRQ4V+28+lknMySXbU3uFLXGAs6W9PrZXGcmy/12\n" + "certif: pZ+82hHckh+jN9xUTtF89NK/wHh09SAxDa/ST/z/Dj0k3pQWzgBdi36jwEFtHhck\n" + "certif: xFwGst5Cv8SLvA9/DaP75m9VDJsmsSwh/6JqMUb+hY71Dr7oxlIFLdsREsFVzVec\n" + "certif: YHsKINlZKh60dA/Br+CC7fClBycEsR4Z7akw9cPLWIGnjvw2+nq9miE005QLqRy4\n" + "certif: dsrwydbMGplaE/mZc0d2WnNyiCBXAHB5UhmZABEBAAGJAR8EGAECAAkFAlC0yvUC\n" + "certif: GwwACgkQu8y7LVdjlQ1GMAgAgUohj4q3mAJPR6d5pJ8Ig5E3QK87z3lIpgxHbYR4\n" + "certif: HNaR0NIV/GAt/uca11DtIdj3kBAj69QSPqNVRqaZja3NyhNWQM4OPDWKIUZfolF3\n" + "certif: eY2q58kEhxhz3JKJt4z45TnFY2GFGqYwFPQ94z1S9FOJCifL/dLpwPBSKucCac9y\n" + "certif: 6KiKfjEehZ4VqmtM/SvN23GiI/OOdlHL/xnU4NgZ90GHmmQFfdUiX36jWK99LBqC\n" + "certif: RNW8V2MV+rElPVRHev+nw7vgCM0ewXZwQB/bBLbBrayx8LzGtMvAo4kDJ1kpQpip\n" + "certif: a/bmKCK6E+Z9aph5uoke8bKoybIoQ2K3OQ4Mh8yiI+AjiQ==\n" + "certif: =HQmg\n" + "certif: -----END PGP PUBLIC KEY BLOCK-----" + "mnt-by: UPD-MNT\n" + "notify: [email protected]\n" + "source: TEST\n"); when(keyWrapperFactory.createKeyWrapper(keycert, update, updateContext)).thenReturn(PgpPublicKeyWrapper.parse(keycert)); final RpslObject updatedObject = subject.generateAttributes(keycert, update, updateContext); validateAttributeType(updatedObject, AttributeType.METHOD, "PGP"); validateAttributeType(updatedObject, AttributeType.FINGERPR, "884F 8E23 69E5 E6F1 9FB3 63F4 BBCC BB2D 5763 950D"); validateAttributeType(updatedObject, AttributeType.OWNER, "[email protected] <[email protected]>"); validateMessages(); }
public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void correct_owner_attribute() { RpslObject keycert = RpslObject.parse( "key-cert: PGPKEY-5763950D\n" + "owner: [email protected] <[email protected]>\n" + "certif: -----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "certif: Version: GnuPG v1.4.12 (Darwin)\n" + "certif: \n" + "certif: mQENBFC0yvUBCACn2JKwa5e8Sj3QknEnD5ypvmzNWwYbDhLjmD06wuZxt7Wpgm4+\n" + "certif: yO68swuow09jsrh2DAl2nKQ7YaODEipis0d4H2i0mSswlsC7xbmpx3dRP/yOu4WH\n" + "certif: 2kZciQYxC1NY9J3CNIZxgw6zcghJhtm+LT7OzPS8s3qp+w5nj+vKY09A+BK8yHBN\n" + "certif: E+VPeLOAi+D97s+Da/UZWkZxFJHdV+cAzQ05ARqXKXeadfFdbkx0Eq2R0RZm9R+L\n" + "certif: A9tPUhtw5wk1gFMsN7c5NKwTUQ/0HTTgA5eyKMnTKAdwhIY5/VDxUd1YprnK+Ebd\n" + "certif: YNZh+L39kqoUL6lqeu0dUzYp2Ll7R2IURaXNABEBAAG0I25vcmVwbHlAcmlwZS5u\n" + "certif: ZXQgPG5vcmVwbHlAcmlwZS5uZXQ+iQE4BBMBAgAiBQJQtMr1AhsDBgsJCAcDAgYV\n" + "certif: CAIJCgsEFgIDAQIeAQIXgAAKCRC7zLstV2OVDdjSCACYAyyWr83Df/zzOWGP+qMF\n" + "certif: Vukj8xhaM5f5MGb9FjMKClo6ezT4hLjQ8hfxAAZxndwAXoz46RbDUsAe/aBwdwKB\n" + "certif: 0owcacoaxUd0i+gVEn7CBHPVUfNIuNemcrf1N7aqBkpBLf+NINZ2+3c3t14k1BGe\n" + "certif: xCInxEqHnq4zbUmunCNYjHoKbUj6Aq7janyC7W1MIIAcOY9/PvWQyf3VnERQImgt\n" + "certif: 0fhiekCr6tRbANJ4qFoJQSM/ACoVkpDvb5PHZuZXf/v+XB1DV7gZHjJeZA+Jto5Z\n" + "certif: xrmS5E+HEHVBO8RsBOWDlmWCcZ4k9olxp7/z++mADXPprmLaK8vjQmiC2q/KOTVA\n" + "certif: uQENBFC0yvUBCADTYI6i4baHAkeY2lR2rebpTu1nRHbIET20II8/ZmZDK8E2Lwyv\n" + "certif: eWold6pAWDq9E23J9xAWL4QUQRQ4V+28+lknMySXbU3uFLXGAs6W9PrZXGcmy/12\n" + "certif: pZ+82hHckh+jN9xUTtF89NK/wHh09SAxDa/ST/z/Dj0k3pQWzgBdi36jwEFtHhck\n" + "certif: xFwGst5Cv8SLvA9/DaP75m9VDJsmsSwh/6JqMUb+hY71Dr7oxlIFLdsREsFVzVec\n" + "certif: YHsKINlZKh60dA/Br+CC7fClBycEsR4Z7akw9cPLWIGnjvw2+nq9miE005QLqRy4\n" + "certif: dsrwydbMGplaE/mZc0d2WnNyiCBXAHB5UhmZABEBAAGJAR8EGAECAAkFAlC0yvUC\n" + "certif: GwwACgkQu8y7LVdjlQ1GMAgAgUohj4q3mAJPR6d5pJ8Ig5E3QK87z3lIpgxHbYR4\n" + "certif: HNaR0NIV/GAt/uca11DtIdj3kBAj69QSPqNVRqaZja3NyhNWQM4OPDWKIUZfolF3\n" + "certif: eY2q58kEhxhz3JKJt4z45TnFY2GFGqYwFPQ94z1S9FOJCifL/dLpwPBSKucCac9y\n" + "certif: 6KiKfjEehZ4VqmtM/SvN23GiI/OOdlHL/xnU4NgZ90GHmmQFfdUiX36jWK99LBqC\n" + "certif: RNW8V2MV+rElPVRHev+nw7vgCM0ewXZwQB/bBLbBrayx8LzGtMvAo4kDJ1kpQpip\n" + "certif: a/bmKCK6E+Z9aph5uoke8bKoybIoQ2K3OQ4Mh8yiI+AjiQ==\n" + "certif: =HQmg\n" + "certif: -----END PGP PUBLIC KEY BLOCK-----\n" + "mnt-by: UPD-MNT\n" + "notify: [email protected]\n" + "source: TEST\n"); when(keyWrapperFactory.createKeyWrapper(keycert, update, updateContext)).thenReturn(PgpPublicKeyWrapper.parse(keycert)); final RpslObject updatedObject = subject.generateAttributes(keycert, update, updateContext); validateAttributeType(updatedObject, AttributeType.METHOD, "PGP"); validateAttributeType(updatedObject, AttributeType.FINGERPR, "884F 8E23 69E5 E6F1 9FB3 63F4 BBCC BB2D 5763 950D"); validateAttributeType(updatedObject, AttributeType.OWNER, "[email protected] <[email protected]>"); }
public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void invalid_owner_attribute() { RpslObject keycert = RpslObject.parse( "key-cert: PGPKEY-5763950D\n" + "owner: [email protected] <[email protected]>\n" + "owner: invalid\n" + "certif: -----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "certif: Version: GnuPG v1.4.12 (Darwin)\n" + "certif: \n" + "certif: mQENBFC0yvUBCACn2JKwa5e8Sj3QknEnD5ypvmzNWwYbDhLjmD06wuZxt7Wpgm4+\n" + "certif: yO68swuow09jsrh2DAl2nKQ7YaODEipis0d4H2i0mSswlsC7xbmpx3dRP/yOu4WH\n" + "certif: 2kZciQYxC1NY9J3CNIZxgw6zcghJhtm+LT7OzPS8s3qp+w5nj+vKY09A+BK8yHBN\n" + "certif: E+VPeLOAi+D97s+Da/UZWkZxFJHdV+cAzQ05ARqXKXeadfFdbkx0Eq2R0RZm9R+L\n" + "certif: A9tPUhtw5wk1gFMsN7c5NKwTUQ/0HTTgA5eyKMnTKAdwhIY5/VDxUd1YprnK+Ebd\n" + "certif: YNZh+L39kqoUL6lqeu0dUzYp2Ll7R2IURaXNABEBAAG0I25vcmVwbHlAcmlwZS5u\n" + "certif: ZXQgPG5vcmVwbHlAcmlwZS5uZXQ+iQE4BBMBAgAiBQJQtMr1AhsDBgsJCAcDAgYV\n" + "certif: CAIJCgsEFgIDAQIeAQIXgAAKCRC7zLstV2OVDdjSCACYAyyWr83Df/zzOWGP+qMF\n" + "certif: Vukj8xhaM5f5MGb9FjMKClo6ezT4hLjQ8hfxAAZxndwAXoz46RbDUsAe/aBwdwKB\n" + "certif: 0owcacoaxUd0i+gVEn7CBHPVUfNIuNemcrf1N7aqBkpBLf+NINZ2+3c3t14k1BGe\n" + "certif: xCInxEqHnq4zbUmunCNYjHoKbUj6Aq7janyC7W1MIIAcOY9/PvWQyf3VnERQImgt\n" + "certif: 0fhiekCr6tRbANJ4qFoJQSM/ACoVkpDvb5PHZuZXf/v+XB1DV7gZHjJeZA+Jto5Z\n" + "certif: xrmS5E+HEHVBO8RsBOWDlmWCcZ4k9olxp7/z++mADXPprmLaK8vjQmiC2q/KOTVA\n" + "certif: uQENBFC0yvUBCADTYI6i4baHAkeY2lR2rebpTu1nRHbIET20II8/ZmZDK8E2Lwyv\n" + "certif: eWold6pAWDq9E23J9xAWL4QUQRQ4V+28+lknMySXbU3uFLXGAs6W9PrZXGcmy/12\n" + "certif: pZ+82hHckh+jN9xUTtF89NK/wHh09SAxDa/ST/z/Dj0k3pQWzgBdi36jwEFtHhck\n" + "certif: xFwGst5Cv8SLvA9/DaP75m9VDJsmsSwh/6JqMUb+hY71Dr7oxlIFLdsREsFVzVec\n" + "certif: YHsKINlZKh60dA/Br+CC7fClBycEsR4Z7akw9cPLWIGnjvw2+nq9miE005QLqRy4\n" + "certif: dsrwydbMGplaE/mZc0d2WnNyiCBXAHB5UhmZABEBAAGJAR8EGAECAAkFAlC0yvUC\n" + "certif: GwwACgkQu8y7LVdjlQ1GMAgAgUohj4q3mAJPR6d5pJ8Ig5E3QK87z3lIpgxHbYR4\n" + "certif: HNaR0NIV/GAt/uca11DtIdj3kBAj69QSPqNVRqaZja3NyhNWQM4OPDWKIUZfolF3\n" + "certif: eY2q58kEhxhz3JKJt4z45TnFY2GFGqYwFPQ94z1S9FOJCifL/dLpwPBSKucCac9y\n" + "certif: 6KiKfjEehZ4VqmtM/SvN23GiI/OOdlHL/xnU4NgZ90GHmmQFfdUiX36jWK99LBqC\n" + "certif: RNW8V2MV+rElPVRHev+nw7vgCM0ewXZwQB/bBLbBrayx8LzGtMvAo4kDJ1kpQpip\n" + "certif: a/bmKCK6E+Z9aph5uoke8bKoybIoQ2K3OQ4Mh8yiI+AjiQ==\n" + "certif: =HQmg\n" + "certif: -----END PGP PUBLIC KEY BLOCK-----\n" + "mnt-by: UPD-MNT\n" + "notify: [email protected]\n" + "source: TEST\n"); when(keyWrapperFactory.createKeyWrapper(keycert, update, updateContext)).thenReturn(PgpPublicKeyWrapper.parse(keycert)); final RpslObject updatedObject = subject.generateAttributes(keycert, update, updateContext); validateAttributeType(updatedObject, AttributeType.METHOD, "PGP"); validateAttributeType(updatedObject, AttributeType.FINGERPR, "884F 8E23 69E5 E6F1 9FB3 63F4 BBCC BB2D 5763 950D"); validateAttributeType(updatedObject, AttributeType.OWNER, "[email protected] <[email protected]>"); validateMessages(ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.OWNER)); }
public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void correct_fingerprint_attribute() { RpslObject keycert = RpslObject.parse("" + "key-cert: PGPKEY-5763950D\n" + "fingerpr: 884F 8E23 69E5 E6F1 9FB3 63F4 BBCC BB2D 5763 950D\n" + "certif: -----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "certif: Version: GnuPG v1\n" + "certif: \n" + "certif: mQENBFC0yvUBCACn2JKwa5e8Sj3QknEnD5ypvmzNWwYbDhLjmD06wuZxt7Wpgm4+\n" + "certif: yO68swuow09jsrh2DAl2nKQ7YaODEipis0d4H2i0mSswlsC7xbmpx3dRP/yOu4WH\n" + "certif: 2kZciQYxC1NY9J3CNIZxgw6zcghJhtm+LT7OzPS8s3qp+w5nj+vKY09A+BK8yHBN\n" + "certif: E+VPeLOAi+D97s+Da/UZWkZxFJHdV+cAzQ05ARqXKXeadfFdbkx0Eq2R0RZm9R+L\n" + "certif: A9tPUhtw5wk1gFMsN7c5NKwTUQ/0HTTgA5eyKMnTKAdwhIY5/VDxUd1YprnK+Ebd\n" + "certif: YNZh+L39kqoUL6lqeu0dUzYp2Ll7R2IURaXNABEBAAG0I25vcmVwbHlAcmlwZS5u\n" + "certif: ZXQgPG5vcmVwbHlAcmlwZS5uZXQ+iQE4BBMBAgAiBQJQtMr1AhsDBgsJCAcDAgYV\n" + "certif: CAIJCgsEFgIDAQIeAQIXgAAKCRC7zLstV2OVDdjSCACYAyyWr83Df/zzOWGP+qMF\n" + "certif: Vukj8xhaM5f5MGb9FjMKClo6ezT4hLjQ8hfxAAZxndwAXoz46RbDUsAe/aBwdwKB\n" + "certif: 0owcacoaxUd0i+gVEn7CBHPVUfNIuNemcrf1N7aqBkpBLf+NINZ2+3c3t14k1BGe\n" + "certif: xCInxEqHnq4zbUmunCNYjHoKbUj6Aq7janyC7W1MIIAcOY9/PvWQyf3VnERQImgt\n" + "certif: 0fhiekCr6tRbANJ4qFoJQSM/ACoVkpDvb5PHZuZXf/v+XB1DV7gZHjJeZA+Jto5Z\n" + "certif: xrmS5E+HEHVBO8RsBOWDlmWCcZ4k9olxp7/z++mADXPprmLaK8vjQmiC2q/KOTVA\n" + "certif: uQENBFC0yvUBCADTYI6i4baHAkeY2lR2rebpTu1nRHbIET20II8/ZmZDK8E2Lwyv\n" + "certif: eWold6pAWDq9E23J9xAWL4QUQRQ4V+28+lknMySXbU3uFLXGAs6W9PrZXGcmy/12\n" + "certif: pZ+82hHckh+jN9xUTtF89NK/wHh09SAxDa/ST/z/Dj0k3pQWzgBdi36jwEFtHhck\n" + "certif: xFwGst5Cv8SLvA9/DaP75m9VDJsmsSwh/6JqMUb+hY71Dr7oxlIFLdsREsFVzVec\n" + "certif: YHsKINlZKh60dA/Br+CC7fClBycEsR4Z7akw9cPLWIGnjvw2+nq9miE005QLqRy4\n" + "certif: dsrwydbMGplaE/mZc0d2WnNyiCBXAHB5UhmZABEBAAGJAR8EGAECAAkFAlC0yvUC\n" + "certif: GwwACgkQu8y7LVdjlQ1GMAgAgUohj4q3mAJPR6d5pJ8Ig5E3QK87z3lIpgxHbYR4\n" + "certif: HNaR0NIV/GAt/uca11DtIdj3kBAj69QSPqNVRqaZja3NyhNWQM4OPDWKIUZfolF3\n" + "certif: eY2q58kEhxhz3JKJt4z45TnFY2GFGqYwFPQ94z1S9FOJCifL/dLpwPBSKucCac9y\n" + "certif: 6KiKfjEehZ4VqmtM/SvN23GiI/OOdlHL/xnU4NgZ90GHmmQFfdUiX36jWK99LBqC\n" + "certif: RNW8V2MV+rElPVRHev+nw7vgCM0ewXZwQB/bBLbBrayx8LzGtMvAo4kDJ1kpQpip\n" + "certif: a/bmKCK6E+Z9aph5uoke8bKoybIoQ2K3OQ4Mh8yiI+AjiQ==\n" + "certif: =HQmg\n" + "certif: -----END PGP PUBLIC KEY BLOCK-----\n" + "mnt-by: UPD-MNT\n" + "notify: [email protected]\n" + "source: TEST\n"); when(keyWrapperFactory.createKeyWrapper(keycert, update, updateContext)).thenReturn(PgpPublicKeyWrapper.parse(keycert)); final RpslObject updatedObject = subject.generateAttributes(keycert, update, updateContext); validateAttributeType(updatedObject, AttributeType.METHOD, "PGP"); validateAttributeType(updatedObject, AttributeType.FINGERPR, "884F 8E23 69E5 E6F1 9FB3 63F4 BBCC BB2D 5763 950D"); validateAttributeType(updatedObject, AttributeType.OWNER, "[email protected] <[email protected]>"); }
public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void invalid_fingerprint_attribute() { RpslObject keycert = RpslObject.parse(""+ "key-cert: PGPKEY-5763950D\n" + "owner: [email protected] <[email protected]>\n" + "fingerpr: abcd\n" + "certif: -----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "certif: Version: GnuPG v1.4.12 (Darwin)\n" + "certif: \n" + "certif: mQENBFC0yvUBCACn2JKwa5e8Sj3QknEnD5ypvmzNWwYbDhLjmD06wuZxt7Wpgm4+\n" + "certif: yO68swuow09jsrh2DAl2nKQ7YaODEipis0d4H2i0mSswlsC7xbmpx3dRP/yOu4WH\n" + "certif: 2kZciQYxC1NY9J3CNIZxgw6zcghJhtm+LT7OzPS8s3qp+w5nj+vKY09A+BK8yHBN\n" + "certif: E+VPeLOAi+D97s+Da/UZWkZxFJHdV+cAzQ05ARqXKXeadfFdbkx0Eq2R0RZm9R+L\n" + "certif: A9tPUhtw5wk1gFMsN7c5NKwTUQ/0HTTgA5eyKMnTKAdwhIY5/VDxUd1YprnK+Ebd\n" + "certif: YNZh+L39kqoUL6lqeu0dUzYp2Ll7R2IURaXNABEBAAG0I25vcmVwbHlAcmlwZS5u\n" + "certif: ZXQgPG5vcmVwbHlAcmlwZS5uZXQ+iQE4BBMBAgAiBQJQtMr1AhsDBgsJCAcDAgYV\n" + "certif: CAIJCgsEFgIDAQIeAQIXgAAKCRC7zLstV2OVDdjSCACYAyyWr83Df/zzOWGP+qMF\n" + "certif: Vukj8xhaM5f5MGb9FjMKClo6ezT4hLjQ8hfxAAZxndwAXoz46RbDUsAe/aBwdwKB\n" + "certif: 0owcacoaxUd0i+gVEn7CBHPVUfNIuNemcrf1N7aqBkpBLf+NINZ2+3c3t14k1BGe\n" + "certif: xCInxEqHnq4zbUmunCNYjHoKbUj6Aq7janyC7W1MIIAcOY9/PvWQyf3VnERQImgt\n" + "certif: 0fhiekCr6tRbANJ4qFoJQSM/ACoVkpDvb5PHZuZXf/v+XB1DV7gZHjJeZA+Jto5Z\n" + "certif: xrmS5E+HEHVBO8RsBOWDlmWCcZ4k9olxp7/z++mADXPprmLaK8vjQmiC2q/KOTVA\n" + "certif: uQENBFC0yvUBCADTYI6i4baHAkeY2lR2rebpTu1nRHbIET20II8/ZmZDK8E2Lwyv\n" + "certif: eWold6pAWDq9E23J9xAWL4QUQRQ4V+28+lknMySXbU3uFLXGAs6W9PrZXGcmy/12\n" + "certif: pZ+82hHckh+jN9xUTtF89NK/wHh09SAxDa/ST/z/Dj0k3pQWzgBdi36jwEFtHhck\n" + "certif: xFwGst5Cv8SLvA9/DaP75m9VDJsmsSwh/6JqMUb+hY71Dr7oxlIFLdsREsFVzVec\n" + "certif: YHsKINlZKh60dA/Br+CC7fClBycEsR4Z7akw9cPLWIGnjvw2+nq9miE005QLqRy4\n" + "certif: dsrwydbMGplaE/mZc0d2WnNyiCBXAHB5UhmZABEBAAGJAR8EGAECAAkFAlC0yvUC\n" + "certif: GwwACgkQu8y7LVdjlQ1GMAgAgUohj4q3mAJPR6d5pJ8Ig5E3QK87z3lIpgxHbYR4\n" + "certif: HNaR0NIV/GAt/uca11DtIdj3kBAj69QSPqNVRqaZja3NyhNWQM4OPDWKIUZfolF3\n" + "certif: eY2q58kEhxhz3JKJt4z45TnFY2GFGqYwFPQ94z1S9FOJCifL/dLpwPBSKucCac9y\n" + "certif: 6KiKfjEehZ4VqmtM/SvN23GiI/OOdlHL/xnU4NgZ90GHmmQFfdUiX36jWK99LBqC\n" + "certif: RNW8V2MV+rElPVRHev+nw7vgCM0ewXZwQB/bBLbBrayx8LzGtMvAo4kDJ1kpQpip\n" + "certif: a/bmKCK6E+Z9aph5uoke8bKoybIoQ2K3OQ4Mh8yiI+AjiQ==\n" + "certif: =HQmg\n" + "certif: -----END PGP PUBLIC KEY BLOCK-----\n" + "mnt-by: UPD-MNT\n" + "notify: [email protected]\n" + "source: TEST\n"); when(keyWrapperFactory.createKeyWrapper(keycert, update, updateContext)).thenReturn(PgpPublicKeyWrapper.parse(keycert)); final RpslObject updatedObject = subject.generateAttributes(keycert, update, updateContext); validateAttributeType(updatedObject, AttributeType.METHOD, "PGP"); validateAttributeType(updatedObject, AttributeType.FINGERPR, "884F 8E23 69E5 E6F1 9FB3 63F4 BBCC BB2D 5763 950D"); validateAttributeType(updatedObject, AttributeType.OWNER, "[email protected] <[email protected]>"); validateMessages(ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.FINGERPR)); }
public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void transform_inetnum_leading_zeroes() { final RpslObject rpslObject = RpslObject.parse("inetnum: 010.0.0.01 - 193.255.255.098"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.INETNUM).toString(), is("10.0.0.1 - 193.255.255.98")); verify(objectMessages).addMessage(result.getTypeAttribute(), ValidationMessages.attributeValueConverted("010.0.0.01 - 193.255.255.098", "10.0.0.1 - 193.255.255.98")); 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 correct_method_attribute() { RpslObject keycert = RpslObject.parse(""+ "key-cert: PGPKEY-5763950D\n" + "owner: [email protected] <[email protected]>\n" + "method: PGP\n" + "certif: -----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "certif: Version: GnuPG v1.4.12 (Darwin)\n" + "certif: \n" + "certif: mQENBFC0yvUBCACn2JKwa5e8Sj3QknEnD5ypvmzNWwYbDhLjmD06wuZxt7Wpgm4+\n" + "certif: yO68swuow09jsrh2DAl2nKQ7YaODEipis0d4H2i0mSswlsC7xbmpx3dRP/yOu4WH\n" + "certif: 2kZciQYxC1NY9J3CNIZxgw6zcghJhtm+LT7OzPS8s3qp+w5nj+vKY09A+BK8yHBN\n" + "certif: E+VPeLOAi+D97s+Da/UZWkZxFJHdV+cAzQ05ARqXKXeadfFdbkx0Eq2R0RZm9R+L\n" + "certif: A9tPUhtw5wk1gFMsN7c5NKwTUQ/0HTTgA5eyKMnTKAdwhIY5/VDxUd1YprnK+Ebd\n" + "certif: YNZh+L39kqoUL6lqeu0dUzYp2Ll7R2IURaXNABEBAAG0I25vcmVwbHlAcmlwZS5u\n" + "certif: ZXQgPG5vcmVwbHlAcmlwZS5uZXQ+iQE4BBMBAgAiBQJQtMr1AhsDBgsJCAcDAgYV\n" + "certif: CAIJCgsEFgIDAQIeAQIXgAAKCRC7zLstV2OVDdjSCACYAyyWr83Df/zzOWGP+qMF\n" + "certif: Vukj8xhaM5f5MGb9FjMKClo6ezT4hLjQ8hfxAAZxndwAXoz46RbDUsAe/aBwdwKB\n" + "certif: 0owcacoaxUd0i+gVEn7CBHPVUfNIuNemcrf1N7aqBkpBLf+NINZ2+3c3t14k1BGe\n" + "certif: xCInxEqHnq4zbUmunCNYjHoKbUj6Aq7janyC7W1MIIAcOY9/PvWQyf3VnERQImgt\n" + "certif: 0fhiekCr6tRbANJ4qFoJQSM/ACoVkpDvb5PHZuZXf/v+XB1DV7gZHjJeZA+Jto5Z\n" + "certif: xrmS5E+HEHVBO8RsBOWDlmWCcZ4k9olxp7/z++mADXPprmLaK8vjQmiC2q/KOTVA\n" + "certif: uQENBFC0yvUBCADTYI6i4baHAkeY2lR2rebpTu1nRHbIET20II8/ZmZDK8E2Lwyv\n" + "certif: eWold6pAWDq9E23J9xAWL4QUQRQ4V+28+lknMySXbU3uFLXGAs6W9PrZXGcmy/12\n" + "certif: pZ+82hHckh+jN9xUTtF89NK/wHh09SAxDa/ST/z/Dj0k3pQWzgBdi36jwEFtHhck\n" + "certif: xFwGst5Cv8SLvA9/DaP75m9VDJsmsSwh/6JqMUb+hY71Dr7oxlIFLdsREsFVzVec\n" + "certif: YHsKINlZKh60dA/Br+CC7fClBycEsR4Z7akw9cPLWIGnjvw2+nq9miE005QLqRy4\n" + "certif: dsrwydbMGplaE/mZc0d2WnNyiCBXAHB5UhmZABEBAAGJAR8EGAECAAkFAlC0yvUC\n" + "certif: GwwACgkQu8y7LVdjlQ1GMAgAgUohj4q3mAJPR6d5pJ8Ig5E3QK87z3lIpgxHbYR4\n" + "certif: HNaR0NIV/GAt/uca11DtIdj3kBAj69QSPqNVRqaZja3NyhNWQM4OPDWKIUZfolF3\n" + "certif: eY2q58kEhxhz3JKJt4z45TnFY2GFGqYwFPQ94z1S9FOJCifL/dLpwPBSKucCac9y\n" + "certif: 6KiKfjEehZ4VqmtM/SvN23GiI/OOdlHL/xnU4NgZ90GHmmQFfdUiX36jWK99LBqC\n" + "certif: RNW8V2MV+rElPVRHev+nw7vgCM0ewXZwQB/bBLbBrayx8LzGtMvAo4kDJ1kpQpip\n" + "certif: a/bmKCK6E+Z9aph5uoke8bKoybIoQ2K3OQ4Mh8yiI+AjiQ==\n" + "certif: =HQmg\n" + "certif: -----END PGP PUBLIC KEY BLOCK-----\n" + "mnt-by: UPD-MNT\n" + "notify: [email protected]\n" + "source: TEST\n"); when(keyWrapperFactory.createKeyWrapper(keycert, update, updateContext)).thenReturn(PgpPublicKeyWrapper.parse(keycert)); final RpslObject updatedObject = subject.generateAttributes(keycert, update, updateContext); validateAttributeType(updatedObject, AttributeType.METHOD, "PGP"); validateAttributeType(updatedObject, AttributeType.FINGERPR, "884F 8E23 69E5 E6F1 9FB3 63F4 BBCC BB2D 5763 950D"); validateAttributeType(updatedObject, AttributeType.OWNER, "[email protected] <[email protected]>"); }
public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void invalid_method_attribute() { RpslObject keycert = RpslObject.parse( "key-cert: PGPKEY-5763950D\n" + "owner: [email protected] <[email protected]>\n" + "method: invalid method\n" + "certif: -----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "certif: Version: GnuPG v1.4.12 (Darwin)\n" + "certif: \n" + "certif: mQENBFC0yvUBCACn2JKwa5e8Sj3QknEnD5ypvmzNWwYbDhLjmD06wuZxt7Wpgm4+\n" + "certif: yO68swuow09jsrh2DAl2nKQ7YaODEipis0d4H2i0mSswlsC7xbmpx3dRP/yOu4WH\n" + "certif: 2kZciQYxC1NY9J3CNIZxgw6zcghJhtm+LT7OzPS8s3qp+w5nj+vKY09A+BK8yHBN\n" + "certif: E+VPeLOAi+D97s+Da/UZWkZxFJHdV+cAzQ05ARqXKXeadfFdbkx0Eq2R0RZm9R+L\n" + "certif: A9tPUhtw5wk1gFMsN7c5NKwTUQ/0HTTgA5eyKMnTKAdwhIY5/VDxUd1YprnK+Ebd\n" + "certif: YNZh+L39kqoUL6lqeu0dUzYp2Ll7R2IURaXNABEBAAG0I25vcmVwbHlAcmlwZS5u\n" + "certif: ZXQgPG5vcmVwbHlAcmlwZS5uZXQ+iQE4BBMBAgAiBQJQtMr1AhsDBgsJCAcDAgYV\n" + "certif: CAIJCgsEFgIDAQIeAQIXgAAKCRC7zLstV2OVDdjSCACYAyyWr83Df/zzOWGP+qMF\n" + "certif: Vukj8xhaM5f5MGb9FjMKClo6ezT4hLjQ8hfxAAZxndwAXoz46RbDUsAe/aBwdwKB\n" + "certif: 0owcacoaxUd0i+gVEn7CBHPVUfNIuNemcrf1N7aqBkpBLf+NINZ2+3c3t14k1BGe\n" + "certif: xCInxEqHnq4zbUmunCNYjHoKbUj6Aq7janyC7W1MIIAcOY9/PvWQyf3VnERQImgt\n" + "certif: 0fhiekCr6tRbANJ4qFoJQSM/ACoVkpDvb5PHZuZXf/v+XB1DV7gZHjJeZA+Jto5Z\n" + "certif: xrmS5E+HEHVBO8RsBOWDlmWCcZ4k9olxp7/z++mADXPprmLaK8vjQmiC2q/KOTVA\n" + "certif: uQENBFC0yvUBCADTYI6i4baHAkeY2lR2rebpTu1nRHbIET20II8/ZmZDK8E2Lwyv\n" + "certif: eWold6pAWDq9E23J9xAWL4QUQRQ4V+28+lknMySXbU3uFLXGAs6W9PrZXGcmy/12\n" + "certif: pZ+82hHckh+jN9xUTtF89NK/wHh09SAxDa/ST/z/Dj0k3pQWzgBdi36jwEFtHhck\n" + "certif: xFwGst5Cv8SLvA9/DaP75m9VDJsmsSwh/6JqMUb+hY71Dr7oxlIFLdsREsFVzVec\n" + "certif: YHsKINlZKh60dA/Br+CC7fClBycEsR4Z7akw9cPLWIGnjvw2+nq9miE005QLqRy4\n" + "certif: dsrwydbMGplaE/mZc0d2WnNyiCBXAHB5UhmZABEBAAGJAR8EGAECAAkFAlC0yvUC\n" + "certif: GwwACgkQu8y7LVdjlQ1GMAgAgUohj4q3mAJPR6d5pJ8Ig5E3QK87z3lIpgxHbYR4\n" + "certif: HNaR0NIV/GAt/uca11DtIdj3kBAj69QSPqNVRqaZja3NyhNWQM4OPDWKIUZfolF3\n" + "certif: eY2q58kEhxhz3JKJt4z45TnFY2GFGqYwFPQ94z1S9FOJCifL/dLpwPBSKucCac9y\n" + "certif: 6KiKfjEehZ4VqmtM/SvN23GiI/OOdlHL/xnU4NgZ90GHmmQFfdUiX36jWK99LBqC\n" + "certif: RNW8V2MV+rElPVRHev+nw7vgCM0ewXZwQB/bBLbBrayx8LzGtMvAo4kDJ1kpQpip\n" + "certif: a/bmKCK6E+Z9aph5uoke8bKoybIoQ2K3OQ4Mh8yiI+AjiQ==\n" + "certif: =HQmg\n" + "certif: -----END PGP PUBLIC KEY BLOCK-----\n" + "mnt-by: UPD-MNT\n" + "notify: [email protected]\n" + "source: TEST\n"); when(keyWrapperFactory.createKeyWrapper(keycert, update, updateContext)).thenReturn(PgpPublicKeyWrapper.parse(keycert)); final RpslObject updatedObject = subject.generateAttributes(keycert, update, updateContext); validateAttributeType(updatedObject, AttributeType.METHOD, "PGP"); validateAttributeType(updatedObject, AttributeType.FINGERPR, "884F 8E23 69E5 E6F1 9FB3 63F4 BBCC BB2D 5763 950D"); validateAttributeType(updatedObject, AttributeType.OWNER, "[email protected] <[email protected]>"); validateMessages(ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.METHOD)); }
public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void invalid_attribute_is_ignored() { RpslObject keycert = RpslObject.parse( "key-cert: PGPKEY-5763950D\n" + "invalid-attribute: invalid\n" + "certif: -----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "certif: Version: GnuPG v1.4.12 (Darwin)\n" + "certif: \n" + "certif: mQENBFC0yvUBCACn2JKwa5e8Sj3QknEnD5ypvmzNWwYbDhLjmD06wuZxt7Wpgm4+\n" + "certif: yO68swuow09jsrh2DAl2nKQ7YaODEipis0d4H2i0mSswlsC7xbmpx3dRP/yOu4WH\n" + "certif: 2kZciQYxC1NY9J3CNIZxgw6zcghJhtm+LT7OzPS8s3qp+w5nj+vKY09A+BK8yHBN\n" + "certif: E+VPeLOAi+D97s+Da/UZWkZxFJHdV+cAzQ05ARqXKXeadfFdbkx0Eq2R0RZm9R+L\n" + "certif: A9tPUhtw5wk1gFMsN7c5NKwTUQ/0HTTgA5eyKMnTKAdwhIY5/VDxUd1YprnK+Ebd\n" + "certif: YNZh+L39kqoUL6lqeu0dUzYp2Ll7R2IURaXNABEBAAG0I25vcmVwbHlAcmlwZS5u\n" + "certif: ZXQgPG5vcmVwbHlAcmlwZS5uZXQ+iQE4BBMBAgAiBQJQtMr1AhsDBgsJCAcDAgYV\n" + "certif: CAIJCgsEFgIDAQIeAQIXgAAKCRC7zLstV2OVDdjSCACYAyyWr83Df/zzOWGP+qMF\n" + "certif: Vukj8xhaM5f5MGb9FjMKClo6ezT4hLjQ8hfxAAZxndwAXoz46RbDUsAe/aBwdwKB\n" + "certif: 0owcacoaxUd0i+gVEn7CBHPVUfNIuNemcrf1N7aqBkpBLf+NINZ2+3c3t14k1BGe\n" + "certif: xCInxEqHnq4zbUmunCNYjHoKbUj6Aq7janyC7W1MIIAcOY9/PvWQyf3VnERQImgt\n" + "certif: 0fhiekCr6tRbANJ4qFoJQSM/ACoVkpDvb5PHZuZXf/v+XB1DV7gZHjJeZA+Jto5Z\n" + "certif: xrmS5E+HEHVBO8RsBOWDlmWCcZ4k9olxp7/z++mADXPprmLaK8vjQmiC2q/KOTVA\n" + "certif: uQENBFC0yvUBCADTYI6i4baHAkeY2lR2rebpTu1nRHbIET20II8/ZmZDK8E2Lwyv\n" + "certif: eWold6pAWDq9E23J9xAWL4QUQRQ4V+28+lknMySXbU3uFLXGAs6W9PrZXGcmy/12\n" + "certif: pZ+82hHckh+jN9xUTtF89NK/wHh09SAxDa/ST/z/Dj0k3pQWzgBdi36jwEFtHhck\n" + "certif: xFwGst5Cv8SLvA9/DaP75m9VDJsmsSwh/6JqMUb+hY71Dr7oxlIFLdsREsFVzVec\n" + "certif: YHsKINlZKh60dA/Br+CC7fClBycEsR4Z7akw9cPLWIGnjvw2+nq9miE005QLqRy4\n" + "certif: dsrwydbMGplaE/mZc0d2WnNyiCBXAHB5UhmZABEBAAGJAR8EGAECAAkFAlC0yvUC\n" + "certif: GwwACgkQu8y7LVdjlQ1GMAgAgUohj4q3mAJPR6d5pJ8Ig5E3QK87z3lIpgxHbYR4\n" + "certif: HNaR0NIV/GAt/uca11DtIdj3kBAj69QSPqNVRqaZja3NyhNWQM4OPDWKIUZfolF3\n" + "certif: eY2q58kEhxhz3JKJt4z45TnFY2GFGqYwFPQ94z1S9FOJCifL/dLpwPBSKucCac9y\n" + "certif: 6KiKfjEehZ4VqmtM/SvN23GiI/OOdlHL/xnU4NgZ90GHmmQFfdUiX36jWK99LBqC\n" + "certif: RNW8V2MV+rElPVRHev+nw7vgCM0ewXZwQB/bBLbBrayx8LzGtMvAo4kDJ1kpQpip\n" + "certif: a/bmKCK6E+Z9aph5uoke8bKoybIoQ2K3OQ4Mh8yiI+AjiQ==\n" + "certif: =HQmg\n" + "certif: -----END PGP PUBLIC KEY BLOCK-----\n" + "mnt-by: UPD-MNT\n" + "notify: [email protected]\n" + "source: TEST\n"); when(keyWrapperFactory.createKeyWrapper(keycert, update, updateContext)).thenReturn(PgpPublicKeyWrapper.parse(keycert)); final RpslObject updatedObject = subject.generateAttributes(keycert, update, updateContext); validateAttributeType(updatedObject, AttributeType.METHOD, "PGP"); validateAttributeType(updatedObject, AttributeType.FINGERPR, "884F 8E23 69E5 E6F1 9FB3 63F4 BBCC BB2D 5763 950D"); validateAttributeType(updatedObject, AttributeType.OWNER, "[email protected] <[email protected]>"); }
public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void public_key_with_multiple_owners() { RpslObject keycert = RpslObject.parse( "key-cert: PGPKEY-5763950D\n" + "owner: invalid\n" + "certif: -----BEGIN PGP PUBLIC KEY BLOCK-----\n" + "certif: Version: GnuPG v1.4.15 (Darwin)\n" + "certif: Comment: GPGTools - http: "certif: \n" + "certif: mI0EUqWQnQEEAMKfJ/wK0TuUxgTbDdE5LjDuoDNTNfGr0iw2fNSlsxNME3bpRKW9\n" + "certif: YjgllY7D0wbx4BIdV7MUOaYMDEEPCkApHNwK256Ve2S4WxLCWpyGMiXECs6r4Fj+\n" + "certif: Bkyc2O4bxuXoQocbnKVOiFI0SPpkX1pa0IJleqAq5cz77zK1Ha5OOMErABEBAAG0\n" + "certif: G0FkbWluIFVzZXIgPGFkbWluQHJpcGUubmV0Poi4BBMBAgAiBQJSpZCdAhsDBgsJ\n" + "certif: CAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRDHIn7s6l+7lIpAA/4lExw9e9L2pSsx\n" + "certif: JsDZe0JqukvI6bipuFWa26brAlef+6NtDJjQWvfLAAEoeDBlBchHZ4tpl1Wiyt3J\n" + "certif: kIyeIYDIbb9e/w+romlDlyTQo+8/U1iAdb+TOGzacgbJoykU6OjaGbuMbWn0bu2S\n" + "certif: cmnH08tu0Ydhj04v5yPaSfEYGBF9ULQgSG9zdG1hc3RlciA8aG9zdG1hc3RlckBy\n" + "certif: aXBlLm5ldD6IuAQTAQIAIgUCUqWRMQIbAwYLCQgHAwIGFQgCCQoLBBYCAwECHgEC\n" + "certif: F4AACgkQxyJ+7Opfu5SCzAQAqoRLx76WWa5AcVKUr5BYt2MCPn695iOJ7/Lcxgtq\n" + "certif: wVx8ItIzd0rW5L5iqrreJBSof9W8WfSkHJuwTIzznDzjZZgYaU8eb7zB/g4VAr7b\n" + "certif: ZcfW0b5+IcUI+W1XNdX1ByYsXFkwp/si9QT0VO2rEf+Nxt8zrZ8sygSTWoTWEBWY\n" + "certif: 1X24jQRSpZCdAQQAz3jzZHoumwM2tpNQjLdbb/agjeH9zDEb2lMQXSdLx+VdQWeN\n" + "certif: +ywh40Z0beMySXC+4e/pTyliGO5OUly75BiYsowWwLRA17AdR7YNHv+e22mTVf0O\n" + "certif: TkrzUAsU5TAA6ObX6NZWIt3XSCyDOB7m5imOO+vyGwp8p6+6tg2h/oKfedMAEQEA\n" + "certif: AYifBBgBAgAJBQJSpZCdAhsMAAoJEMcifuzqX7uUqBcEAJ4g4bzoRXWJJ6vjuT6w\n" + "certif: UgYCXmEcPSZIwwKPauTj3j7QX46T7u2+yb0qeyK+gFgb4e+iua3KNGb9L82xSEYy\n" + "certif: M8BQ5qhoZnUZjU1DvusYcX7g8Pwe7nntlucKXaMc/1Rgsx2Wpolu59uMLHZ7FUUM\n" + "certif: FUJok98LaNd+xfMg7u+8Fpca\n" + "certif: =tiwc\n" + "certif: -----END PGP PUBLIC KEY BLOCK----- \n" + "mnt-by: UPD-MNT\n" + "notify: [email protected]\n" + "source: TEST\n"); when(keyWrapperFactory.createKeyWrapper(keycert, update, updateContext)).thenReturn(PgpPublicKeyWrapper.parse(keycert)); final RpslObject updatedObject = subject.generateAttributes(keycert, update, updateContext); validateAttributeType(updatedObject, AttributeType.METHOD, "PGP"); validateAttributeType(updatedObject, AttributeType.FINGERPR, "FBFD 0527 454D 5880 3484 413F C722 7EEC EA5F BB94"); validateAttributeType(updatedObject, AttributeType.OWNER, "Hostmaster <[email protected]>", "Admin User <[email protected]>"); validateMessages(ValidationMessages.suppliedAttributeReplacedWithGeneratedValue(AttributeType.OWNER)); }
public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void unknown_certificate() { final RpslObject keycert = RpslObject.parse("key-cert: unknown"); final RpslObject updatedObject = subject.generateAttributes(keycert, update, updateContext); assertThat(updatedObject.getAttributes(), hasSize(1)); validateMessages(); }
public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void person_object_not_updated() { final RpslObject person = RpslObject.parse("person: first last\nnic-hdl: FL-TEST"); final RpslObject updatedObject = subject.generateAttributes(person, update, updateContext); assertThat(updatedObject, is(person)); validateMessages(); }
public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
KeycertAttributeGenerator extends AttributeGenerator { public RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext) { return generateAttributes(originalObject, originalObject, update, updateContext); } @Autowired KeycertAttributeGenerator(final KeyWrapperFactory keyWrapperFactory); RpslObject generateAttributes(final RpslObject originalObject, final Update update, final UpdateContext updateContext); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void generate_other_status_on_create() { final RpslObject autnum = RpslObject.parse("aut-num: AS3333\nmnt-by: TEST-MNT\nsource: RIPE"); final RpslObject result = autnumStatusAttributeGenerator.generateAttributes(null, autnum, update, updateContext); assertThat(result.getValueForAttribute(AttributeType.STATUS), is(CIString.ciString("OTHER"))); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { switch (updatedObject.getType()) { case AUT_NUM: return generateStatus(originalObject, updatedObject, update, updateContext); default: return updatedObject; } }
AutnumAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { switch (updatedObject.getType()) { case AUT_NUM: return generateStatus(originalObject, updatedObject, update, updateContext); default: return updatedObject; } } }
AutnumAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { switch (updatedObject.getType()) { case AUT_NUM: return generateStatus(originalObject, updatedObject, update, updateContext); default: return updatedObject; } } @Autowired AutnumAttributeGenerator(final AuthoritativeResourceData authoritativeResourceData, final SourceContext sourceContext, final LegacyAutnum legacyAutnum); }
AutnumAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { switch (updatedObject.getType()) { case AUT_NUM: return generateStatus(originalObject, updatedObject, update, updateContext); default: return updatedObject; } } @Autowired AutnumAttributeGenerator(final AuthoritativeResourceData authoritativeResourceData, final SourceContext sourceContext, final LegacyAutnum legacyAutnum); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
AutnumAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { switch (updatedObject.getType()) { case AUT_NUM: return generateStatus(originalObject, updatedObject, update, updateContext); default: return updatedObject; } } @Autowired AutnumAttributeGenerator(final AuthoritativeResourceData authoritativeResourceData, final SourceContext sourceContext, final LegacyAutnum legacyAutnum); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void generate_other_status_on_update() { final RpslObject originalObject = RpslObject.parse("aut-num: AS3333\nmnt-by: RIPE-NCC-HM-MNT\nsource: RIPE"); final RpslObject updatedObject = RpslObject.parse("aut-num: AS3333\nremarks: updated\nmnt-by: RIPE-NCC-HM-MNT\nsource: RIPE"); final RpslObject result = autnumStatusAttributeGenerator.generateAttributes(originalObject, updatedObject, update, updateContext); assertThat(result.getValueForAttribute(AttributeType.STATUS), is(CIString.ciString("OTHER"))); }
@Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { switch (updatedObject.getType()) { case AUT_NUM: return generateStatus(originalObject, updatedObject, update, updateContext); default: return updatedObject; } }
AutnumAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { switch (updatedObject.getType()) { case AUT_NUM: return generateStatus(originalObject, updatedObject, update, updateContext); default: return updatedObject; } } }
AutnumAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { switch (updatedObject.getType()) { case AUT_NUM: return generateStatus(originalObject, updatedObject, update, updateContext); default: return updatedObject; } } @Autowired AutnumAttributeGenerator(final AuthoritativeResourceData authoritativeResourceData, final SourceContext sourceContext, final LegacyAutnum legacyAutnum); }
AutnumAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { switch (updatedObject.getType()) { case AUT_NUM: return generateStatus(originalObject, updatedObject, update, updateContext); default: return updatedObject; } } @Autowired AutnumAttributeGenerator(final AuthoritativeResourceData authoritativeResourceData, final SourceContext sourceContext, final LegacyAutnum legacyAutnum); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
AutnumAttributeGenerator extends AttributeGenerator { @Override public RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext) { switch (updatedObject.getType()) { case AUT_NUM: return generateStatus(originalObject, updatedObject, update, updateContext); default: return updatedObject; } } @Autowired AutnumAttributeGenerator(final AuthoritativeResourceData authoritativeResourceData, final SourceContext sourceContext, final LegacyAutnum legacyAutnum); @Override RpslObject generateAttributes(final RpslObject originalObject, final RpslObject updatedObject, final Update update, final UpdateContext updateContext); }
@Test public void translate_not_a_maintainer() { final RpslObject object = RpslObject.parse("person: test person\nnic-hdl: test-nic"); final RpslObject result = subject.translateFromCacheAuthToUuid(updateContext, object); verifyZeroInteractions(updateContext); assertThat(result, is(object)); }
public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); }
SsoTranslator { public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } }
SsoTranslator { public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } @Autowired SsoTranslator(final CrowdClient crowdClient); }
SsoTranslator { public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
SsoTranslator { public RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
@Test public void translate_to_uuid_username_stored_in_context_already() { final RpslObject object = RpslObject.parse("mntner: TEST-MNT\nauth: SSO [email protected]"); when(updateContext.getSsoTranslationResult("[email protected]")).thenReturn("BBBB-1234-CCCC-DDDD"); final RpslObject result = subject.translateFromCacheAuthToUsername(updateContext, object); assertThat(result, is(RpslObject.parse("mntner: TEST-MNT\nauth: SSO BBBB-1234-CCCC-DDDD"))); }
public RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); }
SsoTranslator { public RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } }
SsoTranslator { public RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } @Autowired SsoTranslator(final CrowdClient crowdClient); }
SsoTranslator { public RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
SsoTranslator { public RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject) { return translateAuthFromCache(updateContext, rpslObject); } @Autowired SsoTranslator(final CrowdClient crowdClient); void populateCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); void populateCacheAuthToUuid(final UpdateContext updateContext, final Update update); RpslObject translateFromCacheAuthToUuid(final UpdateContext updateContext, final RpslObject rpslObject); RpslObject translateFromCacheAuthToUsername(final UpdateContext updateContext, final RpslObject rpslObject); }
@Test public void transform_inetnum_change() { final RpslObject rpslObject = RpslObject.parse("inetnum: 192.0.0.0/4"); final RpslObject result = attributeSanitizer.sanitize(rpslObject, objectMessages); assertThat(result.getValueForAttribute(AttributeType.INETNUM).toString(), is("192.0.0.0 - 207.255.255.255")); verify(objectMessages).addMessage(result.getTypeAttribute(), ValidationMessages.attributeValueConverted("192.0.0.0/4", "192.0.0.0 - 207.255.255.255")); verifyNoMoreInteractions(objectMessages); }
public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
AttributeSanitizer { public RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages) { final Map<RpslAttribute, RpslAttribute> replacements = Maps.newHashMap(); for (final RpslAttribute attribute : object.getAttributes()) { final AttributeType type = attribute.getType(); String newValue = null; final Sanitizer sanitizer = SANITIZER_MAP.get(type); if (sanitizer == null) { continue; } try { newValue = sanitizer.sanitize(attribute); } catch (IllegalArgumentException ignored) { LOGGER.debug("{}: {}", ignored.getClass().getName(), ignored.getMessage()); } if (newValue == null) { continue; } final List<Message> attributeMessages = Lists.newArrayList(); if (!sanitizer.silent() && !attribute.getCleanValue().toString().equals(newValue)) { attributeMessages.add(ValidationMessages.attributeValueConverted(attribute.getCleanValue(), newValue)); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('\n') != -1) { attributeMessages.add(ValidationMessages.continuationLinesRemoved()); } if (keyAttributes.contains(type) && attribute.getValue().indexOf('#') != -1) { attributeMessages.add(ValidationMessages.remarksReformatted()); } final String replacement = newValue + getCommentReplacement(attribute); final RpslAttribute transformed = new RpslAttribute(attribute.getKey(), replacement); replacements.put(attribute, transformed); for (final Message attributeMessage : attributeMessages) { objectMessages.addMessage(transformed, attributeMessage); } } return new RpslObjectBuilder(object).replaceAttributes(replacements).get(); } @Autowired AttributeSanitizer(DateTimeProvider dateTimeProvider); CIString sanitizeKey(final RpslObject originalObject); RpslObject sanitize(final RpslObject object, final ObjectMessages objectMessages); }
@Test public void isExportDir_home() { final File homeDir = new File(System.getProperty("user.home")); assertThat(homeDir.exists(), Matchers.is(true)); assertThat(homeDir.isDirectory(), Matchers.is(true)); assertThat(homeDir.canWrite(), Matchers.is(true)); assertThat(subject.isExportDir(homeDir), Matchers.is(false)); }
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 testRepoScanner() throws IOException { try { JSONObject submissions = new RepoScanner() .getSubmissionsFromRepo("bpmn-miwg/bpmn-miwg-test-suite"); System.out.println(submissions); FileUtils.writeStringToFile(new File("target/submissions.json"), submissions.toJSONString()); } catch (Throwable t) { assumeNoException("Assume no GitHub token provided, continuing", t); } }
public RepoScanner() { githubUser = System.getProperty("githubUser"); githubToken = System.getProperty("githubToken"); if (githubUser == null || githubToken == null) { String msg = ("To scan GitHub for submissions please provide your username and a valid Personal Access Token.\n" + "Without this the submissions table will be out of date.\n" + "JVM parameters are githubUser and githubToken"); throw new IllegalStateException(msg); } }
RepoScanner { public RepoScanner() { githubUser = System.getProperty("githubUser"); githubToken = System.getProperty("githubToken"); if (githubUser == null || githubToken == null) { String msg = ("To scan GitHub for submissions please provide your username and a valid Personal Access Token.\n" + "Without this the submissions table will be out of date.\n" + "JVM parameters are githubUser and githubToken"); throw new IllegalStateException(msg); } } }
RepoScanner { public RepoScanner() { githubUser = System.getProperty("githubUser"); githubToken = System.getProperty("githubToken"); if (githubUser == null || githubToken == null) { String msg = ("To scan GitHub for submissions please provide your username and a valid Personal Access Token.\n" + "Without this the submissions table will be out of date.\n" + "JVM parameters are githubUser and githubToken"); throw new IllegalStateException(msg); } } RepoScanner(); }
RepoScanner { public RepoScanner() { githubUser = System.getProperty("githubUser"); githubToken = System.getProperty("githubToken"); if (githubUser == null || githubToken == null) { String msg = ("To scan GitHub for submissions please provide your username and a valid Personal Access Token.\n" + "Without this the submissions table will be out of date.\n" + "JVM parameters are githubUser and githubToken"); throw new IllegalStateException(msg); } } RepoScanner(); JSONObject getSubmissionsFromRepo(String repoName); }
RepoScanner { public RepoScanner() { githubUser = System.getProperty("githubUser"); githubToken = System.getProperty("githubToken"); if (githubUser == null || githubToken == null) { String msg = ("To scan GitHub for submissions please provide your username and a valid Personal Access Token.\n" + "Without this the submissions table will be out of date.\n" + "JVM parameters are githubUser and githubToken"); throw new IllegalStateException(msg); } } RepoScanner(); JSONObject getSubmissionsFromRepo(String repoName); }
@Test public void testMojo() { try { Resource res = new Resource(); res.setDirectory(SRC_TEST_RESOURCES); mojo.resources.add(res); mojo.execute(); System.out .println("Checking expected output exists with base folder: " + TestUtil.REPORT_BASE_FOLDER_NAME); assertTrue(overview.exists()); Document document = docBuilder.parse(overview); XPathExpression xpath = createXpathExpression(" NodeList nodes = (NodeList) xpath.evaluate(document, XPathConstants.NODESET); assertEquals(7, nodes.getLength()); assertHtmlReportsExist(new File(TestUtil.REPORT_BASE_FOLDER_NAME, XmlCompareAnalysisTool.NAME)); assertHtmlReportsExist(new File(TestUtil.REPORT_BASE_FOLDER_NAME, SchemaAnalysisTool.NAME)); assertHtmlReportsExist(new File(TestUtil.REPORT_BASE_FOLDER_NAME, XpathAnalysisTool.NAME)); File xpathResult = new File(TestUtil.REPORT_BASE_FOLDER_NAME + File.separator + XpathAnalysisTool.NAME + File.separator + MavenTestConsts.W4_MODELER_ID + File.separator + MavenTestConsts.W4_MODELER_ID + "-A.1.0-roundtrip.html"); System.out.println("Checking file: " + xpathResult); assertTrue(xpathResult.exists()); document = docBuilder.parse(xpathResult); nodes = (NodeList) xPath.compile( " XPathConstants.NODESET); assertTrue("Did not find result element", nodes.getLength() == 1); nodes = (NodeList) xPath.compile( " .evaluate(document, XPathConstants.NODESET); assertTrue("Did not find tool element", nodes.getLength() == 1); nodes = (NodeList) xPath .compile( " .evaluate(document, XPathConstants.NODESET); assertTrue("Did not find test element", nodes.getLength() >= 1); } catch (Exception e) { e.printStackTrace(); fail(e.getClass() + ":" + e.getMessage()); } }
public void execute() throws MojoExecutionException { getLog().info("Running BPMN-MIWG test suite..."); if (!outputDirectory.exists()) { outputDirectory.mkdirs(); } try { Collection<String> inputFolders = new LinkedList<String>(); if (!resources.isEmpty()) { for (Resource resource : resources) { String folderName = resource.getDirectory(); inputFolders.add(folderName); } } Collection<AnalysisJob> jobs = BpmnFileScanner .buildListOfAnalysisJobs(new StandardScanParameters(application, null, inputFolders, outputDirectory.getCanonicalPath())); AnalysisFacade.executeAnalysisJobs(jobs, outputDirectory.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } try (FileWriter out = new FileWriter(new File(outputDirectory, "submissions.json"))) { JSONObject submissions = new RepoScanner().getSubmissionsFromRepo("bpmn-miwg/bpmn-miwg-test-suite"); submissions.writeJSONString(out); } catch (Exception e) { e.printStackTrace(); } }
ModelInterchangeMojo extends AbstractMojo { public void execute() throws MojoExecutionException { getLog().info("Running BPMN-MIWG test suite..."); if (!outputDirectory.exists()) { outputDirectory.mkdirs(); } try { Collection<String> inputFolders = new LinkedList<String>(); if (!resources.isEmpty()) { for (Resource resource : resources) { String folderName = resource.getDirectory(); inputFolders.add(folderName); } } Collection<AnalysisJob> jobs = BpmnFileScanner .buildListOfAnalysisJobs(new StandardScanParameters(application, null, inputFolders, outputDirectory.getCanonicalPath())); AnalysisFacade.executeAnalysisJobs(jobs, outputDirectory.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } try (FileWriter out = new FileWriter(new File(outputDirectory, "submissions.json"))) { JSONObject submissions = new RepoScanner().getSubmissionsFromRepo("bpmn-miwg/bpmn-miwg-test-suite"); submissions.writeJSONString(out); } catch (Exception e) { e.printStackTrace(); } } }
ModelInterchangeMojo extends AbstractMojo { public void execute() throws MojoExecutionException { getLog().info("Running BPMN-MIWG test suite..."); if (!outputDirectory.exists()) { outputDirectory.mkdirs(); } try { Collection<String> inputFolders = new LinkedList<String>(); if (!resources.isEmpty()) { for (Resource resource : resources) { String folderName = resource.getDirectory(); inputFolders.add(folderName); } } Collection<AnalysisJob> jobs = BpmnFileScanner .buildListOfAnalysisJobs(new StandardScanParameters(application, null, inputFolders, outputDirectory.getCanonicalPath())); AnalysisFacade.executeAnalysisJobs(jobs, outputDirectory.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } try (FileWriter out = new FileWriter(new File(outputDirectory, "submissions.json"))) { JSONObject submissions = new RepoScanner().getSubmissionsFromRepo("bpmn-miwg/bpmn-miwg-test-suite"); submissions.writeJSONString(out); } catch (Exception e) { e.printStackTrace(); } } }
ModelInterchangeMojo extends AbstractMojo { public void execute() throws MojoExecutionException { getLog().info("Running BPMN-MIWG test suite..."); if (!outputDirectory.exists()) { outputDirectory.mkdirs(); } try { Collection<String> inputFolders = new LinkedList<String>(); if (!resources.isEmpty()) { for (Resource resource : resources) { String folderName = resource.getDirectory(); inputFolders.add(folderName); } } Collection<AnalysisJob> jobs = BpmnFileScanner .buildListOfAnalysisJobs(new StandardScanParameters(application, null, inputFolders, outputDirectory.getCanonicalPath())); AnalysisFacade.executeAnalysisJobs(jobs, outputDirectory.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } try (FileWriter out = new FileWriter(new File(outputDirectory, "submissions.json"))) { JSONObject submissions = new RepoScanner().getSubmissionsFromRepo("bpmn-miwg/bpmn-miwg-test-suite"); submissions.writeJSONString(out); } catch (Exception e) { e.printStackTrace(); } } void execute(); }
ModelInterchangeMojo extends AbstractMojo { public void execute() throws MojoExecutionException { getLog().info("Running BPMN-MIWG test suite..."); if (!outputDirectory.exists()) { outputDirectory.mkdirs(); } try { Collection<String> inputFolders = new LinkedList<String>(); if (!resources.isEmpty()) { for (Resource resource : resources) { String folderName = resource.getDirectory(); inputFolders.add(folderName); } } Collection<AnalysisJob> jobs = BpmnFileScanner .buildListOfAnalysisJobs(new StandardScanParameters(application, null, inputFolders, outputDirectory.getCanonicalPath())); AnalysisFacade.executeAnalysisJobs(jobs, outputDirectory.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } try (FileWriter out = new FileWriter(new File(outputDirectory, "submissions.json"))) { JSONObject submissions = new RepoScanner().getSubmissionsFromRepo("bpmn-miwg/bpmn-miwg-test-suite"); submissions.writeJSONString(out); } catch (Exception e) { e.printStackTrace(); } } void execute(); }
@Test public void testMojoHandlingSchemaInvalidBpmn() throws XPathExpressionException, SAXException, IOException, MojoExecutionException { Resource res = new Resource(); res.setDirectory("src/test/invalid-resources"); mojo.resources.add(res); mojo.application = "Yaoqiang BPMN Editor 2.2.6"; mojo.execute(); assertTrue(overview.exists()); Document document = docBuilder.parse(overview); XPathExpression xpath = createXpathExpression(" NodeList nodes = (NodeList) xpath.evaluate(document, XPathConstants.NODESET); Node invalidNode = nodes.item(0); assertEquals("2", invalidNode.getAttributes().getNamedItem("data-xsd-finding") .getNodeValue()); }
public void execute() throws MojoExecutionException { getLog().info("Running BPMN-MIWG test suite..."); if (!outputDirectory.exists()) { outputDirectory.mkdirs(); } try { Collection<String> inputFolders = new LinkedList<String>(); if (!resources.isEmpty()) { for (Resource resource : resources) { String folderName = resource.getDirectory(); inputFolders.add(folderName); } } Collection<AnalysisJob> jobs = BpmnFileScanner .buildListOfAnalysisJobs(new StandardScanParameters(application, null, inputFolders, outputDirectory.getCanonicalPath())); AnalysisFacade.executeAnalysisJobs(jobs, outputDirectory.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } try (FileWriter out = new FileWriter(new File(outputDirectory, "submissions.json"))) { JSONObject submissions = new RepoScanner().getSubmissionsFromRepo("bpmn-miwg/bpmn-miwg-test-suite"); submissions.writeJSONString(out); } catch (Exception e) { e.printStackTrace(); } }
ModelInterchangeMojo extends AbstractMojo { public void execute() throws MojoExecutionException { getLog().info("Running BPMN-MIWG test suite..."); if (!outputDirectory.exists()) { outputDirectory.mkdirs(); } try { Collection<String> inputFolders = new LinkedList<String>(); if (!resources.isEmpty()) { for (Resource resource : resources) { String folderName = resource.getDirectory(); inputFolders.add(folderName); } } Collection<AnalysisJob> jobs = BpmnFileScanner .buildListOfAnalysisJobs(new StandardScanParameters(application, null, inputFolders, outputDirectory.getCanonicalPath())); AnalysisFacade.executeAnalysisJobs(jobs, outputDirectory.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } try (FileWriter out = new FileWriter(new File(outputDirectory, "submissions.json"))) { JSONObject submissions = new RepoScanner().getSubmissionsFromRepo("bpmn-miwg/bpmn-miwg-test-suite"); submissions.writeJSONString(out); } catch (Exception e) { e.printStackTrace(); } } }
ModelInterchangeMojo extends AbstractMojo { public void execute() throws MojoExecutionException { getLog().info("Running BPMN-MIWG test suite..."); if (!outputDirectory.exists()) { outputDirectory.mkdirs(); } try { Collection<String> inputFolders = new LinkedList<String>(); if (!resources.isEmpty()) { for (Resource resource : resources) { String folderName = resource.getDirectory(); inputFolders.add(folderName); } } Collection<AnalysisJob> jobs = BpmnFileScanner .buildListOfAnalysisJobs(new StandardScanParameters(application, null, inputFolders, outputDirectory.getCanonicalPath())); AnalysisFacade.executeAnalysisJobs(jobs, outputDirectory.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } try (FileWriter out = new FileWriter(new File(outputDirectory, "submissions.json"))) { JSONObject submissions = new RepoScanner().getSubmissionsFromRepo("bpmn-miwg/bpmn-miwg-test-suite"); submissions.writeJSONString(out); } catch (Exception e) { e.printStackTrace(); } } }
ModelInterchangeMojo extends AbstractMojo { public void execute() throws MojoExecutionException { getLog().info("Running BPMN-MIWG test suite..."); if (!outputDirectory.exists()) { outputDirectory.mkdirs(); } try { Collection<String> inputFolders = new LinkedList<String>(); if (!resources.isEmpty()) { for (Resource resource : resources) { String folderName = resource.getDirectory(); inputFolders.add(folderName); } } Collection<AnalysisJob> jobs = BpmnFileScanner .buildListOfAnalysisJobs(new StandardScanParameters(application, null, inputFolders, outputDirectory.getCanonicalPath())); AnalysisFacade.executeAnalysisJobs(jobs, outputDirectory.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } try (FileWriter out = new FileWriter(new File(outputDirectory, "submissions.json"))) { JSONObject submissions = new RepoScanner().getSubmissionsFromRepo("bpmn-miwg/bpmn-miwg-test-suite"); submissions.writeJSONString(out); } catch (Exception e) { e.printStackTrace(); } } void execute(); }
ModelInterchangeMojo extends AbstractMojo { public void execute() throws MojoExecutionException { getLog().info("Running BPMN-MIWG test suite..."); if (!outputDirectory.exists()) { outputDirectory.mkdirs(); } try { Collection<String> inputFolders = new LinkedList<String>(); if (!resources.isEmpty()) { for (Resource resource : resources) { String folderName = resource.getDirectory(); inputFolders.add(folderName); } } Collection<AnalysisJob> jobs = BpmnFileScanner .buildListOfAnalysisJobs(new StandardScanParameters(application, null, inputFolders, outputDirectory.getCanonicalPath())); AnalysisFacade.executeAnalysisJobs(jobs, outputDirectory.getAbsolutePath()); } catch (Exception e) { e.printStackTrace(); } try (FileWriter out = new FileWriter(new File(outputDirectory, "submissions.json"))) { JSONObject submissions = new RepoScanner().getSubmissionsFromRepo("bpmn-miwg/bpmn-miwg-test-suite"); submissions.writeJSONString(out); } catch (Exception e) { e.printStackTrace(); } } void execute(); }
@Test public void onReceivedError() { final int code = 500; final String message = "foo"; final String url = "bar"; debugClient.onReceivedError(webView, code, message, url); verifyLogger().onReceivedError(webView, code, message, url); verifyWrappedClient().onReceivedError(webView, code, message, url); }
@RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { logger.onReceivedError(view, request, error); client.onReceivedError(view, request, error); }
DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { logger.onReceivedError(view, request, error); client.onReceivedError(view, request, error); } }
DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { logger.onReceivedError(view, request, error); client.onReceivedError(view, request, error); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient( @NonNull final WebViewClient client, @NonNull final DebugWebViewClientLogger logger); }
DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { logger.onReceivedError(view, request, error); client.onReceivedError(view, request, error); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient( @NonNull final WebViewClient client, @NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); }
DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { logger.onReceivedError(view, request, error); client.onReceivedError(view, request, error); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient( @NonNull final WebViewClient client, @NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); }