private Stream<Mapping> recurseMapping(Stream<Mapping> nonRecursiveResult, User targetUser, int remainingLoops) throws ErrorMappingException, RecipientRewriteTableException { Mappings childMappings = getMappings(targetUser, remainingLoops - 1); if (childMappings.isEmpty()) { return nonRecursiveResult; } else { return childMappings.asStream(); } }
/** * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTable#mapAddressInternal(java.lang.String, * java.lang.String) */ protected String mapAddressInternal(String user, String domain) throws RecipientRewriteTableException { if (mappings == null) { return null; } else { return RecipientRewriteTableUtil.getTargetString(user, domain, mappings); } }
@Override public void addForwardMapping(MappingSource source, String address) throws RecipientRewriteTableException { Mapping mapping = Mapping.forward(address) .appendDomainFromThrowingSupplierIfNone(this::defaultDomain); checkHasValidAddress(mapping); checkDuplicateMapping(source, mapping); LOGGER.info("Add forward mapping => {} for source: {}", mapping, source.asString()); addMapping(source, mapping); }
@Override public void addMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException { Mappings map = getUserDomainMappings(source); if (!map.isEmpty()) { Mappings updatedMappings = MappingsImpl.from(map).add(mapping).build(); doUpdateMapping(source, updatedMappings.serialize()); } else { doAddMapping(source, mapping.asString()); } }
protected void addMappingToConfiguration(MappingSource source, String mapping, Type type) throws RecipientRewriteTableException { Mappings mappings = Optional.ofNullable(virtualUserTable.getUserDomainMappings(source)) .orElse(MappingsImpl.empty()); Mappings updatedMappings = MappingsImpl.from(mappings) .add(Mapping.of(type, mapping)) .build(); updateConfiguration(source, mappings, updatedMappings); }
@Override public void addAddressMapping(MappingSource source, String address) throws RecipientRewriteTableException { Mapping mapping = Mapping.address(address) .appendDomainFromThrowingSupplierIfNone(this::defaultDomain); checkHasValidAddress(mapping); checkDuplicateMapping(source, mapping); LOGGER.info("Add address mapping => {} for source: {}", mapping, source.asString()); addMapping(source, mapping); }
@Override public void addGroupMapping(MappingSource source, String address) throws RecipientRewriteTableException { Mapping mapping = Mapping.group(address) .appendDomainFromThrowingSupplierIfNone(this::defaultDomain); checkHasValidAddress(mapping); checkDuplicateMapping(source, mapping); LOGGER.info("Add group mapping => {} for source: {}", mapping, source.asString()); addMapping(source, mapping); }
@Given("store \"([^\"]*)\" regexp mapping for user \"([^\"]*)\" at domain \"([^\"]*)\"") public void storeRegexpMappingForUserAtDomain(String regexp, String user, String domain) throws Throwable { MappingSource source = MappingSource.fromUser(user, domain); rewriteTable.addRegexMapping(source, regexp); }
@Given("store \"([^\"]*)\" address mapping for user \"([^\"]*)\" at domain \"([^\"]*)\"") public void storeAddressMappingForUserAtDomain(String address, String user, String domain) throws Throwable { MappingSource source = MappingSource.fromUser(user, domain); rewriteTable.addAddressMapping(source, address); }
@Given("store \"([^\"]*)\" error mapping for user \"([^\"]*)\" at domain \"([^\"]*)\"") public void storeErrorMappingForUserAtDomain(String error, String user, String domain) throws Throwable { MappingSource source = MappingSource.fromUser(user, domain); rewriteTable.addErrorMapping(source, error); }
@Given("store \"([^\"]*)\" forward mapping for user \"([^\"]*)\" at domain \"([^\"]*)\"") public void storeForwardMappingForUserAtDomain(String address, String user, String domain) throws Throwable { MappingSource source = MappingSource.fromUser(user, domain); rewriteTable.addForwardMapping(source, address); }
@When("user \"([^\"]*)\" at domain \"([^\"]*)\" removes a address mapping \"([^\"]*)\"") public void userAtDomainRemovesAddressMapping(String user, String domain, String address) throws Throwable { MappingSource source = MappingSource.fromUser(user, domain); rewriteTable.removeAddressMapping(source, address); }
@When("user \"([^\"]*)\" at domain \"([^\"]*)\" removes a error mapping \"([^\"]*)\"") public void userAtDomainRemovesErrorMapping(String user, String domain, String error) throws Throwable { MappingSource source = MappingSource.fromUser(user, domain); rewriteTable.removeErrorMapping(source, error); }
@Override public void removeAddressMapping(MappingSource source, String address) throws RecipientRewriteTableException { Mapping mapping = Mapping.address(address) .appendDomainFromThrowingSupplierIfNone(this::defaultDomain); LOGGER.info("Remove address mapping => {} for source: {}", mapping, source.asString()); removeMapping(source, mapping); }
@Override public void removeForwardMapping(MappingSource source, String address) throws RecipientRewriteTableException { Mapping mapping = Mapping.forward(address) .appendDomainFromThrowingSupplierIfNone(this::defaultDomain); LOGGER.info("Remove forward mapping => {} for source: {}", mapping, source.asString()); removeMapping(source, mapping); }
@Override public void removeGroupMapping(MappingSource source, String address) throws RecipientRewriteTableException { Mapping mapping = Mapping.group(address) .appendDomainFromThrowingSupplierIfNone(this::defaultDomain); LOGGER.info("Remove group mapping => {} for source: {}", mapping, source.asString()); removeMapping(source, mapping); }
@Override public void addErrorMapping(MappingSource source, String error) throws RecipientRewriteTableException { Mapping mapping = Mapping.error(error); checkDuplicateMapping(source, mapping); LOGGER.info("Add error mapping => {} for source: {}", error, source.asString()); addMapping(source, mapping); }
@Override public void removeErrorMapping(MappingSource source, String error) throws RecipientRewriteTableException { LOGGER.info("Remove error mapping => {} for source: {}", error, source.asString()); removeMapping(source, Mapping.error(error)); }
@Override public void removeRegexMapping(MappingSource source, String regex) throws RecipientRewriteTableException { LOGGER.info("Remove regex mapping => {} for source: {}", regex, source.asString()); removeMapping(source, Mapping.regex(regex)); }
private void checkDuplicateMapping(MappingSource source, Mapping mapping) throws RecipientRewriteTableException { Mappings mappings = getUserDomainMappings(source); if (mappings != null && mappings.contains(mapping)) { throw new MappingAlreadyExistsException("Mapping " + mapping + " for " + source.asString() + " already exist!"); } }