summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-fw/src/main/java
diff options
context:
space:
mode:
authorChristopher Lott (cl778h) <clott@research.att.com>2017-07-07 07:21:10 -0400
committerChristopher Lott (cl778h) <clott@research.att.com>2017-07-07 07:22:13 -0400
commit3e7145fc12ed8475ba10bb2a3c63004d41aa42bc (patch)
treec205d84c80e4786708caa705683a56de37c5ed2d /ecomp-sdk/epsdk-fw/src/main/java
parent952895873b6179857c6773086a4d2b55f086bd61 (diff)
[PORTAL-25] Role Centralization
Bump EP SDK version to 1.3.0-SNAPSHOT Support Role Centralization & Common Set of Roles across All ONAP On-Boarded Applications Change-Id: Icfc1bbfddaf2c7c7176b4cf7bb7017d853c63100 Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-fw/src/main/java')
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java4
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java13
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FavoritesClient.java2
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FunctionalMenuClient.java2
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/RestWebServiceClient.java174
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/util/PortalApiConstants.java2
6 files changed, 172 insertions, 25 deletions
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java
index 0efd1ce4..b2d5ef3d 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java
@@ -102,11 +102,13 @@ public interface IPortalRestAPIService {
* library will catch the exception and send an appropriate response to
* Portal.
*
+ * @param requestedLoginId
+ * requested userloginId to fetch available roles
* @return List of role attribute objects; empty list if none are found.
* @throws PortalAPIException
* If an unexpected error occurs while processing the request.
*/
- public List<EcompRole> getAvailableRoles() throws PortalAPIException;
+ public List<EcompRole> getAvailableRoles(String requestedLoginId) throws PortalAPIException;
/**
* Updates roles for the user with the specified loginId to the list of
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java
index 02d35ae9..01337f78 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java
@@ -110,7 +110,6 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
-
if (portalRestApiServiceImpl == null) {
// Should never happen due to checks in init()
logger.error("doPost: no service class instance");
@@ -145,7 +144,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
bodyMap.put("userid", userId);
requestBody = mapper.writeValueAsString(bodyMap);
responseJson = RestWebServiceClient.getInstance().postPortalContent(storeAnalyticsContextPath,
- userId, credential, null, credential, credential, "application/json", requestBody);
+ userId, credential, null, credential, credential, "application/json", requestBody, true);
if (logger.isDebugEnabled())
logger.debug("doPost: postPortalContent returns " + responseJson);
response.setStatus(HttpServletResponse.SC_OK);
@@ -321,8 +320,9 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
String credential = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY);
// for now lets also pass uebkey as user name and password
contentType = "text/javascript";
+
responseString = RestWebServiceClient.getInstance().getPortalContent(webAnalyticsContextPath,
- userId, credential, null, credential, credential);
+ userId, credential, null, credential, credential,true);
if (logger.isDebugEnabled())
logger.debug("doGet: " + webAnalyticsContextPath + ": " + responseString);
response.setStatus(HttpServletResponse.SC_OK);
@@ -398,9 +398,10 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
}
} else
// Example: /roles <-- get all roles
+
if (requestUri.endsWith(PortalApiConstants.API_PREFIX + "/roles")) {
try {
- List<EcompRole> roles = getAvailableRoles();
+ List<EcompRole> roles = getAvailableRoles(getUserId(request));
responseJson = mapper.writeValueAsString(roles);
if (logger.isDebugEnabled())
logger.debug("doGet: getAvailableRoles: " + responseJson);
@@ -484,8 +485,8 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
}
@Override
- public List<EcompRole> getAvailableRoles() throws PortalAPIException {
- return portalRestApiServiceImpl.getAvailableRoles();
+ public List<EcompRole> getAvailableRoles(String requestedLoginId) throws PortalAPIException {
+ return portalRestApiServiceImpl.getAvailableRoles(requestedLoginId);
}
@Override
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FavoritesClient.java b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FavoritesClient.java
index b4ca4755..eed49f2a 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FavoritesClient.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FavoritesClient.java
@@ -46,6 +46,6 @@ public class FavoritesClient {
public static String getFavorites(String userId, String appName, String requestId, String appUserName,
String appPassword) throws Exception {
return RestWebServiceClient.getInstance().getPortalContent("/getFavorites", userId, appName, requestId, appUserName,
- appPassword);
+ appPassword,true);
}
} \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FunctionalMenuClient.java b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FunctionalMenuClient.java
index a3a320eb..90cbdcb4 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FunctionalMenuClient.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/FunctionalMenuClient.java
@@ -48,7 +48,7 @@ public class FunctionalMenuClient {
public static String getFunctionalMenu(String userId, String appName, String requestId, String appUserName,
String appPassword) throws Exception {
return RestWebServiceClient.getInstance().getPortalContent("/functionalMenuItemsForUser", userId, appName,
- requestId, appUserName, appPassword);
+ requestId, appUserName, appPassword,true);
}
} \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/RestWebServiceClient.java b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/RestWebServiceClient.java
index f01590d4..1d4feb07 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/RestWebServiceClient.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/rest/RestWebServiceClient.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.util.Base64;
import java.util.UUID;
import org.apache.commons.logging.Log;
@@ -32,7 +33,7 @@ import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants;
import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties;
/**
- * Simple REST client for GET-ing content from and POST-ing content to the
+ * Simple REST client for GET-ing content from and POST-ing content , Delete to the
* Portal application.
*/
public class RestWebServiceClient {
@@ -86,9 +87,9 @@ public class RestWebServiceClient {
* @throws Exception
* on any failure
*/
- public String getPortalContent(String restPath, String userId, String appName, String requestId, String appUserName,
- String appPassword) throws Exception {
- String restURL = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL);
+ public String getPortalContent(String restPath,String userId, String appName, String requestId, String appUserName, String appPassword, boolean isBasicAuth) throws Exception {
+ String restURL = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL);
+
if (restURL == null) {
// should never happen
String msg = "getPortalContent: failed to get property " + PortalApiConstants.ECOMP_REST_URL;
@@ -96,17 +97,23 @@ public class RestWebServiceClient {
throw new Exception(msg);
}
String appUebKey = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY);
+
if (appUebKey == null) {
// should never happen
- String msg = "getPortalContent: failed to get property " + PortalApiConstants.UEB_APP_KEY;
+ String msg = "getPortalContent: failed to get property " + PortalApiConstants.UEB_APP_KEY;
+
logger.error(msg);
throw new Exception(msg);
}
final String restEndpointUrl = restURL + restPath;
- return get(restEndpointUrl, userId, appName, requestId, appUebKey, appUserName, appPassword);
-
+ if(isBasicAuth)
+ {
+ return get(restEndpointUrl, userId,appName, requestId, appUebKey, appUserName, appPassword,isBasicAuth);
+ }
+ return get(restEndpointUrl, userId,appName, requestId, appUebKey, appUserName, appPassword);
}
+
/**
* Makes a call to a Portal REST API using the specified URL and parameters.
*
@@ -131,8 +138,39 @@ public class RestWebServiceClient {
* @throws Exception
* On any failure; e.g., unknown host.
*/
+
public String get(String url, String loginId, String appName, String requestId, String appUebKey,
String appUserName, String appPassword) throws Exception {
+ return get(url, loginId, appName,requestId, appUebKey, appUserName, appPassword, false);
+ }
+
+
+ /**
+ * Makes a call to a Portal REST API using the specified URL and parameters.
+ *
+ * @param url
+ * Complete URL of the REST endpoint.
+ * @param loginId
+ * User that it should be fetching the data
+ * @param appName
+ * Application name for logging; if null or empty, defaulted to
+ * Unknown.
+ * @param requestId
+ * 128-bit UUID value to uniquely identify the transaction; if
+ * null or empty, one is generated.
+ * @param appUebKey
+ * Unique key for the application, used by Portal to authenticate
+ * the request
+ * @param appUserName
+ * REST API user name, used by Portal to authenticate the request
+ * @param appPassword
+ * REST API password, used by Portal to authenticate the request
+ * @return Content from REST endpoint
+ * @throws Exception
+ * On any failure; e.g., unknown host.
+ */
+ public String get(String url, String loginId, String appName, String requestId, String appUebKey,
+ String appUserName, String appPassword, Boolean useBasicAuth) throws Exception {
logger.debug("RestWebServiceClient.get (" + url + ") operation is started.");
@@ -150,12 +188,17 @@ public class RestWebServiceClient {
// add request header
con.setRequestProperty("uebkey", appUebKey);
- con.setRequestProperty("username", appUserName);
- con.setRequestProperty("password", appPassword);
con.setRequestProperty("LoginId", loginId);
con.setRequestProperty("user-agent", appName);
con.setRequestProperty("X-ECOMP-RequestID", requestId);
-
+ con.setRequestProperty("username", appUserName);
+ con.setRequestProperty("password", appPassword);
+
+ if(useBasicAuth){
+ String encoding = Base64.getEncoder().encodeToString((appUserName + ":" + appPassword).getBytes());
+ con.setRequestProperty("Authorization", "Basic "+ encoding);
+ }
+
int responseCode = con.getResponseCode();
logger.debug("get: received response code '" + responseCode + "' while getting the '" + url + "' for user: "
+ loginId);
@@ -181,7 +224,7 @@ public class RestWebServiceClient {
logger.debug("get: url " + url + " yielded " + response);
return response;
}
-
+
/**
* Convenience method that fetches the URL for the Portal REST API endpoint
* and the application UEB key, then calls
@@ -211,25 +254,30 @@ public class RestWebServiceClient {
* on any failure
*/
public String postPortalContent(String restPath, String userId, String appName, String requestId,
- String appUserName, String appPassword, String contentType, String content) throws Exception {
+ String appUserName, String appPassword, String contentType, String content, boolean isBasicAuth) throws Exception {
String restURL = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL);
+
+
if (restURL == null) {
// should never happen
String msg = "getPortalContent: failed to get property " + PortalApiConstants.ECOMP_REST_URL;
+
logger.error(msg);
throw new Exception(msg);
}
String appUebKey = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY);
+
if (appUebKey == null) {
// should never happen
String msg = "getPortalContent: failed to get property " + PortalApiConstants.UEB_APP_KEY;
+
logger.error(msg);
throw new Exception(msg);
}
final String separator = restURL.endsWith("/") || restPath.startsWith("/") ? "" : "/";
final String restEndpointUrl = restURL + separator + restPath;
return post(restEndpointUrl, userId, appName, requestId, appUebKey, appUserName, appPassword, contentType,
- content);
+ content,isBasicAuth);
}
/**
@@ -264,7 +312,7 @@ public class RestWebServiceClient {
* On any error
*/
public String post(String url, String loginId, String appName, String requestId, String appUebKey,
- String appUserName, String appPassword, String contentType, String content) throws Exception {
+ String appUserName, String appPassword, String contentType, String content, boolean isBasicAuth) throws Exception {
if (logger.isDebugEnabled())
logger.debug("RestWebServiceClient.post to URL " + url);
@@ -290,6 +338,99 @@ public class RestWebServiceClient {
con.setRequestProperty("user-agent", appName);
con.setRequestProperty("X-ECOMP-RequestID", requestId);
con.setRequestProperty("Content-Type", contentType);
+ if(isBasicAuth){
+ String encoding = Base64.getEncoder().encodeToString((appUserName + ":" + appPassword).getBytes());
+ con.setRequestProperty("Authorization", "Basic "+ encoding);
+ }
+
+ con.setDoInput(true);
+ con.setDoOutput(true);
+ con.getOutputStream().write(content.getBytes());
+ con.getOutputStream().flush();
+ con.getOutputStream().close();
+
+ int responseCode = con.getResponseCode();
+ logger.debug("Response Code : " + responseCode);
+
+ StringBuffer sb = new StringBuffer();
+ InputStreamReader in = null;
+ char[] buf = new char[8196];
+ int bytes;
+ try {
+ in = new InputStreamReader(con.getInputStream(), "UTF-8");
+ while ((bytes = in.read(buf)) > 0)
+ sb.append(new String(buf, 0, bytes));
+ } finally {
+ try {
+ if (in != null)
+ in.close();
+ } catch (IOException ex) {
+ logger.warn("get: failed to close reader", ex);
+ }
+ }
+
+ return sb.toString();
+ }
+
+
+ public String deletePortalContent(String restPath, String userId, String appName, String requestId,
+ String appUserName, String appPassword, String contentType, String content, boolean isBasicAuth ,String filter) throws Exception {
+ String restURL = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL);
+
+ if (restURL == null) {
+ // should never happen
+ String msg = "getPortalContent: failed to get property " + PortalApiConstants.ECOMP_REST_URL;
+
+ logger.error(msg);
+ throw new Exception(msg);
+ }
+ String appUebKey = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY);
+
+ if (appUebKey == null) {
+ // should never happen
+ String msg = "getPortalContent: failed to get property " + PortalApiConstants.UEB_APP_KEY;
+
+ logger.error(msg);
+ throw new Exception(msg);
+ }
+ final String separator = restURL.endsWith("/") || restPath.startsWith("/") ? "" : "/";
+ final String restEndpointUrl = restURL + separator + restPath;
+ return delete(restEndpointUrl, userId, appName, requestId, appUebKey, appUserName, appPassword, contentType,
+ content,isBasicAuth,filter);
+ }
+
+ public String delete(String url, String loginId, String appName, String requestId, String appUebKey,
+ String appUserName, String appPassword, String contentType, String content,boolean isBasicAuth ,String filter) throws Exception {
+
+ if (logger.isDebugEnabled())
+ logger.debug("RestWebServiceClient.post to URL " + url);
+ if (appName == null || appName.trim().length() == 0)
+ appName = "Unknown";
+ if (requestId == null || requestId.trim().length() == 0)
+ requestId = UUID.randomUUID().toString();
+
+ URL obj = new URL(url);
+ // Create the connection object
+ HttpURLConnection con = (HttpURLConnection) obj.openConnection();
+ con.setRequestMethod("DELETE");
+ con.setConnectTimeout(3000);
+ con.setReadTimeout(15000);
+
+ // add request header
+ con.setRequestProperty("uebkey", appUebKey);
+ if (appUserName != null)
+ con.setRequestProperty("username", appUserName);
+ if (appPassword != null)
+ con.setRequestProperty("password", appPassword);
+ con.setRequestProperty("LoginId", loginId);
+ con.setRequestProperty("user-agent", appName);
+ con.setRequestProperty("X-ECOMP-RequestID", requestId);
+ con.setRequestProperty("Content-Type", contentType);
+ con.setRequestProperty("filter", filter);
+ if(isBasicAuth){
+ String encoding = Base64.getEncoder().encodeToString((appUserName + ":" + appPassword).getBytes());
+ con.setRequestProperty("Authorization", "Basic "+ encoding);
+ }
con.setDoInput(true);
con.setDoOutput(true);
@@ -319,6 +460,7 @@ public class RestWebServiceClient {
return sb.toString();
}
+
/**
* Basic unit test for the client to call Portal app on localhost.
@@ -330,13 +472,13 @@ public class RestWebServiceClient {
public static void main(String[] args) throws Exception {
RestWebServiceClient client = RestWebServiceClient.getInstance();
final String getUrl = "http://www.ecomp.openecomp.org:8080/ecompportal/auxapi/analytics";
- String get = client.get(getUrl, "userId", "appName", null, "appUebKey", "appUserName", "appPassword");
+ String get = client.get(getUrl, "userId", "appName", null, "appUebKey", "appUserName", "appPassword", null);
System.out.println("Get result:\n" + get);
final String postUrl = "http://www.ecomp.openecomp.org:8080/ecompportal/auxapi/storeAnalytics";
final String content = " { " + " \"action\" : \"test1\", " + " \"page\" : \"test2\", "
+ " \"function\" : \"test3\", " + " \"userid\" : \"ab1234\" " + "}";
String post = client.post(postUrl, "userId", "appName", null, "appUebKey", "appUserName", "appPassword",
- "application/json", content);
+ "application/json", content, true);
System.out.println("Post result:\n" + post);
}
}
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/util/PortalApiConstants.java b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/util/PortalApiConstants.java
index e706b7ec..196d2100 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/util/PortalApiConstants.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/openecomp/portalsdk/core/onboarding/util/PortalApiConstants.java
@@ -37,6 +37,7 @@ public interface PortalApiConstants {
public static final String PORTAL_API_IMPL_CLASS = "portal.api.impl.class";
public static final String ECOMP_REDIRECT_URL = "ecomp_redirect_url";
public static final String ECOMP_REST_URL = "ecomp_rest_url";
+ public static final String ROLE_ACCESS_CENTRALIZED = "role_access_centralized";
public static final String CSP_COOKIE_NAME = "csp_cookie_name";
public static final String CSP_GATE_KEEPER_PROD_KEY = "csp_gate_keeper_prod_key";
@@ -48,6 +49,7 @@ public interface PortalApiConstants {
public static final String UEB_LISTENERS_ENABLE = "ueb_listeners_enable";
public static final String UEB_APP_INBOUND_MAILBOX_NAME = "ueb_app_mailbox_name";
public static final String UEB_APP_CONSUMER_GROUP_NAME = "ueb_app_consumer_group_name";
+
// UebManager generates a consumer group name for special token {UUID}
public static final String UEB_APP_CONSUMER_GROUP_NAME_GENERATOR = "{UUID}";
public static final String UEB_APP_KEY = "ueb_app_key";