Merge "Re-enable southbound build."
[netvirt.git] / northbound / src / main / java / org / opendaylight / ovsdb / northbound / OvsdbNorthboundV3.java
1 /*
2  * Copyright (C) 2014 Red Hat, Inc. and others
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  * Authors : Madhu Venugopal
9  */
10 package org.opendaylight.ovsdb.northbound;
11
12 import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException;
13 import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils;
14 import org.opendaylight.controller.sal.authorization.Privilege;
15
16 import javax.ws.rs.Path;
17 import javax.ws.rs.core.Context;
18 import javax.ws.rs.core.SecurityContext;
19 import javax.ws.rs.core.UriInfo;
20
21 /**
22 * OVSDB Northbound V3 REST API
23 */
24
25 @Path("/v3/")
26 public class OvsdbNorthboundV3 {
27     @Context
28     private UriInfo _uriInfo;
29     private String username;
30
31     @Context
32     public void setSecurityContext(SecurityContext context) {
33         if (context != null && context.getUserPrincipal() != null) {
34             username = context.getUserPrincipal().getName();
35         }
36     }
37
38     protected String getUserName() {
39         return username;
40     }
41
42     @Path("node")
43     public NodeResource getNode(){
44         if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) {
45             throw new UnauthorizedException("User is not authorized to perform this operation");
46         }
47         return new NodeResource();
48     }
49
50 }