X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fstaticrouting%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwarding%2Fstaticrouting%2Fnorthbound%2FStaticRoutingNorthbound.java;h=8462ef804ad0cce4c81819bd6b0369a675673566;hb=7ea745ea554f99275d96504c09d63d24137278eb;hp=f04c9023b02a388b1256292a51ddde2d4e4fccaa;hpb=29f7cfb54b580928c7feac63abce028a7014b0d5;p=controller.git diff --git a/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthbound.java b/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthbound.java index f04c9023b0..8462ef804a 100644 --- a/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthbound.java +++ b/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthbound.java @@ -19,8 +19,11 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.core.UriInfo; import javax.xml.bind.JAXBElement; import org.codehaus.enunciate.jaxrs.ResponseCode; @@ -34,25 +37,50 @@ import org.opendaylight.controller.northbound.commons.exception.InternalServerEr import org.opendaylight.controller.northbound.commons.exception.NotAcceptableException; import org.opendaylight.controller.northbound.commons.exception.ResourceConflictException; import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException; +import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException; +import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils; +import org.opendaylight.controller.sal.authorization.Privilege; import org.opendaylight.controller.sal.utils.GlobalConstants; import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.controller.sal.utils.Status; /** - * Static Routing Northbound APIs + *
Static Routing Northbound API allows for the management of the static + * routes.
+ * + * An example request/response for retrieving the static routes may look like this: + *+ * GET http://localhost:8080/controller/nb/v2/staticroute/default HTTP/1.1 + * Accept: application/json + * + * HTTP/1.1 200 OK + * Content-Type: application/json + * + * {"staticRoute":{"name":"route-1","prefix":"10.10.1.0/24","nextHop":"1.1.1.1"}} + * + ** *
+ * Example: + * + * Request URL: + * GET http://localhost:8080/controller/nb/v2/staticroute/default + * + * Response in XML: + * <list> + * <staticRoute> + * <name>route-1</name> + * <prefix>10.10.1.0/24</prefix> + * <nextHop>1.1.1.1</nextHop> + * </staticRoute> + * </list> + * + * Response in JSON: + * {"staticRoute":{"name":"route-1","prefix":"10.10.1.0/24","nextHop":"1.1.1.1"}} + * + **/ @Path("/{containerName}") @GET @@ -90,6 +138,13 @@ public class StaticRoutingNorthbound { @ResponseCode(code = 404, condition = "The containerName passed was not found") }) public StaticRoutes getStaticRoutes( @PathParam("containerName") String containerName) { + + if(!NorthboundUtils.isAuthorized(getUserName(), containerName, + Privilege.WRITE, this)){ + throw new + UnauthorizedException("User is not authorized to perform this operation on container " + + containerName); + } return new StaticRoutes(getStaticRoutesInternal(containerName)); } @@ -97,10 +152,29 @@ public class StaticRoutingNorthbound { * Returns the static route for the provided configuration name on a given container * * @param containerName Name of the Container. The Container name for the base controller is "default". - * @param name Name of the Static Route configuration + * @param route Name of the Static Route configuration * @return Static route configured with the supplied Name. + * + *
+ * Example: + * + * Request URL: + * GET http://localhost:8080/controller/nb/v2/staticroute/default/route/route-1 + * + * Response in XML: + * + * <staticRoute> + * <name>route-1</name> + * <prefix>10.10.1.0/24</prefix> + * <nextHop>1.1.1.1</nextHop> + * </staticRoute> + * + * Response in JSON: + * {"name":"route-1","prefix":"10.10.1.0/24","nextHop":"1.1.1.1"} + * + **/ - @Path("/{containerName}/{name}") + @Path("/{containerName}/route/{route}") @GET @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @TypeHint(StaticRoute.class) @@ -109,11 +183,18 @@ public class StaticRoutingNorthbound { @ResponseCode(code = 404, condition = "The Container Name or Static Route Configuration name passed was not found") }) public StaticRoute getStaticRoute( @PathParam("containerName") String containerName, - @PathParam("name") String name) { + @PathParam("route") String route) { + + if(!NorthboundUtils.isAuthorized(getUserName(), containerName, + Privilege.WRITE, this)){ + throw new + UnauthorizedException("User is not authorized to perform this operation on container " + + containerName); + } List
+ * Example: + * + * Request URL: + * POST http://localhost:8080/controller/nb/v2/staticroute/default/route/route-1 + * + * Request payload in JSON: + * {"name":"route-1","prefix":"10.10.1.0/24","nextHop":"1.1.1.1"} + * + **/ - @Path("/{containerName}/{name}") + @Path("/{containerName}/route/{route}") @POST @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @StatusCodes( { @@ -138,10 +230,18 @@ public class StaticRoutingNorthbound { @ResponseCode(code = 406, condition = "Cannot operate on Default Container when other Containers are active"), @ResponseCode(code = 409, condition = "Failed to create Static Route entry due to Conflicting Name or Prefix."), }) public Response addStaticRoute( + @Context UriInfo uriInfo, @PathParam(value = "containerName") String containerName, - @PathParam(value = "name") String name, + @PathParam(value = "route") String route, @TypeHint(StaticRoute.class) JAXBElement
+ * Example: + * + * Request URL: + * DELETE http://localhost:8080/controller/nb/v2/staticroute/default/route/route-1 + * + **/ - - @Path("/{containerName}/{name}") + @Path("/{containerName}/route/{route}") @DELETE @StatusCodes( { @ResponseCode(code = 200, condition = "Operation successful"), @@ -181,8 +289,14 @@ public class StaticRoutingNorthbound { @ResponseCode(code = 406, condition = "Cannot operate on Default Container when other Containers are active") }) public Response removeStaticRoute( @PathParam(value = "containerName") String containerName, - @PathParam(value = "name") String name) { + @PathParam(value = "route") String route) { + if(!NorthboundUtils.isAuthorized(getUserName(), containerName, + Privilege.WRITE, this)){ + throw new + UnauthorizedException("User is not authorized to perform this operation on container " + + containerName); + } handleDefaultDisabled(containerName); IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper @@ -194,8 +308,9 @@ public class StaticRoutingNorthbound { .toString()); } - Status status = staticRouting.removeStaticRoute(name); + Status status = staticRouting.removeStaticRoute(route); if (status.isSuccess()) { + NorthboundUtils.auditlog("Static Route", username, "removed", route, containerName); return Response.ok().build(); } throw new ResourceNotFoundException(status.getDescription());