added OAuth2 authentication for REST protocol
Change-Id: I3b8f3943ea043587730870a0b861760a4d6f3aa7
diff --git a/protocols/rest/api/src/main/java/org/onosproject/protocol/rest/DefaultRestSBDevice.java b/protocols/rest/api/src/main/java/org/onosproject/protocol/rest/DefaultRestSBDevice.java
index 8f59093..fef7f37 100644
--- a/protocols/rest/api/src/main/java/org/onosproject/protocol/rest/DefaultRestSBDevice.java
+++ b/protocols/rest/api/src/main/java/org/onosproject/protocol/rest/DefaultRestSBDevice.java
@@ -41,6 +41,8 @@
private String protocol;
private String url;
private boolean isProxy;
+ private AuthenticationScheme authenticationScheme;
+ private String token;
private final Optional<String> testUrl;
private final Optional<String> manufacturer;
private final Optional<String> hwVersion;
@@ -48,13 +50,13 @@
public DefaultRestSBDevice(IpAddress ip, int port, String name, String password,
String protocol, String url, boolean isActive) {
- this(ip, port, name, password, protocol, url, isActive, "", "", "", "");
+ this(ip, port, name, password, protocol, url, isActive, "", "", "", "", AuthenticationScheme.BASIC, "");
}
public DefaultRestSBDevice(IpAddress ip, int port, String name, String password,
String protocol, String url, boolean isActive, String testUrl, String manufacturer,
- String hwVersion,
- String swVersion) {
+ String hwVersion, String swVersion, AuthenticationScheme authenticationScheme,
+ String token) {
Preconditions.checkNotNull(ip, "IP address cannot be null");
Preconditions.checkArgument(port > 0, "Port address cannot be negative");
Preconditions.checkNotNull(protocol, "protocol address cannot be null");
@@ -65,6 +67,8 @@
this.isActive = isActive;
this.protocol = protocol;
this.url = StringUtils.isEmpty(url) ? null : url;
+ this.authenticationScheme = authenticationScheme;
+ this.token = token;
this.manufacturer = StringUtils.isEmpty(manufacturer) ?
Optional.empty() : Optional.ofNullable(manufacturer);
this.hwVersion = StringUtils.isEmpty(hwVersion) ?
@@ -159,6 +163,16 @@
}
@Override
+ public AuthenticationScheme authentication() {
+ return authenticationScheme;
+ }
+
+ @Override
+ public String token() {
+ return token;
+ }
+
+ @Override
public String toString() {
return MoreObjects.toStringHelper(this)
.omitNullValues()
@@ -168,6 +182,8 @@
.add("username", username)
.add("port", port)
.add("ip", ip)
+ .add("authentication", authenticationScheme.name())
+ .add("token", token)
.add("manufacturer", manufacturer.orElse(null))
.add("hwVersion", hwVersion.orElse(null))
.add("swVersion", swVersion.orElse(null))
diff --git a/protocols/rest/api/src/main/java/org/onosproject/protocol/rest/RestSBDevice.java b/protocols/rest/api/src/main/java/org/onosproject/protocol/rest/RestSBDevice.java
index edcce6e..6767b2d 100644
--- a/protocols/rest/api/src/main/java/org/onosproject/protocol/rest/RestSBDevice.java
+++ b/protocols/rest/api/src/main/java/org/onosproject/protocol/rest/RestSBDevice.java
@@ -26,6 +26,16 @@
*/
public interface RestSBDevice {
/**
+ * REST Authentication schemes.
+ */
+ public enum AuthenticationScheme {
+ NO_AUTHENTICATION,
+ BASIC,
+ OAUTH,
+ OAUTH2,
+ }
+
+ /**
* Returns the ip of this device.
*
* @return ip
@@ -40,6 +50,20 @@
int port();
/**
+ * The authentication scheme of rest device.
+ *
+ * @return authentication
+ */
+ AuthenticationScheme authentication();
+
+ /**
+ * The access token of rest device if authentication is OAuth2.
+ *
+ * @return token
+ */
+ String token();
+
+ /**
* Returns the username of this device.
*
* @return username
@@ -91,6 +115,7 @@
/**
* Returns the proxy state of this device
* (if true, the device is proxying multiple ONOS devices).
+ *
* @return proxy state
*/
boolean isProxy();
@@ -122,4 +147,5 @@
* @return the software version.
*/
Optional<String> swVersion();
+
}