summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java')
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxy.java85
1 files changed, 40 insertions, 45 deletions
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()) {