Merge "Initial pass at netvirt model"
[netvirt.git] / northbound / src / main / java / org / opendaylight / ovsdb / northbound / OvsdbNorthboundV3.java
1 /*
2  * Copyright (c) 2014, 2015 Red Hat, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.ovsdb.northbound;
10
11 import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException;
12 import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils;
13 import org.opendaylight.controller.sal.authorization.Privilege;
14
15 import javax.ws.rs.Path;
16 import javax.ws.rs.core.Context;
17 import javax.ws.rs.core.SecurityContext;
18 import javax.ws.rs.core.UriInfo;
19
20 /**
21 * OVSDB Northbound V3 REST API
22 */
23
24 @Path("/v3/")
25 public class OvsdbNorthboundV3 {
26     @Context
27     private UriInfo _uriInfo;
28     private String username;
29
30     @Context
31     public void setSecurityContext(SecurityContext context) {
32         if (context != null && context.getUserPrincipal() != null) {
33             username = context.getUserPrincipal().getName();
34         }
35     }
36
37     protected String getUserName() {
38         return username;
39     }
40
41     @Path("node")
42     public NodeResource getNode(){
43         if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) {
44             throw new UnauthorizedException("User is not authorized to perform this operation");
45         }
46         return new NodeResource();
47     }
48
49 }