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;fp=opendaylight%2Fnorthbound%2Fstaticrouting%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fforwarding%2Fstaticrouting%2Fnorthbound%2FStaticRoutingNorthbound.java;h=c48d7ec02684463962909ec2d60b600e3b270167;hb=af9729aac43f1dd32b77076d757e3052d7a8e87b;hp=f04c9023b02a388b1256292a51ddde2d4e4fccaa;hpb=60ba2f16a5cfa1bc7bcfa0089df544225c70a4cd;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..c48d7ec026 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,10 @@ 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.xml.bind.JAXBElement; import org.codehaus.enunciate.jaxrs.ResponseCode; @@ -34,6 +36,9 @@ 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; @@ -53,6 +58,19 @@ import org.opendaylight.controller.sal.utils.Status; @Path("/") public class StaticRoutingNorthbound { + + private String username; + + @Context + public void setSecurityContext(SecurityContext context) { + username = context.getUserPrincipal().getName(); + } + protected String getUserName() { + return username; + } + + + private List getStaticRoutesInternal(String containerName) { IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper @@ -90,6 +108,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)); } @@ -110,6 +135,13 @@ public class StaticRoutingNorthbound { public StaticRoute getStaticRoute( @PathParam("containerName") String containerName, @PathParam("name") String name) { + + if(!NorthboundUtils.isAuthorized(getUserName(), containerName, + Privilege.WRITE, this)){ + throw new + UnauthorizedException("User is not authorized to perform this operation on container " + + containerName); + } List routes = this.getStaticRoutesInternal(containerName); for (StaticRoute route : routes) { if (route.getName().equalsIgnoreCase(name)) { @@ -142,6 +174,13 @@ public class StaticRoutingNorthbound { @PathParam(value = "name") String name, @TypeHint(StaticRoute.class) JAXBElement staticRouteData) { + + 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 @@ -182,7 +221,13 @@ public class StaticRoutingNorthbound { public Response removeStaticRoute( @PathParam(value = "containerName") String containerName, @PathParam(value = "name") String name) { - + + 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