OAuth2 authentication support for patch API, (HttpSbController)
Change-Id: I4b0ae5d0ab60db968812eb5d26b277a1975e8098
diff --git a/protocols/rest/api/src/main/java/org/onosproject/protocol/http/ctl/HttpSBControllerImpl.java b/protocols/rest/api/src/main/java/org/onosproject/protocol/http/ctl/HttpSBControllerImpl.java
index 602d989..c546c49 100644
--- a/protocols/rest/api/src/main/java/org/onosproject/protocol/http/ctl/HttpSBControllerImpl.java
+++ b/protocols/rest/api/src/main/java/org/onosproject/protocol/http/ctl/HttpSBControllerImpl.java
@@ -75,6 +75,7 @@
private static final String HTTPS = "https";
private static final String AUTHORIZATION_PROPERTY = "authorization";
private static final String BASIC_AUTH_PREFIX = "Basic ";
+ private static final String OAUTH2_BEARER_AUTH_PREFIX = "Bearer ";
private final Map<DeviceId, RestSBDevice> deviceMap = new ConcurrentHashMap<>();
private final Map<DeviceId, Client> clientMap = new ConcurrentHashMap<>();
@@ -227,11 +228,15 @@
try {
log.debug("Url request {} ", getUrlString(device, request));
HttpPatch httprequest = new HttpPatch(getUrlString(device, request));
- if (deviceMap.get(device).username() != null) {
+ if (deviceMap.get(device).authentication() == AuthenticationScheme.BASIC) {
String pwd = deviceMap.get(device).password() == null ? "" : COLON + deviceMap.get(device).password();
String userPassword = deviceMap.get(device).username() + pwd;
String base64string = Base64.getEncoder().encodeToString(userPassword.getBytes(StandardCharsets.UTF_8));
httprequest.addHeader(AUTHORIZATION_PROPERTY, BASIC_AUTH_PREFIX + base64string);
+ } else if (deviceMap.get(device).authentication() == AuthenticationScheme.OAUTH2) {
+ String token = deviceMap.get(device).token();
+ // TODO: support token types other then bearer of OAuth2 authentication
+ httprequest.addHeader(AUTHORIZATION_PROPERTY, OAUTH2_BEARER_AUTH_PREFIX + token);
}
if (payload != null) {
StringEntity input = new StringEntity(IOUtils.toString(payload, StandardCharsets.UTF_8));