summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk
diff options
context:
space:
mode:
authorLott, Christopher (cl778h) <cl778h@att.com>2019-07-29 11:41:36 -0400
committerLott, Christopher (cl778h) <cl778h@att.com>2019-07-30 13:35:33 -0400
commit19087734d0cd4d7e7c892490a795b01e93ba00d0 (patch)
treedc18fcd42374b9c74098b09f20ca99245b13bad5 /ecomp-sdk
parent69d4e12be832b560ed5ee1bb84a4ab3b0855310f (diff)
Publish fixed strings as public constants
Change-Id: I47c8458a0f16251ef19043eb63cf5f392990efdf Issue-ID: PORTAL-657 Signed-off-by: Lott, Christopher (cl778h) <cl778h@att.com>
Diffstat (limited to 'ecomp-sdk')
-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
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java17
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/AuthUtil.java9
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/KeyProperties.java8
-rw-r--r--ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/PortalApiProperties.java8
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxyTest.java4
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/util/AuthUtilTest.java23
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/ExtendSessionTimeoutTest.java6
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/RestClientTest.java13
-rw-r--r--ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/SessionSlotCheckIntervalTest.java6
14 files changed, 115 insertions, 101 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());
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java
index a5608746..dce26752 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClient.java
@@ -47,6 +47,7 @@ import java.util.UUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestCentralService;
import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
import org.owasp.esapi.ESAPI;
@@ -216,8 +217,8 @@ public class RestWebServiceClient {
con.setRequestProperty("user-agent", appName);
con.setRequestProperty("X-ECOMP-RequestID", requestId);
logger.debug("Post: X-ECOMP-RequestID: "+ requestId);
- con.setRequestProperty("username", appUserName);
- con.setRequestProperty("password", appPassword);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_USER, appUserName);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_PASS, appPassword);
if (useBasicAuth) {
String encoding = Base64.getEncoder().encodeToString((appUserName + ":" + appPassword).getBytes());
con.setRequestProperty("Authorization", "Basic " + encoding);
@@ -348,11 +349,11 @@ public class RestWebServiceClient {
Integer.parseInt(PortalApiProperties.getProperty(PortalApiConstants.EXT_REQUEST_READ_TIMEOUT)));
// add request header
- con.setRequestProperty("uebkey", appUebKey);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_UEB, appUebKey);
if (appUserName != null)
- con.setRequestProperty("username", appUserName);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_USER, appUserName);
if (appPassword != null)
- con.setRequestProperty("password", appPassword);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_PASS, appPassword);
con.setRequestProperty("LoginId", loginId);
con.setRequestProperty("user-agent", appName);
con.setRequestProperty("X-ECOMP-RequestID", requestId);
@@ -490,11 +491,11 @@ public class RestWebServiceClient {
Integer.parseInt(PortalApiProperties.getProperty(PortalApiConstants.EXT_REQUEST_READ_TIMEOUT)));
// add request header
- con.setRequestProperty("uebkey", appUebKey);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_UEB, appUebKey);
if (appUserName != null)
- con.setRequestProperty("username", appUserName);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_USER, appUserName);
if (appPassword != null)
- con.setRequestProperty("password", appPassword);
+ con.setRequestProperty(IPortalRestCentralService.CREDENTIALS_PASS, appPassword);
con.setRequestProperty("LoginId", loginId);
con.setRequestProperty("user-agent", appName);
con.setRequestProperty("X-ECOMP-RequestID", requestId);
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/AuthUtil.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/AuthUtil.java
index dc49933e..ac310805 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/AuthUtil.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/AuthUtil.java
@@ -53,6 +53,7 @@ import org.apache.commons.logging.LogFactory;
import org.onap.aaf.cadi.CadiWrap;
import org.onap.aaf.cadi.Permission;
import org.onap.aaf.cadi.aaf.AAFPermission;
+import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestCentralService;
import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
public class AuthUtil {
@@ -215,9 +216,9 @@ public class AuthUtil {
String appName = "";
for (Map.Entry<String, String> entry : appCredentials.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();
@@ -225,8 +226,8 @@ public class AuthUtil {
}
try {
- String appUser = request.getHeader("username");
- String password = request.getHeader("password");
+ String appUser = request.getHeader(IPortalRestCentralService.CREDENTIALS_USER);
+ String password = request.getHeader(IPortalRestCentralService.CREDENTIALS_PASS);
if (password.equals(appPassword) && appUserName.equals(appUser)) {
isauthorized = true;
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/KeyProperties.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/KeyProperties.java
index 6fa35372..28ada258 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/KeyProperties.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/KeyProperties.java
@@ -57,7 +57,7 @@ public class KeyProperties {
private static final Log logger = LogFactory.getLog(KeyProperties.class);
private static Properties properties;
- private static String propertyFileName = "key.properties";
+ public static final String PROPERTY_FILE_NAME = "key.properties";
private static final Object lockObject = new Object();
@@ -81,11 +81,11 @@ public class KeyProperties {
synchronized (lockObject) {
try {
if (!initialize()) {
- logger.error("Failed to read property file " + propertyFileName);
+ logger.error("Failed to read property file " + PROPERTY_FILE_NAME);
return null;
}
} catch (IOException e) {
- logger.error("Failed to read property file " + propertyFileName, e);
+ logger.error("Failed to read property file " + PROPERTY_FILE_NAME, e);
return null;
}
}
@@ -109,7 +109,7 @@ public class KeyProperties {
private static boolean initialize() throws IOException {
if (properties != null)
return true;
- InputStream in = KeyProperties.class.getClassLoader().getResourceAsStream(propertyFileName);
+ InputStream in = KeyProperties.class.getClassLoader().getResourceAsStream(PROPERTY_FILE_NAME);
if (in == null)
return false;
properties = new Properties();
diff --git a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/PortalApiProperties.java b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/PortalApiProperties.java
index aba57e44..501d35ca 100644
--- a/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/PortalApiProperties.java
+++ b/ecomp-sdk/epsdk-fw/src/main/java/org/onap/portalsdk/core/onboarding/util/PortalApiProperties.java
@@ -58,7 +58,7 @@ public class PortalApiProperties {
private static final Log logger = LogFactory.getLog(PortalApiProperties.class);
private static Properties properties;
- private static String propertyFileName = "portal.properties";
+ public static final String PROPERTY_FILE_NAME = "portal.properties";
private static final Object lockObject = new Object();
@@ -82,11 +82,11 @@ public class PortalApiProperties {
synchronized (lockObject) {
try {
if (!initialize()) {
- logger.error("Failed to read property file " + propertyFileName);
+ logger.error("Failed to read property file " + PROPERTY_FILE_NAME);
return null;
}
} catch (IOException e) {
- logger.error("Failed to read property file " + propertyFileName, e);
+ logger.error("Failed to read property file " + PROPERTY_FILE_NAME, e);
return null;
}
}
@@ -110,7 +110,7 @@ public class PortalApiProperties {
public static boolean initialize() throws IOException {
if (properties != null)
return true;
- InputStream in = PortalApiProperties.class.getClassLoader().getResourceAsStream(propertyFileName);
+ InputStream in = PortalApiProperties.class.getClassLoader().getResourceAsStream(PROPERTY_FILE_NAME);
if (in == null)
return false;
properties = new Properties();
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxyTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxyTest.java
index 897f84a1..35b8bf4d 100644
--- a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxyTest.java
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/PortalRestAPIProxyTest.java
@@ -138,7 +138,7 @@ public class PortalRestAPIProxyTest {
@Test
public void testDoPost_WhenRequestForStoreAnalytics() throws Exception {
Mockito.when(portalRestAPICentralServiceImpl.getUserId(request)).thenReturn("test");
- Mockito.when(portalRestAPICentralServiceImpl.getCredentials()).thenReturn(new HashMap(){{put("username","test");put("password","test");}});
+ Mockito.when(portalRestAPICentralServiceImpl.getCredentials()).thenReturn(new HashMap(){{put(IPortalRestCentralService.CREDENTIALS_USER,"test");put(IPortalRestCentralService.CREDENTIALS_PASS,"test");}});
Mockito.when(request.getRequestURI()).thenReturn(PortalApiConstants.API_PREFIX+"/storeAnalytics");
doPost.invoke(portalRestAPIProxyObj, new Object[] {request, response});
}
@@ -228,7 +228,7 @@ public class PortalRestAPIProxyTest {
@Test
public void testDoGet_WhenRequestForAnalytics() throws Exception {
Mockito.when(portalRestAPICentralServiceImpl.getUserId(request)).thenReturn("test");
- Mockito.when(portalRestAPICentralServiceImpl.getCredentials()).thenReturn(new HashMap(){{put("username","test");put("password","test");}});
+ Mockito.when(portalRestAPICentralServiceImpl.getCredentials()).thenReturn(new HashMap(){{put(IPortalRestCentralService.CREDENTIALS_USER,"test");put(IPortalRestCentralService.CREDENTIALS_PASS,"test");}});
Mockito.when(request.getRequestURI()).thenReturn(PortalApiConstants.API_PREFIX+"/analytics");
doGet.invoke(portalRestAPIProxyObj, new Object[] {request, response});
}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/util/AuthUtilTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/util/AuthUtilTest.java
index 00745922..ec3135f1 100644
--- a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/util/AuthUtilTest.java
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/util/AuthUtilTest.java
@@ -48,6 +48,7 @@ import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mockito;
import org.onap.aaf.cadi.CadiWrap;
+import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestCentralService;
import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
public class AuthUtilTest {
@@ -77,29 +78,29 @@ public class AuthUtilTest {
@Test(expected = PortalAPIException.class)
public void isAccessAllowedExceptionTest() throws PortalAPIException {
Map<String, String> appCreds = new HashMap<>();
- appCreds.put("username", "test");
- appCreds.put("password", "test1");
+ appCreds.put(IPortalRestCentralService.CREDENTIALS_USER, "test");
+ appCreds.put(IPortalRestCentralService.CREDENTIALS_PASS, "test1");
AuthUtil.isAccessAllowed(request, "com.test", appCreds);
}
@Test
public void isAccessAllowedTest() throws PortalAPIException {
- Mockito.when(request.getHeader("username")).thenReturn("test");
- Mockito.when(request.getHeader("password")).thenReturn("test1");
+ Mockito.when(request.getHeader(IPortalRestCentralService.CREDENTIALS_USER)).thenReturn("test");
+ Mockito.when(request.getHeader(IPortalRestCentralService.CREDENTIALS_PASS)).thenReturn("test1");
Map<String, String> appCreds = new HashMap<>();
- appCreds.put("username", "test");
- appCreds.put("password", "test1");
+ appCreds.put(IPortalRestCentralService.CREDENTIALS_USER, "test");
+ appCreds.put(IPortalRestCentralService.CREDENTIALS_PASS, "test1");
assertTrue(AuthUtil.isAccessAllowed(request, "com.test", appCreds));
}
@Test
public void isAccessAllowedFalseTest() throws PortalAPIException {
- Mockito.when(request.getHeader("username")).thenReturn("test");
- Mockito.when(request.getHeader("password")).thenReturn("test1");
+ Mockito.when(request.getHeader(IPortalRestCentralService.CREDENTIALS_USER)).thenReturn("test");
+ Mockito.when(request.getHeader(IPortalRestCentralService.CREDENTIALS_PASS)).thenReturn("test1");
Map<String, String> appCreds = new HashMap<>();
- appCreds.put("username", "test");
- appCreds.put("password", "test123");
- appCreds.put("appName", "testApp");
+ appCreds.put(IPortalRestCentralService.CREDENTIALS_USER, "test");
+ appCreds.put(IPortalRestCentralService.CREDENTIALS_PASS, "test123");
+ appCreds.put(IPortalRestCentralService.CREDENTIALS_APP, "testApp");
assertFalse(AuthUtil.isAccessAllowed(request, "com.test", appCreds));
}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/ExtendSessionTimeoutTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/ExtendSessionTimeoutTest.java
index d7f7ca9c..b22cff03 100644
--- a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/ExtendSessionTimeoutTest.java
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/ExtendSessionTimeoutTest.java
@@ -53,6 +53,7 @@ import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestCentralService;
import org.onap.portalsdk.core.onboarding.crossapi.SessionCommunicationService;
import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler;
import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler.SessionCommInf;
@@ -68,8 +69,9 @@ public class ExtendSessionTimeoutTest {
public static class RestResource {
@POST
@Produces(MediaType.APPLICATION_JSON)
- public String get( @HeaderParam("username") String username,
- @HeaderParam("password") String password, @HeaderParam("uebkey") String uebkey) {
+ public String get( @HeaderParam(IPortalRestCentralService.CREDENTIALS_USER) String username,
+ @HeaderParam(IPortalRestCentralService.CREDENTIALS_PASS) String password,
+ @HeaderParam(IPortalRestCentralService.CREDENTIALS_UEB) String uebkey) {
return "{ 'post-session' : '" + username + "' }";
}
}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/RestClientTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/RestClientTest.java
index 17d38264..22ce43b9 100644
--- a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/RestClientTest.java
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/RestClientTest.java
@@ -55,6 +55,7 @@ import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestCentralService;
import org.onap.portalsdk.core.onboarding.rest.RestWebServiceClient;
import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
@@ -68,18 +69,18 @@ public class RestClientTest {
public static class RestResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
- public String get(@HeaderParam("LoginId") String loginId, @HeaderParam("username") String username,
- @HeaderParam("password") String password) {
+ public String get(@HeaderParam("LoginId") String loginId, @HeaderParam(IPortalRestCentralService.CREDENTIALS_USER) String username,
+ @HeaderParam(IPortalRestCentralService.CREDENTIALS_PASS) String password) {
return "{ 'get' : '" + loginId + "' }";
}
@POST
- public String post(@HeaderParam("LoginId") String loginId, @HeaderParam("username") String username,
- @HeaderParam("password") String password) {
+ public String post(@HeaderParam("LoginId") String loginId, @HeaderParam(IPortalRestCentralService.CREDENTIALS_USER) String username,
+ @HeaderParam(IPortalRestCentralService.CREDENTIALS_PASS) String password) {
return "{ 'post' : '" + loginId + "' }";
}
@DELETE
- public String delete(@HeaderParam("LoginId") String loginId, @HeaderParam("username") String username,
- @HeaderParam("password") String password) {
+ public String delete(@HeaderParam("LoginId") String loginId, @HeaderParam(IPortalRestCentralService.CREDENTIALS_USER) String username,
+ @HeaderParam(IPortalRestCentralService.CREDENTIALS_PASS) String password) {
return "{ 'delete' : '" + loginId + "' }";
}
}
diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/SessionSlotCheckIntervalTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/SessionSlotCheckIntervalTest.java
index b922b6c7..d24f365b 100644
--- a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/SessionSlotCheckIntervalTest.java
+++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/fw/test/SessionSlotCheckIntervalTest.java
@@ -53,6 +53,7 @@ import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestCentralService;
import org.onap.portalsdk.core.onboarding.crossapi.SessionCommunicationService;
import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler;
import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler.SessionCommInf;
@@ -69,8 +70,9 @@ public class SessionSlotCheckIntervalTest {
public static class RestResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
- public String get( @HeaderParam("username") String username,
- @HeaderParam("password") String password, @HeaderParam("uebkey") String uebkey) {
+ public String get( @HeaderParam(IPortalRestCentralService.CREDENTIALS_USER) String username,
+ @HeaderParam(IPortalRestCentralService.CREDENTIALS_PASS) String password,
+ @HeaderParam(IPortalRestCentralService.CREDENTIALS_UEB) String uebkey) {
// Expects only an integer, not even a POJO/JSON model.
return timeoutValue;
}