- * Retrieve the user configured links
- *
- * @param containerName The container for which we want to retrieve the user links
- *
- * @return A List of user configured links
- */
- @Path("/{containerName}/userLink")
- @GET
- @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @TypeHint(TopologyUserLinks.class)
- @StatusCodes( { @ResponseCode(code = 404, condition = "The Container Name passed was not found") })
- public TopologyUserLinks getUserLinks(
- @PathParam("containerName") String containerName) {
- ITopologyManager topologyManager = (ITopologyManager) ServiceHelper
- .getInstance(ITopologyManager.class, containerName, this);
- if (topologyManager == null) {
- throw new ResourceNotFoundException(RestMessages.NOCONTAINER
- .toString());
- }
-
- ConcurrentMap<String, TopologyUserLinkConfig> userLinks = topologyManager.getUserLinks();
- if ((userLinks != null) && (userLinks.values() != null)) {
- List<TopologyUserLinkConfig> res = new ArrayList<TopologyUserLinkConfig>(userLinks.values());
- return new TopologyUserLinks(res);
- }
-
- return null;
- }
-
- /**
- * Add an User Link
- *
- * @param containerName Name of the Container. The base Container is "default".
- * @param TopologyUserLinkConfig in JSON or XML format
- * @return Response as dictated by the HTTP Response Status code
- */
-
- @Path("/{containerName}/userLink")
- @POST
- @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @StatusCodes( {
- @ResponseCode(code = 201, condition = "User Link added successfully"),
- @ResponseCode(code = 404, condition = "The Container Name passed was not found"),
- @ResponseCode(code = 409, condition = "Failed to add User Link due to Conflicting Name"),
- @ResponseCode(code = 500, condition = "Failed to add User Link. Failure Reason included in HTTP Error response"),
- @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
- public Response addUserLink(
- @PathParam(value = "containerName") String containerName,
- @TypeHint(TopologyUserLinkConfig.class) JAXBElement<TopologyUserLinkConfig> userLinkConfig) {
-
- ITopologyManager topologyManager = (ITopologyManager) ServiceHelper
- .getInstance(ITopologyManager.class, containerName, this);
- if (topologyManager == null) {
- throw new ResourceNotFoundException(RestMessages.NOCONTAINER
- .toString());
- }
-
- Status status = topologyManager.addUserLink(userLinkConfig.getValue());
- if (status.isSuccess()) {
- return Response.status(Response.Status.CREATED).build();
- }
- throw new InternalServerErrorException(status.getDescription());
- }
-
- /**
- * Delete an User Link
- *
- * @param containerName Name of the Container. The base Container is "default".
- * @param name Name of the Link Configuration
- * @return Response as dictated by the HTTP Response Status code
- */
-
- @Path("/{containerName}/userLink/{name}")
- @DELETE
- @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @StatusCodes( {
- @ResponseCode(code = 200, condition = "Operation successful"),
- @ResponseCode(code = 404, condition = "The Container Name or Link Configuration Name was not found"),
- @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
- public Response deleteUserLink(
- @PathParam("containerName") String containerName,
- @PathParam("name") String name) {
-
- ITopologyManager topologyManager = (ITopologyManager) ServiceHelper
- .getInstance(ITopologyManager.class, containerName, this);
- if (topologyManager == null) {
- throw new ResourceNotFoundException(RestMessages.NOCONTAINER
- .toString());
- }
-
- Status ret = topologyManager.deleteUserLink(name);
- if (ret.isSuccess()) {
- return Response.ok().build();
- }
- throw new ResourceNotFoundException(ret.getDescription());
- }
+ * Retrieve the user configured links
+ *
+ * @param containerName
+ * The container for which we want to retrieve the user links
+ *
+ * @return A List of user configured links
+ */
+ @Path("/{containerName}/userLink")
+ @GET
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @TypeHint(TopologyUserLinks.class)
+ @StatusCodes({ @ResponseCode(code = 404, condition = "The Container Name passed was not found") })
+ public TopologyUserLinks getUserLinks(
+ @PathParam("containerName") String containerName) {
+
+ if (!NorthboundUtils.isAuthorized(
+ getUserName(), containerName, Privilege.READ, this)) {
+ throw new UnauthorizedException(
+ "User is not authorized to perform this operation on container "
+ + containerName);
+ }
+ ITopologyManager topologyManager = (ITopologyManager) ServiceHelper
+ .getInstance(ITopologyManager.class, containerName, this);
+ if (topologyManager == null) {
+ throw new ResourceNotFoundException(
+ RestMessages.NOCONTAINER.toString());
+ }
+
+ ConcurrentMap<String, TopologyUserLinkConfig> userLinks = topologyManager
+ .getUserLinks();
+ if ((userLinks != null) && (userLinks.values() != null)) {
+ List<TopologyUserLinkConfig> res = new ArrayList<TopologyUserLinkConfig>(
+ userLinks.values());
+ return new TopologyUserLinks(res);
+ }
+
+ return null;
+ }
+
+ /**
+ * Add an User Link
+ *
+ * @param containerName
+ * Name of the Container. The base Container is "default".
+ * @param TopologyUserLinkConfig
+ * in JSON or XML format
+ * @return Response as dictated by the HTTP Response Status code
+ */
+
+ @Path("/{containerName}/userLink")
+ @POST
+ @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @StatusCodes({
+ @ResponseCode(code = 201, condition = "User Link added successfully"),
+ @ResponseCode(code = 404, condition = "The Container Name passed was not found"),
+ @ResponseCode(code = 409, condition = "Failed to add User Link due to Conflicting Name"),
+ @ResponseCode(code = 500, condition = "Failed to add User Link. Failure Reason included in HTTP Error response"),
+ @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
+ public Response addUserLink(
+ @PathParam(value = "containerName") String containerName,
+ @TypeHint(TopologyUserLinkConfig.class) JAXBElement<TopologyUserLinkConfig> userLinkConfig) {
+
+ if (!NorthboundUtils.isAuthorized(
+ getUserName(), containerName, Privilege.WRITE, this)) {
+ throw new UnauthorizedException(
+ "User is not authorized to perform this operation on container "
+ + containerName);
+ }
+ ITopologyManager topologyManager = (ITopologyManager) ServiceHelper
+ .getInstance(ITopologyManager.class, containerName, this);
+ if (topologyManager == null) {
+ throw new ResourceNotFoundException(
+ RestMessages.NOCONTAINER.toString());
+ }
+
+ Status status = topologyManager.addUserLink(userLinkConfig.getValue());
+ if (status.isSuccess()) {
+ return Response.status(Response.Status.CREATED).build();
+ }
+ throw new InternalServerErrorException(status.getDescription());
+ }
+
+ /**
+ * Delete an User Link
+ *
+ * @param containerName
+ * Name of the Container. The base Container is "default".
+ * @param name
+ * Name of the Link Configuration
+ * @return Response as dictated by the HTTP Response Status code
+ */
+
+ @Path("/{containerName}/userLink/{name}")
+ @DELETE
+ @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @StatusCodes({
+ @ResponseCode(code = 200, condition = "Operation successful"),
+ @ResponseCode(code = 404, condition = "The Container Name or Link Configuration Name was not found"),
+ @ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
+ public Response deleteUserLink(
+ @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);
+ }
+ ITopologyManager topologyManager = (ITopologyManager) ServiceHelper
+ .getInstance(ITopologyManager.class, containerName, this);
+ if (topologyManager == null) {
+ throw new ResourceNotFoundException(
+ RestMessages.NOCONTAINER.toString());
+ }
+
+ Status ret = topologyManager.deleteUserLink(name);
+ if (ret.isSuccess()) {
+ return Response.ok().build();
+ }
+ throw new ResourceNotFoundException(ret.getDescription());
+ }
+