summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi
diff options
context:
space:
mode:
authorManoop Talasila <talasila@research.att.com>2019-07-31 20:16:05 +0000
committerGerrit Code Review <gerrit@onap.org>2019-07-31 20:16:05 +0000
commit71cf9cbe286d92e38b517e3a5829ba833859c93f (patch)
treeb0c48a9b1b6738fb44d4b1679dd8bf2ddac12395 /ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi
parent97b02765d0528f1c03c42597cfefe36f0c3a9d09 (diff)
parent19087734d0cd4d7e7c892490a795b01e93ba00d0 (diff)
Merge "Publish fixed strings as public constants"
Diffstat (limited to 'ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi')
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java2
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestCentralService.java11
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPICentralServiceImpl.java12
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java85
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationService.java12
5 files changed, 64 insertions, 58 deletions
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java
index c707d137..0c445bd3 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestAPIService.java
@@ -172,6 +172,8 @@ public interface IPortalRestAPIService {
*
* @param request
* HttpServletRequest
+ * @param appCredentials
+ * Map with app name, user name, password
* @return true if the request contains appropriate credentials, else false.
* @throws PortalAPIException
* If an unexpected error occurs while processing the request.
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestCentralService.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestCentralService.java
index 87b460e3..2d35a9f9 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestCentralService.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/IPortalRestCentralService.java
@@ -46,13 +46,22 @@ import org.onap.portalsdk.core.restful.domain.EcompUser;
public interface IPortalRestCentralService {
+ public static final String CREDENTIALS_APP = "appName";
+ public static final String CREDENTIALS_USER = "username";
+ public static final String CREDENTIALS_PASS = "password";
+ public static final String CREDENTIALS_UEB = "uebkey";
+
/**
* Gets and returns the Map with username, password and appName of application .If any error
* occurs, the method should throw PortalApiException with an appropriate
* message. The FW library will catch the exception and send an appropriate
* response to Portal.
*
- * @return a map with keys username, password and appName
+ * @return a map with keys {@link IPortalRestCentralService#CREDENTIALS_APP},
+ * {@link IPortalRestCentralService#CREDENTIALS_USER}, and
+ * {@link IPortalRestCentralService#CREDENTIALS_PASS},
+ * @throws PortalAPIException
+ * If any error occurs
*/
public Map<String, String> getAppCredentials() throws PortalAPIException;
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPICentralServiceImpl.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPICentralServiceImpl.java
index 27e90221..54ce2f4f 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPICentralServiceImpl.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPICentralServiceImpl.java
@@ -81,9 +81,9 @@ public class PortalRestAPICentralServiceImpl implements IPortalRestAPIService {
try {
Class<?> centralImplClass = Class.forName(centralClassName);
portalRestCentralService = (IPortalRestCentralService) (centralImplClass.getConstructor().newInstance());
- username = portalRestCentralService.getAppCredentials().get("username");
- password = portalRestCentralService.getAppCredentials().get("password");
- appName = portalRestCentralService.getAppCredentials().get("appName");
+ username = portalRestCentralService.getAppCredentials().get(IPortalRestCentralService.CREDENTIALS_USER);
+ password = portalRestCentralService.getAppCredentials().get(IPortalRestCentralService.CREDENTIALS_PASS);
+ appName = portalRestCentralService.getAppCredentials().get(IPortalRestCentralService.CREDENTIALS_APP);
} catch (Exception e) {
throw new ClassCastException("Failed to find or instantiate class ");
}
@@ -205,9 +205,9 @@ public class PortalRestAPICentralServiceImpl implements IPortalRestAPIService {
public Map<String, String> getCredentials() throws PortalAPIException{
Map<String, String> credentialsMap = new HashMap<>();
- credentialsMap.put("username", username);
- credentialsMap.put("password", password);
- credentialsMap.put("appName", appName);
+ credentialsMap.put(IPortalRestCentralService.CREDENTIALS_USER, username);
+ credentialsMap.put(IPortalRestCentralService.CREDENTIALS_PASS, password);
+ credentialsMap.put(IPortalRestCentralService.CREDENTIALS_APP, appName);
return credentialsMap;
}
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java
index 29095970..15f0d664 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java
@@ -95,7 +95,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@WebServlet(urlPatterns = { PortalApiConstants.API_PREFIX + "/*" })
public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPIService {
-
+
private static final long serialVersionUID = 1L;
private static final String APPLICATION_JSON = "application/json";
@@ -113,10 +113,9 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
private static IPortalRestAPIService portalRestApiServiceImpl;
private static final String isAccessCentralized = PortalApiProperties
.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED);
- private static final String errorMessage = "Access Management is not allowed for Centralized applications." ;
+ private static final String errorMessage = "Access Management is not allowed for Centralized applications.";
private static final String isCentralized = "remote";
-
public PortalRestAPIProxy() {
// Ensure that any additional fields sent by the Portal
// will be ignored when creating objects.
@@ -135,7 +134,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
if (!isCentralized.equals(isAccessCentralized))
portalRestApiServiceImpl = (IPortalRestAPIService) (implClass.getConstructor().newInstance());
else {
- portalRestApiServiceImpl = new PortalRestAPICentralServiceImpl();
+ portalRestApiServiceImpl = new PortalRestAPICentralServiceImpl();
}
} catch (Exception ex) {
throw new ServletException("init: Failed to find or instantiate class " + className, ex);
@@ -152,8 +151,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
response.getWriter().write(buildJsonResponse(false, "Misconfigured - no instance of service class"));
return;
}
-
-
+
String requestUri = request.getRequestURI();
String responseJson = "";
String storeAnalyticsContextPath = "/storeAnalytics";
@@ -178,15 +176,15 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
for (Map.Entry<String, String> entry : getCredentials().entrySet()) {
- if (entry.getKey().equalsIgnoreCase("username")) {
+ if (entry.getKey().equalsIgnoreCase(IPortalRestCentralService.CREDENTIALS_USER)) {
appUserName = entry.getValue();
- } else if (entry.getKey().equalsIgnoreCase("password")) {
+ } else if (entry.getKey().equalsIgnoreCase(IPortalRestCentralService.CREDENTIALS_PASS)) {
appPassword = entry.getValue();
} else {
appName = entry.getValue();
}
}
-
+
String credential = PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY);
// for now lets also pass uebkey as user name and password
String requestBody = readRequestBody(request);
@@ -195,7 +193,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
// add user ID
bodyMap.put("userid", userId);
requestBody = mapper.writeValueAsString(bodyMap);
- logger.debug("doPost: StoreAnalytics requestbody: "+ requestBody);
+ logger.debug("doPost: StoreAnalytics requestbody: " + requestBody);
responseJson = RestWebServiceClient.getInstance().postPortalContent(storeAnalyticsContextPath,
userId, appName, null, appUserName, appPassword, "application/json", requestBody, true);
logger.debug("doPost: postPortalContent returns " + responseJson);
@@ -225,7 +223,6 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
writeAndFlush(response, APPLICATION_JSON, buildJsonResponse(false, "Not authorized"));
return;
}
-
try {
String requestBody = readRequestBody(request);
@@ -273,7 +270,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
if (requestUri.endsWith(PortalApiConstants.API_PREFIX + "/user")) {
try {
EcompUser user = mapper.readValue(requestBody, EcompUser.class);
- logger.debug("doPost: create user requestbody: "+ requestBody);
+ logger.debug("doPost: create user requestbody: " + requestBody);
Set<EcompRole> userEcompRoles = getEcompRolesOfUser(user);
user.setRoles(userEcompRoles);
pushUser(user);
@@ -282,17 +279,17 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
responseJson = buildJsonResponse(true, "user saved successfully");
response.setStatus(HttpServletResponse.SC_OK);
} catch (Exception ex) {
- responseJson = buildShortJsonResponse(ex);
+ responseJson = buildShortJsonResponse(ex);
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
logger.error("doPost: pushUser: caught exception", ex);
}
} else
- // Example: /user/abc <-- edit user abc
+ // Example: /user/abc <-- edit user abc
if (requestUri.contains(PortalApiConstants.API_PREFIX + "/user/") && !(requestUri.endsWith("/roles"))) {
String loginId = requestUri.substring(requestUri.lastIndexOf('/') + 1);
try {
EcompUser user = mapper.readValue(requestBody, EcompUser.class);
- logger.debug("doPost: update user requestbody: "+ requestBody);
+ logger.debug("doPost: update user requestbody: " + requestBody);
Set<EcompRole> userEcompRoles = getEcompRolesOfUser(user);
user.setRoles(userEcompRoles);
editUser(loginId, user);
@@ -301,7 +298,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
responseJson = buildJsonResponse(true, "user saved successfully");
response.setStatus(HttpServletResponse.SC_OK);
} catch (Exception ex) {
- responseJson = buildShortJsonResponse(ex);
+ responseJson = buildShortJsonResponse(ex);
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
logger.error("doPost: editUser: caught exception", ex);
}
@@ -331,7 +328,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
}
} else {
String msg = "doPost: no match for request " + requestUri;
- logger.warn( ESAPI.encoder().encodeForHTML(msg));
+ logger.warn(ESAPI.encoder().encodeForHTML(msg));
responseJson = buildJsonResponse(false, msg);
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
@@ -357,7 +354,6 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
buildJsonResponse(false, "Misconfigured - no instance of service class"));
return;
}
-
String requestUri = request.getRequestURI();
String contentType = APPLICATION_JSON;
@@ -384,9 +380,9 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
for (Map.Entry<String, String> entry : getCredentials().entrySet()) {
- if (entry.getKey().equalsIgnoreCase("username")) {
+ if (entry.getKey().equalsIgnoreCase(IPortalRestCentralService.CREDENTIALS_USER)) {
appUserName = entry.getValue();
- } else if (entry.getKey().equalsIgnoreCase("password")) {
+ } else if (entry.getKey().equalsIgnoreCase(IPortalRestCentralService.CREDENTIALS_PASS)) {
appPassword = entry.getValue();
} else {
appName = entry.getValue();
@@ -398,7 +394,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
responseString = RestWebServiceClient.getInstance().getPortalContent(webAnalyticsContextPath,
userId, appName, null, appUserName, appPassword, true);
-
+
if (logger.isDebugEnabled())
logger.debug("doGet: " + webAnalyticsContextPath + ": " + responseString);
response.setStatus(HttpServletResponse.SC_OK);
@@ -445,14 +441,14 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
*/
if (requestUri.endsWith("/sessionTimeOuts")) {
- try {
+ try {
responseJson = getSessionTimeOuts();
logger.debug("doGet: got session timeouts");
response.setStatus(HttpServletResponse.SC_OK);
- } catch(Exception ex) {
+ } catch (Exception ex) {
String msg = "Failed to get session time outs";
logger.error("doGet: " + msg);
- responseJson = buildShortJsonResponse(ex);
+ responseJson = buildShortJsonResponse(ex);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
} else
@@ -478,7 +474,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
if (logger.isDebugEnabled())
logger.debug("doGet: getAvailableRoles: " + responseJson);
} catch (Exception ex) {
- responseJson = buildShortJsonResponse(ex);
+ responseJson = buildShortJsonResponse(ex);
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
logger.error("doGet: getAvailableRoles: caught exception", ex);
}
@@ -492,7 +488,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
if (logger.isDebugEnabled())
logger.debug("doGet: getUser: " + responseJson);
} catch (Exception ex) {
- responseJson = buildShortJsonResponse(ex);
+ responseJson = buildShortJsonResponse(ex);
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
logger.error("doGet: getUser: caught exception", ex);
}
@@ -511,8 +507,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
logger.error("doGet: getUserRoles: caught exception", ex);
}
- }
- else {
+ } else {
logger.warn("doGet: no match found for request");
responseJson = buildJsonResponse(false, "No match for request");
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
@@ -573,7 +568,8 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
}
@Override
- public boolean isAppAuthenticated(HttpServletRequest request, Map<String,String> appCredentials) throws PortalAPIException {
+ public boolean isAppAuthenticated(HttpServletRequest request, Map<String, String> appCredentials)
+ throws PortalAPIException {
return portalRestApiServiceImpl.isAppAuthenticated(request, appCredentials);
}
@@ -605,22 +601,22 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
String body = null;
StringBuilder stringBuilder = new StringBuilder();
- try(InputStream inputStream = request.getInputStream()) {
+ try (InputStream inputStream = request.getInputStream()) {
if (inputStream != null) {
- try(BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));){
+ try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));) {
char[] charBuffer = new char[1024];
int bytesRead = -1;
while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
stringBuilder.append(charBuffer, 0, bytesRead);
}
- } catch(IOException e) {
+ } catch (IOException e) {
logger.error("readRequestBody", e);
throw e;
}
} else {
stringBuilder.append("");
}
- } catch(IOException e) {
+ } catch (IOException e) {
logger.error("readRequestBody", e);
throw e;
}
@@ -632,9 +628,10 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
* Builds JSON object with status + message response body.
*
* @param success
- * True to indicate success, false to signal failure.
+ * True to indicate success, false to signal failure.
* @param msg
- * Message to include in the response object; ignored if null.
+ * Message to include in the response object; ignored if
+ * null.
* @return
*
* <pre>
@@ -659,7 +656,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
* for the specified throwable.
*
* @param t
- * Throwable with stack trace to use as message
+ * Throwable with stack trace to use as message
*
* @return
*
@@ -673,9 +670,8 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
t.printStackTrace(pw);
return buildJsonResponse(false, sw.toString());
}
-
- private String buildShortJsonResponse(Throwable t)
- {
+
+ private String buildShortJsonResponse(Throwable t) {
String errorMessage = t.getMessage();
return buildJsonResponse(false, errorMessage);
}
@@ -692,15 +688,14 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
public static void setPortalRestApiServiceImpl(IPortalRestAPIService portalRestApiServiceImpl) {
PortalRestAPIProxy.portalRestApiServiceImpl = portalRestApiServiceImpl;
}
-
+
@Override
- public Map<String, String> getCredentials() throws PortalAPIException {
+ public Map<String, String> getCredentials() throws PortalAPIException {
return portalRestApiServiceImpl.getCredentials();
}
- private Set<EcompRole> getEcompRolesOfUser(EcompUser user) throws JsonProcessingException
- {
-
+ private Set<EcompRole> getEcompRolesOfUser(EcompUser user) throws JsonProcessingException {
+
Set<EcompRole> userEcompRoles = new TreeSet<>();
Set<EcompRole> ecompRoles = user.getRoles();
for (EcompRole role : ecompRoles) {
@@ -715,7 +710,7 @@ public class PortalRestAPIProxy extends HttpServlet implements IPortalRestAPISer
Map<String, String> result = Arrays.stream(str1.split(",")).map(s -> s.split(":"))
.collect(Collectors.toMap(a -> a[0], // key
a -> a[1] // value
- ));
+ ));
EcompRoleFunction roleFunction = new EcompRoleFunction();
for (Map.Entry<String, String> set : result.entrySet()) {
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationService.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationService.java
index 847707bc..3a886af6 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationService.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationService.java
@@ -79,9 +79,9 @@ public class SessionCommunicationService {
con.setConnectTimeout(3000);
con.setReadTimeout(8000);
// add request header
- con.setRequestProperty("username", userName);
- con.setRequestProperty("password", password);
- con.setRequestProperty("uebkey", uebKey);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_USER, userName);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_PASS, password);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_UEB, uebKey);
String encoding = Base64.getEncoder().encodeToString((userName + ":" + password).getBytes());
con.setRequestProperty("Authorization", "Basic " + encoding);
@@ -138,9 +138,9 @@ public class SessionCommunicationService {
con.setReadTimeout(15000);
// add request header
- con.setRequestProperty("username", userName);
- con.setRequestProperty("password", password);
- con.setRequestProperty("uebkey", uebKey);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_USER, userName);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_PASS, password);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_UEB, uebKey);
con.setRequestProperty("sessionMap", sessionTimeoutMap);
String encoding = Base64.getEncoder().encodeToString((userName + ":" + password).getBytes());