[
https://issues.apache.org/jira/browse/JAMES-2149?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16507773#comment-16507773
]
ASF GitHub Bot commented on JAMES-2149:
---------------------------------------
Github user nstdio commented on a diff in the pull request:
https://github.com/apache/james-project/pull/119#discussion_r194316652
--- Diff:
server/protocols/webadmin/webadmin-data/src/main/java/org/apache/james/webadmin/routes/DomainMappingsRoutes.java
---
@@ -0,0 +1,155 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.webadmin.routes;
+
+import com.github.fge.lambdas.consumers.ThrowingBiConsumer;
+import io.swagger.annotations.*;
+import org.apache.james.core.Domain;
+import org.apache.james.rrt.api.RecipientRewriteTable;
+import org.apache.james.rrt.api.RecipientRewriteTableException;
+import org.apache.james.rrt.lib.Mapping;
+import org.apache.james.rrt.lib.MappingSource;
+import org.apache.james.webadmin.Routes;
+import org.apache.james.webadmin.utils.ErrorResponder;
+import org.apache.james.webadmin.utils.JsonTransformer;
+import org.eclipse.jetty.http.HttpStatus;
+import spark.HaltException;
+import spark.Request;
+import spark.Response;
+import spark.Service;
+
+import javax.inject.Inject;
+import javax.ws.rs.*;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+
+import static com.github.steveash.guavate.Guavate.toImmutableList;
+import static com.github.steveash.guavate.Guavate.toImmutableMap;
+import static org.apache.james.webadmin.Constants.SEPARATOR;
+import static
org.apache.james.webadmin.routes.DomainMappingsRoutes.DOMAIN_MAPPINGS;
+import static spark.Spark.halt;
+
+@Api(tags = "Domain Mappings")
+@Path(DOMAIN_MAPPINGS)
+@Produces("application/json")
+public class DomainMappingsRoutes implements Routes {
+ static final String DOMAIN_MAPPINGS = "/domainMappings";
+ private static final String FROM_DOMAIN = "fromDomain";
+ private static final String SPECIFIC_MAPPING_PATH = SEPARATOR + "/{" +
FROM_DOMAIN + "}";
+ private static final String SPECIFIC_MAPPING = DOMAIN_MAPPINGS +
SEPARATOR + ":" + FROM_DOMAIN;
+
+ private final RecipientRewriteTable recipientRewriteTable;
+ private final JsonTransformer jsonTransformer;
+
+ @Inject
+ public DomainMappingsRoutes(final RecipientRewriteTable
recipientRewriteTable, final JsonTransformer jsonTransformer) {
+ this.recipientRewriteTable = recipientRewriteTable;
+ this.jsonTransformer = jsonTransformer;
+ }
+
+ @Override
+ public void define(final Service service) {
+ service.get(DOMAIN_MAPPINGS, this::get, jsonTransformer);
+ service.put(SPECIFIC_MAPPING, this::addDomainMapping);
+ service.delete(SPECIFIC_MAPPING, this::removeDomainMapping);
+ }
+
+ @PUT
+ @Path(SPECIFIC_MAPPING_PATH)
+ @ApiOperation(value = "Creating domain mapping between source and
destination domains.")
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "string", name =
FROM_DOMAIN, paramType = "path")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "Ok"),
+ @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message =
"Domain name is invalid"),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+ message = "Internal server error - Something went bad
on the server side.")
+ })
+ public HaltException addDomainMapping(Request request, Response
response) {
+ doMapping(request, recipientRewriteTable::addAliasDomainMapping);
+ return halt(HttpStatus.NO_CONTENT_204);
+ }
+
+ @DELETE
+ @Path(SPECIFIC_MAPPING_PATH)
+ @ApiOperation(value = "Removes domain mapping between source and
destination domains.")
+ @ApiImplicitParams({
+ @ApiImplicitParam(required = true, dataType = "string", name =
FROM_DOMAIN, paramType = "path")
+ })
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.NO_CONTENT_204, message = "Ok"),
+ @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message =
"Domain name is invalid"),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+ message = "Internal server error - Something went bad
on the server side.")
+ })
+ public HaltException removeDomainMapping(Request request, Response
response) {
+ doMapping(request,
recipientRewriteTable::removeAliasDomainMapping);
+ return halt(HttpStatus.NO_CONTENT_204);
+ }
+
+ @GET
+ @Path(DOMAIN_MAPPINGS)
+ @ApiOperation(value = "Lists all domain mappings.")
+ @ApiResponses(value = {
+ @ApiResponse(code = HttpStatus.OK_200, message = "Domain
mappings.", responseContainer = "Map"),
+ @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
+ message = "Internal server error - Something went bad
on the server side.")
+ })
+ public Map<String, List<String>> get(Request request, Response
response) throws RecipientRewriteTableException {
--- End diff --
If you mean `MultiMap` then, yes, of course it is!
> Create domain mappings via webadmin
> -----------------------------------
>
> Key: JAMES-2149
> URL: https://issues.apache.org/jira/browse/JAMES-2149
> Project: James Server
> Issue Type: New Feature
> Components: webadmin
> Affects Versions: master
> Reporter: Tellier Benoit
> Priority: Major
> Labels: feature, newbie
>
> Nowadays, the Rewrite Table engine supports domain redirections. That is to
> say [email protected] will be rewritten as [email protected].
> However, such a feature is not exposed via webadmin.
> You will need to :
> - Create a new **DomainMappingsRoutes** in webadmin-data
> - You will expose in this routes, using directly RecipientsRewriteTable, the
> endpoitns for adding, removing and listing domain mappings.
> {code:java}
> GET /domainMappings/
> {"fromDomain1":"toDomain1", "fromDomain2": "toDomain2"}
> PUT /domainMappings/fromDomain
> "toDomain"
> DELETE /domainMappings/fromDomain
> "toDomain"
> {code}
> You will write a test class from your endpoints. See *GroupsRoutesTest*.
> Don't hesitate to ask for help on the *Gitter* chat.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]