summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-core/src/main
diff options
context:
space:
mode:
authorst782s <statta@research.att.com>2018-11-20 07:31:32 -0500
committerst782s <statta@research.att.com>2018-11-20 07:31:32 -0500
commit7246eabfd23d6cadc9f658f666df62b93f30ed70 (patch)
treef60963a0eb52e3bf645491afa5c6ed9477dc28c7 /ecomp-sdk/epsdk-core/src/main
parentace477c7097f4dc48498916ba2e024a81513ed93 (diff)
CADI Integration
Issue-ID: PORTAL-474 System to system authorization using CADI Change-Id: I76487f8155a36fca8283669fe5e28ec7d5aec91d Signed-off-by: st782s <statta@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-core/src/main')
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/auth/LoginStrategy.java3
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/controller/FusionBaseController.java11
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java10
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/AppMessagesEnum.java318
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/ErrorCodesEnum.java75
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/ErrorSeverityEnum.java42
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java503
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginExternalAuthService.java (renamed from ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/AlarmSeverityEnum.java)58
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginExternalAuthServiceImpl.java254
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UserApiService.java (renamed from ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/ErrorTypeEnum.java)57
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UserApiServiceImpl.java316
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/UserUtils.java2
12 files changed, 681 insertions, 968 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/auth/LoginStrategy.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/auth/LoginStrategy.java
index 739e086a..6a643eac 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/auth/LoginStrategy.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/auth/LoginStrategy.java
@@ -89,6 +89,7 @@ public abstract class LoginStrategy {
String password = request.getParameter("password");
commandBean.setLoginId(loginId);
commandBean.setLoginPwd(password);
+ commandBean.setUserid(loginId);
commandBean = loginService.findUser(commandBean,
(String) request.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY), new HashMap());
List<RoleFunction> roleFunctionList = roleService.getRoleFunctions(loginId);
@@ -106,7 +107,7 @@ public abstract class LoginStrategy {
SystemProperties.getProperty(SystemProperties.LOGIN_METHOD_BACKDOOR), roleFunctionList);
initateSessionMgtHandler(request);
// user has been authenticated, now take them to the welcome page
- return new ModelAndView("redirect:welcome.htm");
+ return new ModelAndView("redirect:welcome");
}
}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/controller/FusionBaseController.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/controller/FusionBaseController.java
index da731b89..bad77424 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/controller/FusionBaseController.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/controller/FusionBaseController.java
@@ -88,10 +88,15 @@ public abstract class FusionBaseController implements SecurityInterface {
String appName = appService.getDefaultAppName();
if (appName == null || appName == "")
appName = SystemProperties.SDK_NAME;
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, appName);
-
- session = request.getSession();
+ String requestId = UserUtils.getRequestId(request);
+ String loginId = "";
User user = UserUtils.getUserSession(request);
+ if (user != null) {
+ loginId = user.getLoginId();
+ }
+ logger.setRequestBasedDefaultsIntoGlobalLoggingContext(request, appName,requestId,loginId);
+
+ session = request.getSession();
if (session != null && user != null) {
Set<MenuData> menuResult = (Set<MenuData>) session
.getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME));
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java
index d250591e..55a27837 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java
@@ -42,11 +42,13 @@ import java.util.Date;
import javax.servlet.http.HttpServletRequest;
+import org.onap.portalsdk.core.domain.User;
import org.onap.portalsdk.core.logging.format.AuditLogFormatter;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.service.AppService;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
+import org.onap.portalsdk.core.web.support.UserUtils;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
@@ -107,7 +109,13 @@ public class EELFLoggerAdvice {
MDC.put(className + methodName + SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC());
if (args[0] != null && args[0] instanceof HttpServletRequest) {
HttpServletRequest req = (HttpServletRequest) args[0];
- logger.setRequestBasedDefaultsIntoGlobalLoggingContext(req, appName);
+ String requestId = UserUtils.getRequestId(req);
+ String loginId = "";
+ User user = UserUtils.getUserSession(req);
+ if (user != null) {
+ loginId = user.getLoginId();
+ }
+ logger.setRequestBasedDefaultsIntoGlobalLoggingContext(req, appName, requestId, loginId);
}
}
logger.debug(EELFLoggerDelegate.debugLogger, "{} was invoked.", methodName);
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/AppMessagesEnum.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/AppMessagesEnum.java
deleted file mode 100644
index bcc1279e..00000000
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/AppMessagesEnum.java
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * ONAP Portal SDK
- * ===================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
- *
- * Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the "License");
- * you may not use this software except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
- * you may not use this documentation except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://creativecommons.org/licenses/by/4.0/
- *
- * Unless required by applicable law or agreed to in writing, documentation
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ============LICENSE_END============================================
- *
- *
- */
-package org.onap.portalsdk.core.logging.format;
-
-public enum AppMessagesEnum {
- /*
- * 100-199 Security/Permission Related - Authentication problems (from external
- * client, to external server) - Certification errors -
- *
- * 200-299 Availability/Timeout Related - connectivity error - connection
- * timeout
- *
- * 300-399 Data Access/Integrity Related - Data in graph in invalid(E.g. no
- * creator is found for service) - Artifact is missing in ES, but exists in
- * graph.
- *
- * 400-499 Schema Interface Type/Validation - received Pay-load checksum is
- * invalid - received JSON is not valid
- *
- * 500-599 Business/Flow Processing Related - check out to service is not
- * allowed - Roll-back is done - failed to generate heat file
- *
- *
- * 600-899 Reserved - do not use
- *
- * 900-999 Unknown Errors - Unexpected exception
- */
-
- BeUebAuthenticationError(ErrorCodesEnum.BEUEBAUTHENTICATIONERROR_ONE_ARGUMENT, ErrorTypeEnum.AUTHENTICATION_PROBLEM,
- AlarmSeverityEnum.MAJOR, ErrorSeverityEnum.ERROR, "ERR100E",
- "An Authentication failure occurred during access to UEB server", "Details: {0}.",
- "Please check UEB server list and keys configured under Portal.Properties file."),
-
- BeRestApiAuthenticationError(ErrorCodesEnum.BERESTAPIAUTHENTICATIONERROR, ErrorTypeEnum.AUTHENTICATION_PROBLEM,
- AlarmSeverityEnum.MAJOR, ErrorSeverityEnum.ERROR, "ERR101E",
- "Rejected an incoming REST API request due to invalid credentials", "",
- "Please check application credentials defined in Database or properties files."),
-
- InternalAuthenticationInfo(ErrorCodesEnum.INTERNALAUTHENTICATIONINFO_ONE_ARGUMENT,
- ErrorTypeEnum.AUTHENTICATION_PROBLEM, AlarmSeverityEnum.INFORMATIONAL, ErrorSeverityEnum.INFO, "ERR199I",
- "Internal authentication problem", "Details: {0}.", "Please check the logs for more information."),
-
- InternalAuthenticationWarning(ErrorCodesEnum.INTERNALAUTHENTICATIONWARNING_ONE_ARGUMENT,
- ErrorTypeEnum.AUTHENTICATION_PROBLEM, AlarmSeverityEnum.MINOR, ErrorSeverityEnum.WARN, "ERR199W",
- "Internal authentication problem", "Details: {0}.", "Please check the logs for more information."),
-
- InternalAuthenticationError(ErrorCodesEnum.INTERNALAUTHENTICATIONERROR_ONE_ARGUMENT,
- ErrorTypeEnum.AUTHENTICATION_PROBLEM, AlarmSeverityEnum.MAJOR, ErrorSeverityEnum.ERROR, "ERR199E",
- "Internal authentication problem", "Details: {0}.", "Please check the logs for more information."),
-
- InternalAuthenticationFatal(ErrorCodesEnum.INTERNALAUTHENTICATIONFATAL_ONE_ARGUMENT,
- ErrorTypeEnum.AUTHENTICATION_PROBLEM, AlarmSeverityEnum.CRITICAL, ErrorSeverityEnum.FATAL, "ERR199F",
- "Internal authentication problem", "Details: {0}.", "Please check the logs for more information."),
-
- BeHealthCheckError(ErrorCodesEnum.BeHEALTHCHECKERROR, ErrorTypeEnum.SYSTEM_ERROR, AlarmSeverityEnum.CRITICAL,
- ErrorSeverityEnum.ERROR, "ERR200E",
- "ECOMP-PORTAL Back-end probably lost connectivity to either one of the following components: MySQL DB, UEB Cluster",
- "", "Please check the logs for more information."),
-
- BeHealthCheckMySqlError(ErrorCodesEnum.BEHEALTHCHECKMYSQLERROR, ErrorTypeEnum.SYSTEM_ERROR,
- AlarmSeverityEnum.CRITICAL, ErrorSeverityEnum.ERROR, "ERR201E",
- "ECOMP-PORTAL Back-end probably lost connectivity to MySQL DB", "",
- "Check connectivity to MYSQL is configured correctly under system.properties file."),
-
- BeHealthCheckUebClusterError(ErrorCodesEnum.BEHEALTHCHECKUEBCLUSTERERROR, ErrorTypeEnum.SYSTEM_ERROR,
- AlarmSeverityEnum.CRITICAL, ErrorSeverityEnum.ERROR, "ERR203E",
- "ECOMP-PORTAL Back-end probably lost connectivity to UEB Cluster", "",
- "Check connectivity to UEB cluster which is configured under portal.properties file."),
-
- FeHealthCheckError(ErrorCodesEnum.FEHEALTHCHECKERROR, ErrorTypeEnum.SYSTEM_ERROR, AlarmSeverityEnum.CRITICAL,
- ErrorSeverityEnum.ERROR, "ERR204E", "Unable to connect to a valid ECOMP-PORTAL Back-end Server.", "",
- "Please check connectivity from this FE instance towards BE or BE Load Balancer."),
-
- BeHealthCheckRecovery(ErrorCodesEnum.BEHEALTHCHECKRECOVERY, ErrorTypeEnum.RECOVERY, AlarmSeverityEnum.INFORMATIONAL,
- ErrorSeverityEnum.INFO, "ERR205I",
- "ECOMP-PORTAL Back-end Recovery to either one of the following components: MySQL DB, UEB Cluster", "",
- "Please check logs for more specific information about the problem."),
-
- BeHealthCheckMySqlRecovery(ErrorCodesEnum.BEHEALTHCHECKMYSQLRECOVERY, ErrorTypeEnum.RECOVERY,
- AlarmSeverityEnum.INFORMATIONAL, ErrorSeverityEnum.INFO, "ERR206I",
- "ECOMP-PORTAL Back-end connection recovery to MySQL DB", "",
- "Please check logs for more specific information about the problem."),
-
- BeHealthCheckUebClusterRecovery(ErrorCodesEnum.BEHEALTHCHECKUEBCLUSTERRECOVERY, ErrorTypeEnum.RECOVERY,
- AlarmSeverityEnum.INFORMATIONAL, ErrorSeverityEnum.INFO, "ERR208I",
- "ECOMP-PORTAL Back-end connection recovery to UEB Cluster", "",
- "Please check logs for more specific information about the problem."),
-
- FeHealthCheckRecovery(ErrorCodesEnum.FEHEALTHCHECKRECOVERY, ErrorTypeEnum.RECOVERY, AlarmSeverityEnum.INFORMATIONAL,
- ErrorSeverityEnum.INFO, "ERR209I", "Connectivity to ECOMP-PORTAL Front-end Server is recovered", "",
- "Please check logs for more specific information about the problem."),
-
- BeUebConnectionError(ErrorCodesEnum.BEUEBCONNECTIONERROR_ONE_ARGUMENT, ErrorTypeEnum.CONNECTION_PROBLEM,
- AlarmSeverityEnum.MAJOR, ErrorSeverityEnum.ERROR, "ERR210E",
- "ECOMP-PORTAL Back-end probably lost connectivity to UEB Cluster", "Details: {0}.",
- "Please check UEB server list and keys configured under Portal.Properties file."),
-
- BeUebUnkownHostError(ErrorCodesEnum.BEUEBUNKOWNHOSTERROR_ONE_ARGUMENT, ErrorTypeEnum.CONNECTION_PROBLEM,
- AlarmSeverityEnum.MAJOR, ErrorSeverityEnum.ERROR, "ERR211E",
- "ECOMP-PORTAL Back-end probably lost connectivity to UEB Cluster", "Cannot reach host: {0}.",
- "Please check UEB server list and keys configured under Portal.Properties file."),
-
- BeUebRegisterOnboardingAppError(ErrorCodesEnum.BEUEBREGISTERONBOARDINGAPPERROR, ErrorTypeEnum.CONNECTION_PROBLEM,
- AlarmSeverityEnum.MAJOR, ErrorSeverityEnum.ERROR, "ERR212E",
- "Failed to register the On-boarding application with UEB Communication server", "Details: {0}.",
- "Please check UEB server list and keys configured under Portal.Properties file."),
-
- BeHttpConnectionError(ErrorCodesEnum.BEHTTPCONNECTIONERROR_ONE_ARGUMENT, ErrorTypeEnum.CONNECTION_PROBLEM,
- AlarmSeverityEnum.MAJOR, ErrorSeverityEnum.ERROR, "ERR213E",
- "It could be that communication to an external application might resulted an exception or failed to reach the external application",
- "Details: {0}.", "Please check logs for more information."),
-
- InternalConnectionInfo(ErrorCodesEnum.INTERNALCONNECTIONINFO_ONE_ARGUMENT, ErrorTypeEnum.CONNECTION_PROBLEM,
- AlarmSeverityEnum.INFORMATIONAL, ErrorSeverityEnum.INFO, "ERR299I", "Internal Connection problem",
- "Details: {0}.", "Please check logs for more information."),
-
- InternalConnectionWarning(ErrorCodesEnum.INTERNALCONNECTIONWARNING_ONE_ARGUMENT, ErrorTypeEnum.CONNECTION_PROBLEM,
- AlarmSeverityEnum.MINOR, ErrorSeverityEnum.WARN, "ERR299W", "Internal Connection problem", "Details: {0}.",
- "Please check logs for more information."),
-
- InternalConnectionError(ErrorCodesEnum.INTERNALCONNECTIONERROR_ONE_ARGUMENT, ErrorTypeEnum.CONNECTION_PROBLEM,
- AlarmSeverityEnum.MAJOR, ErrorSeverityEnum.ERROR, "ERR299E", "Internal Connection problem", "Details: {0}.",
- "Please check logs for more information."),
-
- InternalConnectionFatal(ErrorCodesEnum.INTERNALCONNECTIONFATAL_ONE_ARGUMENT, ErrorTypeEnum.CONNECTION_PROBLEM,
- AlarmSeverityEnum.CRITICAL, ErrorSeverityEnum.FATAL, "ERR299F", "Internal Connection problem",
- "Details: {0}.", "Please check logs for more information."),
-
- BeUebObjectNotFoundError(ErrorCodesEnum.BEUEBOBJECTNOTFOUNDERROR_ONE_ARGUMENT, ErrorTypeEnum.DATA_ERROR,
- AlarmSeverityEnum.MAJOR, ErrorSeverityEnum.ERROR, "ERR303E", "Error occurred during access to U-EB Server.",
- "Data not found: {0}.",
- "An error occurred during access to UEB Server, {1} failed to either register or unregister to/from UEB topic."),
-
- BeUserMissingError(ErrorCodesEnum.BEUSERMISSINGERROR_ONE_ARGUMENT, ErrorTypeEnum.DATA_ERROR,
- AlarmSeverityEnum.MAJOR, ErrorSeverityEnum.ERROR, "ERR310E", "User is not found", "",
- "User {0} must be added to the corresponding application with proper user roles."),
-
- BeUserInactiveWarning(ErrorCodesEnum.BEUSERINACTIVEWARNING_ONE_ARGUMENT, ErrorTypeEnum.DATA_ERROR,
- AlarmSeverityEnum.MINOR, ErrorSeverityEnum.WARN, "ERR313W", "User is found but in-active", "",
- "User {0} must be added to the corresponding application with proper user roles."),
-
- BeUserAdminPrivilegesInfo(ErrorCodesEnum.BEUSERADMINPRIVILEGESINFO_ONE_ARGUMENT, ErrorTypeEnum.DATA_ERROR,
- AlarmSeverityEnum.MINOR, ErrorSeverityEnum.WARN, "ERR314W",
- "User is found but don't have administrative privileges", "",
- "User {0} should be given administrator role for the corresponding application to perform the necessary actions."),
-
- BeInvalidJsonInput(ErrorCodesEnum.BEINVALIDJSONINPUT, ErrorTypeEnum.SYSTEM_ERROR, AlarmSeverityEnum.MAJOR,
- ErrorSeverityEnum.ERROR, "ERR405E", "Failed to convert JSON input to object", "",
- "Please check logs for more information."),
-
- BeIncorrectHttpStatusError(ErrorCodesEnum.BEINCORRECTHTTPSTATUSERROR, ErrorTypeEnum.SYSTEM_ERROR,
- AlarmSeverityEnum.MAJOR, ErrorSeverityEnum.ERROR, "ERR407E",
- "Communication to an external application is resulted in with Incorrect Http response code", "",
- "Please check logs for more information."),
-
- BeInitializationError(ErrorCodesEnum.BEINITIALIZATIONERROR, ErrorTypeEnum.SYSTEM_ERROR, AlarmSeverityEnum.CRITICAL,
- ErrorSeverityEnum.ERROR, "ERR500E", "ECOMP-PORTAL Back-end was not initialized properly", "",
- "Please check logs for more information."),
-
- BeUebSystemError(ErrorCodesEnum.BEUEBSYSTEMERROR, ErrorTypeEnum.SYSTEM_ERROR, AlarmSeverityEnum.MAJOR,
- ErrorSeverityEnum.ERROR, "ERR502E", "Error occurred during access to U-EB Server", "Details: {0}.",
- "An error occurred in {1} distribution mechanism. Please check the logs for more information."),
-
- BeDaoSystemError(ErrorCodesEnum.BEDAOSYSTEMERROR, ErrorTypeEnum.SYSTEM_ERROR, AlarmSeverityEnum.CRITICAL,
- ErrorSeverityEnum.ERROR, "ERR505E", "Performing DDL or DML operations on database might have failed", "",
- "Please check MySQL DB health or look at the logs for more details."),
-
- BeSystemError(ErrorCodesEnum.BESYSTEMERROR, ErrorTypeEnum.SYSTEM_ERROR, AlarmSeverityEnum.CRITICAL,
- ErrorSeverityEnum.ERROR, "ERR506E", "Unexpected error during operation", "",
- "Please check logs for more information."),
-
- BeExecuteRollbackError(ErrorCodesEnum.BEEXECUTEROLLBACKERROR, ErrorTypeEnum.DATA_ERROR, AlarmSeverityEnum.MAJOR,
- ErrorSeverityEnum.ERROR, "ERR507E", "Roll-back operation towards database has failed", "",
- "Please check MYSQL DB health or look at the logs for more details."),
-
- FeHttpLoggingError(ErrorCodesEnum.FEHTTPLOGGINGERROR, ErrorTypeEnum.SYSTEM_ERROR, AlarmSeverityEnum.MINOR,
- ErrorSeverityEnum.ERROR, "ERR517E", "Error when logging FE HTTP request/response", "",
- "Please check MYSQL DB health or look at the logs for more details."),
-
- FePortalServletError(ErrorCodesEnum.FEPORTALSERVLETERROR, ErrorTypeEnum.SYSTEM_ERROR, AlarmSeverityEnum.MAJOR,
- ErrorSeverityEnum.ERROR, "ERR518E", "Error when trying to access FE Portal page.", "",
- "Please check logs for more information."),
-
- BeDaoCloseSessionError(ErrorCodesEnum.BEDAOCLOSESESSIONERROR, ErrorTypeEnum.SYSTEM_ERROR, AlarmSeverityEnum.MAJOR,
- ErrorSeverityEnum.ERROR, "ERR519E", "Close local session operation with database failed", "",
- "Please check MYSQL DB health or look at the logs form more details."),
-
- BeRestApiGeneralError(ErrorCodesEnum.BERESTAPIGENERALERROR, ErrorTypeEnum.SYSTEM_ERROR, AlarmSeverityEnum.CRITICAL,
- ErrorSeverityEnum.ERROR, "ERR900E", "Unexpected error during ECOMP-PORTAL Back-end REST API execution", "",
- "Please check error log for more information."),
-
- FeHealthCheckGeneralError(ErrorCodesEnum.FEHEALTHCHECKGENERALERROR, ErrorTypeEnum.SYSTEM_ERROR,
- AlarmSeverityEnum.CRITICAL, ErrorSeverityEnum.ERROR, "ERR901E", "General error during FE Health Check", "",
- "Please check error log for more information."),
-
- InternalUnexpectedInfo(ErrorCodesEnum.INTERNALUNEXPECTEDINFO_ONE_ARGUMENT, ErrorTypeEnum.SYSTEM_ERROR,
- AlarmSeverityEnum.INFORMATIONAL, ErrorSeverityEnum.INFO, "ERR999I", "Unexpected error", "Details: {0}.",
- "Please check logs for more information."),
-
- InternalUnexpectedWarning(ErrorCodesEnum.INTERNALUNEXPECTEDWARNING_ONE_ARGUMENT, ErrorTypeEnum.SYSTEM_ERROR,
- AlarmSeverityEnum.MINOR, ErrorSeverityEnum.WARN, "ERR999W", "Unexpected error", "Details: {0}.",
- "Please check logs for more information."),
-
- InternalUnexpectedError(ErrorCodesEnum.INTERNALUNEXPECTEDERROR_ONE_ARGUMENT, ErrorTypeEnum.SYSTEM_ERROR,
- AlarmSeverityEnum.MAJOR, ErrorSeverityEnum.ERROR, "ERR999E", "Unexpected error", "Details: {0}.",
- "Please check logs for more information."),
-
- InternalUnexpectedFatal(ErrorCodesEnum.INTERNALUNEXPECTEDFATAL_ONE_ARGUMENT, ErrorTypeEnum.SYSTEM_ERROR,
- AlarmSeverityEnum.CRITICAL, ErrorSeverityEnum.FATAL, "ERR999F", "Unexpected error", "Details: {0}.",
- "Please check logs for more information."),
-
- ;
-
- ErrorTypeEnum eType;
- AlarmSeverityEnum alarmSeverity;
- ErrorCodesEnum messageCode;
- ErrorSeverityEnum errorSeverity;
- String errorCode;
- String errorDescription;
- String details;
- String resolution;
-
- AppMessagesEnum(ErrorCodesEnum messageCode, ErrorTypeEnum eType, AlarmSeverityEnum alarmSeverity,
- ErrorSeverityEnum errorSeverity, String errorCode, String errorDescription, String details,
- String resolution) {
- this.messageCode = messageCode;
- this.eType = eType;
- this.alarmSeverity = alarmSeverity;
- this.errorSeverity = errorSeverity;
- this.errorCode = errorCode;
- this.errorDescription = errorDescription;
- this.details = details;
- this.resolution = resolution;
- }
-
- public String getDetails() {
- return this.details;
- }
-
- public String getResolution() {
- return this.resolution;
- }
-
- public String getErrorCode() {
- return this.errorCode;
- }
-
- public String getErrorDescription() {
- return this.errorDescription;
- }
-
- public ErrorSeverityEnum getErrorSeverity() {
- return this.errorSeverity;
- }
-
- public void setErrorSeverity(ErrorSeverityEnum errorSeverity) {
- this.errorSeverity = errorSeverity;
- }
-
- public ErrorCodesEnum getMessageCode() {
- return messageCode;
- }
-
- public void setMessageCode(ErrorCodesEnum messageCode) {
- this.messageCode = messageCode;
- }
-
- public AlarmSeverityEnum getAlarmSeverity() {
- return alarmSeverity;
- }
-
- public void setAlarmSeverity(AlarmSeverityEnum alarmSeverity) {
- this.alarmSeverity = alarmSeverity;
- }
-
- public ErrorTypeEnum getErrorType() {
- return eType;
- }
-
- public void setErrorType(ErrorTypeEnum eType) {
- this.eType = eType;
- }
-}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/ErrorCodesEnum.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/ErrorCodesEnum.java
deleted file mode 100644
index e7cf1d87..00000000
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/ErrorCodesEnum.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * ONAP Portal SDK
- * ===================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
- *
- * Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the "License");
- * you may not use this software except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
- * you may not use this documentation except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://creativecommons.org/licenses/by/4.0/
- *
- * Unless required by applicable law or agreed to in writing, documentation
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ============LICENSE_END============================================
- *
- *
- */
-package org.onap.portalsdk.core.logging.format;
-
-import com.att.eelf.i18n.EELFResolvableErrorEnum;
-//import com.att.eelf.i18n.EELFResourceManager;
-
-public enum ErrorCodesEnum implements EELFResolvableErrorEnum {
- BERESTAPIAUTHENTICATIONERROR, BEHTTPCONNECTIONERROR_ONE_ARGUMENT, BEUEBAUTHENTICATIONERROR_ONE_ARGUMENT,
-
- INTERNALAUTHENTICATIONINFO_ONE_ARGUMENT, INTERNALAUTHENTICATIONWARNING_ONE_ARGUMENT, INTERNALAUTHENTICATIONERROR_ONE_ARGUMENT, INTERNALAUTHENTICATIONFATAL_ONE_ARGUMENT,
-
- BEHEALTHCHECKRECOVERY, BEHEALTHCHECKMYSQLRECOVERY, BEHEALTHCHECKUEBCLUSTERRECOVERY, FEHEALTHCHECKRECOVERY, BeHEALTHCHECKERROR,
-
- BEHEALTHCHECKMYSQLERROR, BEHEALTHCHECKUEBCLUSTERERROR, FEHEALTHCHECKERROR, BEUEBCONNECTIONERROR_ONE_ARGUMENT, BEUEBUNKOWNHOSTERROR_ONE_ARGUMENT, BEUEBREGISTERONBOARDINGAPPERROR,
-
- INTERNALCONNECTIONINFO_ONE_ARGUMENT, INTERNALCONNECTIONWARNING_ONE_ARGUMENT, INTERNALCONNECTIONERROR_ONE_ARGUMENT, INTERNALCONNECTIONFATAL_ONE_ARGUMENT,
-
- BEUEBOBJECTNOTFOUNDERROR_ONE_ARGUMENT, BEUSERMISSINGERROR_ONE_ARGUMENT,
-
- BEUSERINACTIVEWARNING_ONE_ARGUMENT, BEUSERADMINPRIVILEGESINFO_ONE_ARGUMENT,
-
- BEINVALIDJSONINPUT, BEINCORRECTHTTPSTATUSERROR,
-
- BEINITIALIZATIONERROR, BEUEBSYSTEMERROR, BEDAOSYSTEMERROR, BESYSTEMERROR, BEEXECUTEROLLBACKERROR,
-
- FEHTTPLOGGINGERROR, FEPORTALSERVLETERROR, BEDAOCLOSESESSIONERROR,
-
- BERESTAPIGENERALERROR, FEHEALTHCHECKGENERALERROR,
-
- INTERNALUNEXPECTEDINFO_ONE_ARGUMENT, INTERNALUNEXPECTEDWARNING_ONE_ARGUMENT, INTERNALUNEXPECTEDERROR_ONE_ARGUMENT, INTERNALUNEXPECTEDFATAL_ONE_ARGUMENT,
-
- ;
-
- /**
- * Static initializer to ensure the resource bundles for this class are
- * loaded... Here this application loads messages from three bundles
- */
-
-}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/ErrorSeverityEnum.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/ErrorSeverityEnum.java
deleted file mode 100644
index 97010e62..00000000
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/ErrorSeverityEnum.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * ONAP Portal SDK
- * ===================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
- *
- * Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the "License");
- * you may not use this software except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
- * you may not use this documentation except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://creativecommons.org/licenses/by/4.0/
- *
- * Unless required by applicable law or agreed to in writing, documentation
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ============LICENSE_END============================================
- *
- *
- */
-package org.onap.portalsdk.core.logging.format;
-
-public enum ErrorSeverityEnum {
- INFO, WARN, ERROR, FATAL,
-}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java
deleted file mode 100644
index c33d7839..00000000
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegate.java
+++ /dev/null
@@ -1,503 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * ONAP Portal SDK
- * ===================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
- *
- * Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the "License");
- * you may not use this software except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
- * you may not use this documentation except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://creativecommons.org/licenses/by/4.0/
- *
- * Unless required by applicable law or agreed to in writing, documentation
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ============LICENSE_END============================================
- *
- *
- */
-package org.onap.portalsdk.core.logging.logic;
-
-import static com.att.eelf.configuration.Configuration.MDC_ALERT_SEVERITY;
-import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID;
-import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
-import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
-import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
-import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
-import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
-
-import java.net.InetAddress;
-import java.text.MessageFormat;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.onap.portalsdk.core.domain.User;
-import org.onap.portalsdk.core.logging.aspect.EELFLoggerAdvice;
-import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum;
-import org.onap.portalsdk.core.logging.format.AppMessagesEnum;
-import org.onap.portalsdk.core.logging.format.ErrorSeverityEnum;
-import org.onap.portalsdk.core.util.SystemProperties;
-import org.onap.portalsdk.core.web.support.UserUtils;
-import org.slf4j.MDC;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.att.eelf.configuration.SLF4jWrapper;
-
-
-public class EELFLoggerDelegate extends SLF4jWrapper implements EELFLogger {
-
-
- public static final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger();
- public static final EELFLogger applicationLogger = EELFManager.getInstance().getApplicationLogger();
- public static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
- public static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
- public static final EELFLogger debugLogger = EELFManager.getInstance().getDebugLogger();
-
- private String className;
- private static ConcurrentMap<String, EELFLoggerDelegate> classMap = new ConcurrentHashMap<>();
-
- public EELFLoggerDelegate(final String className) {
- super(className);
- this.className = className;
- }
-
- /**
- * Convenience method that gets a logger for the specified class.
- *
- * @see #getLogger(String)
- *
- * @param clazz
- * @return Instance of EELFLoggerDelegate
- */
- public static EELFLoggerDelegate getLogger(Class<?> clazz) {
- return getLogger(clazz.getName());
- }
-
- /**
- * Gets a logger for the specified class name. If the logger does not already
- * exist in the map, this creates a new logger.
- *
- * @param className
- * If null or empty, uses EELFLoggerDelegate as the class name.
- * @return Instance of EELFLoggerDelegate
- */
- public static EELFLoggerDelegate getLogger(final String className) {
- String classNameNeverNull = className == null || "".equals(className) ? EELFLoggerDelegate.class.getName()
- : className;
- EELFLoggerDelegate delegate = classMap.get(classNameNeverNull);
- if (delegate == null) {
- delegate = new EELFLoggerDelegate(className);
- classMap.put(className, delegate);
- }
- return delegate;
- }
-
- /**
- * Logs a message at the lowest level: trace.
- *
- * @param logger
- * @param msg
- */
- public void trace(EELFLogger logger, String msg) {
- if (logger.isTraceEnabled()) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.trace(msg);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
- }
-
- /**
- * Logs a message with parameters at the lowest level: trace.
- *
- * @param logger
- * @param msg
- * @param arguments
- */
- public void trace(EELFLogger logger, String msg, Object... arguments) {
- if (logger.isTraceEnabled()) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.trace(msg, arguments);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
- }
-
- /**
- * Logs a message and throwable at the lowest level: trace.
- *
- * @param logger
- * @param msg
- * @param th
- */
- public void trace(EELFLogger logger, String msg, Throwable th) {
- if (logger.isTraceEnabled()) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.trace(msg, th);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
- }
-
- /**
- * Logs a message at the second-lowest level: debug.
- *
- * @param logger
- * @param msg
- */
- public void debug(EELFLogger logger, String msg) {
- if (logger.isDebugEnabled()) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.debug(msg);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
- }
-
- /**
- * Logs a message with parameters at the second-lowest level: debug.
- *
- * @param logger
- * @param msg
- * @param arguments
- */
- public void debug(EELFLogger logger, String msg, Object... arguments) {
- if (logger.isDebugEnabled()) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.debug(msg, arguments);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
- }
-
- /**
- * Logs a message and throwable at the second-lowest level: debug.
- *
- * @param logger
- * @param msg
- * @param th
- */
- public void debug(EELFLogger logger, String msg, Throwable th) {
- if (logger.isDebugEnabled()) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.debug(msg, th);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
- }
-
- /**
- * Logs a message at info level.
- *
- * @param logger
- * @param msg
- */
- public void info(EELFLogger logger, String msg) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.info(msg);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
-
- /**
- * Logs a message with parameters at info level.
- *
- * @param logger
- * @param msg
- * @param arguments
- */
- public void info(EELFLogger logger, String msg, Object... arguments) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.info(msg, arguments);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
-
- /**
- * Logs a message and throwable at info level.
- *
- * @param logger
- * @param msg
- * @param th
- */
- public void info(EELFLogger logger, String msg, Throwable th) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.info(msg, th);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
-
- /**
- * Logs a message at warn level.
- *
- * @param logger
- * @param msg
- */
- public void warn(EELFLogger logger, String msg) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.warn(msg);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
-
- /**
- * Logs a message with parameters at warn level.
- *
- * @param logger
- * @param msg
- * @param arguments
- */
- public void warn(EELFLogger logger, String msg, Object... arguments) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.warn(msg, arguments);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
-
- /**
- * Logs a message and throwable at warn level.
- *
- * @param logger
- * @param msg
- * @param th
- */
- public void warn(EELFLogger logger, String msg, Throwable th) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.warn(msg, th);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
-
- /**
- * Logs a message at error level.
- *
- * @param logger
- * @param msg
- */
- public void error(EELFLogger logger, String msg) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.error(msg);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
-
- /**
- * Logs a message with parameters at error level.
- *
- * @param logger
- * @param msg
- * @param arguments
- */
- public void error(EELFLogger logger, String msg, Object... arguments) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.warn(msg, arguments);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
-
- /**
- * Logs a message and throwable at error level.
- *
- * @param logger
- * @param msg
- * @param th
- */
- public void error(EELFLogger logger, String msg, Throwable th) {
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.warn(msg, th);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
-
- /**
- * Logs a message with the associated alarm severity at error level.
- *
- * @param logger
- * @param msg
- * @param severtiy
- */
- public void error(EELFLogger logger, String msg, AlarmSeverityEnum severtiy) {
- MDC.put(MDC_ALERT_SEVERITY, severtiy.name());
- MDC.put(SystemProperties.MDC_CLASS_NAME, className);
- logger.error(msg);
- MDC.remove(MDC_ALERT_SEVERITY);
- MDC.remove(SystemProperties.MDC_CLASS_NAME);
- }
-
- /**
- * Initializes the logger context.
- */
- public void init() {
- setGlobalLoggingContext();
- final String msg = "############################ Logging is started. ############################";
- // These loggers emit the current date-time without being told.
- info(applicationLogger, msg);
- error(errorLogger, msg);
- debug(debugLogger, msg);
- // Audit and metrics logger must be told start AND stop times
- final String currentDateTime = EELFLoggerAdvice.getCurrentDateTimeUTC();
- // Set the MDC with audit properties
- MDC.put(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, currentDateTime);
- MDC.put(SystemProperties.AUDITLOG_END_TIMESTAMP, currentDateTime);
- info(auditLogger, msg);
- MDC.remove(SystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
- MDC.remove(SystemProperties.AUDITLOG_END_TIMESTAMP);
- // Set the MDC with metrics properties
- MDC.put(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP, currentDateTime);
- MDC.put(SystemProperties.METRICSLOG_END_TIMESTAMP, currentDateTime);
- info(metricsLogger, msg);
- MDC.remove(SystemProperties.METRICSLOG_BEGIN_TIMESTAMP);
- MDC.remove(SystemProperties.METRICSLOG_END_TIMESTAMP);
- }
-
- /**
- * Logs a standard message identified by the specified enum, using the specified
- * parameters, at error level. Alarm and error severity are taken from the
- * specified enum argument.
- *
- * @param epMessageEnum
- * @param param
- */
- public void logEcompError(AppMessagesEnum epMessageEnum, String... param) {
- try {
- AlarmSeverityEnum alarmSeverityEnum = epMessageEnum.getAlarmSeverity();
- ErrorSeverityEnum errorSeverityEnum = epMessageEnum.getErrorSeverity();
-
- MDC.put(MDC_ALERT_SEVERITY, alarmSeverityEnum.name());
- MDC.put("ErrorCode", epMessageEnum.getErrorCode());
- MDC.put("ErrorDescription", epMessageEnum.getErrorDescription());
-
- String resolution = this.formatMessage(epMessageEnum.getDetails() + " " + epMessageEnum.getResolution(),
- (Object[]) param);
- if (errorSeverityEnum == ErrorSeverityEnum.WARN) {
- errorLogger.warn(resolution);
- } else if (errorSeverityEnum == ErrorSeverityEnum.INFO) {
- errorLogger.info(resolution);
- } else {
- errorLogger.error(resolution);
- }
- } catch (Exception e) {
- errorLogger.error("logEcompError failed", e);
- } finally {
- MDC.remove("ErrorCode");
- MDC.remove("ErrorDescription");
- MDC.remove(MDC_ALERT_SEVERITY);
- }
- }
-
- /**
- * Builds a message using a template string and the arguments.
- *
- * @param message
- * @param args
- * @return
- */
- private String formatMessage(String message, Object... args) {
- StringBuilder sbFormattedMessage = new StringBuilder();
- if (args != null && args.length > 0 && message != null && message != "") {
- MessageFormat mf = new MessageFormat(message);
- sbFormattedMessage.append(mf.format(args));
- } else {
- sbFormattedMessage.append(message);
- }
-
- return sbFormattedMessage.toString();
- }
-
- /**
- * Loads all the default logging fields into the MDC context.
- */
- private void setGlobalLoggingContext() {
- MDC.put(MDC_SERVICE_INSTANCE_ID, "");
- MDC.put(MDC_ALERT_SEVERITY, AlarmSeverityEnum.INFORMATIONAL.toString());
- try {
- MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
- MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
- MDC.put(MDC_INSTANCE_UUID, SystemProperties.getProperty(SystemProperties.INSTANCE_UUID));
- } catch (Exception e) {
- errorLogger.error("setGlobalLoggingContext failed", e);
- }
- }
-
- public static void mdcPut(String key, String value) {
- MDC.put(key, value);
- }
-
- public static String mdcGet(String key) {
- return MDC.get(key);
- }
-
- public static void mdcRemove(String key) {
- MDC.remove(key);
- }
-
- /**
- * Loads the RequestId/TransactionId into the MDC which it should be receiving
- * with an each incoming REST API request. Also, configures few other request
- * based logging fields into the MDC context.
- *
- * @param req
- * @param appName
- */
- public void setRequestBasedDefaultsIntoGlobalLoggingContext(HttpServletRequest req, String appName) {
- // Load the default fields
- setGlobalLoggingContext();
-
- // Load the request based fields
- if (req != null) {
- // Load the Request into MDC context.
- String requestId = UserUtils.getRequestId(req);
- MDC.put(MDC_KEY_REQUEST_ID, requestId);
-
- // Load user agent into MDC context, if available.
- String accessingClient = req.getHeader(SystemProperties.USERAGENT_NAME);
- if (accessingClient != null && !"".equals(accessingClient) && (accessingClient.contains("Mozilla")
- || accessingClient.contains("Chrome") || accessingClient.contains("Safari"))) {
- accessingClient = appName + "_FE";
- }
- MDC.put(SystemProperties.PARTNER_NAME, accessingClient);
-
- // Protocol, Rest URL & Rest Path
- MDC.put(SystemProperties.FULL_URL, SystemProperties.UNKNOWN);
- MDC.put(SystemProperties.PROTOCOL, SystemProperties.HTTP);
- String restURL = UserUtils.getFullURL(req);
- if (restURL != null && restURL != "") {
- MDC.put(SystemProperties.FULL_URL, restURL);
- if (restURL.toLowerCase().contains("https")) {
- MDC.put(SystemProperties.PROTOCOL, SystemProperties.HTTPS);
- }
- }
-
- // Rest Path
- MDC.put(MDC_SERVICE_NAME, req.getServletPath());
-
- // Client IPAddress i.e. IPAddress of the remote host who is making
- // this request.
- String clientIPAddress = req.getHeader("X-FORWARDED-FOR");
- if (clientIPAddress == null) {
- clientIPAddress = req.getRemoteAddr();
- }
- MDC.put(SystemProperties.CLIENT_IP_ADDRESS, clientIPAddress);
-
- // Load loginId into MDC context.
- MDC.put(SystemProperties.MDC_LOGIN_ID, "Unknown");
-
- String loginId = "";
- User user = UserUtils.getUserSession(req);
- if (user != null) {
- loginId = user.getLoginId();
- }
-
- if (loginId != null && loginId != "") {
- MDC.put(SystemProperties.MDC_LOGIN_ID, loginId);
- }
- }
- }
-}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/AlarmSeverityEnum.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginExternalAuthService.java
index 2f56047a..306c6adf 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/AlarmSeverityEnum.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginExternalAuthService.java
@@ -1,8 +1,8 @@
-/*
+/*-
* ============LICENSE_START==========================================
* ONAP Portal SDK
* ===================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
@@ -35,22 +35,46 @@
*
*
*/
-package org.onap.portalsdk.core.logging.format;
+package org.onap.portalsdk.core.service;
-public enum AlarmSeverityEnum {
- CRITICAL("1"),
- MAJOR("2"),
- MINOR("3"),
- INFORMATIONAL("4"),
- NONE("0");
+import java.io.IOException;
+import java.util.Map;
- private final String severity;
+import javax.servlet.http.HttpServletRequest;
- AlarmSeverityEnum(String severity) {
- this.severity = severity;
- }
+import org.onap.portalsdk.core.command.LoginBean;
+import org.onap.portalsdk.core.domain.User;
- public String severity() {
- return severity;
- }
-}
+public interface LoginExternalAuthService {
+
+ /**
+ * validate user exists in the system
+ * @param bean
+ * @param menuPropertiesFilename
+ * @param additionalParams
+ * @return returns login user bean
+ * @throws IOException
+ */
+ @SuppressWarnings("rawtypes")
+ LoginBean findUser(LoginBean bean, String menuPropertiesFilename, Map additionalParams, HttpServletRequest request) throws Exception;
+
+ /**
+ *
+ * @param bean
+ * @param menuPropertiesFilename
+ * @param additionalParams
+ * @param matchPassword
+ * @return returns login user bean
+ * @throws IOException
+ */
+ @SuppressWarnings("rawtypes")
+ LoginBean findUser(LoginBean bean, String menuPropertiesFilename, Map additionalParams, boolean matchPassword, HttpServletRequest request)
+ throws Exception;
+
+ /**
+ *
+ * @param orgUserId
+ * @return
+ */
+ User findUserWithoutPwd(String orgUserId);
+} \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginExternalAuthServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginExternalAuthServiceImpl.java
new file mode 100644
index 00000000..c31ef75e
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginExternalAuthServiceImpl.java
@@ -0,0 +1,254 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalsdk.core.service;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.onap.portalsdk.core.command.LoginBean;
+import org.onap.portalsdk.core.domain.Role;
+import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.menu.MenuBuilder;
+import org.onap.portalsdk.core.service.DataAccessService;
+import org.onap.portalsdk.core.service.LoginServiceCentralizedImpl;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.portalsdk.core.web.support.AppUtils;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service("loginExternalAuthService")
+public class LoginExternalAuthServiceImpl implements LoginExternalAuthService {
+
+ private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(LoginServiceCentralizedImpl.class);
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ @Autowired
+ private UserApiService userApiService;
+
+ @Override
+ public LoginBean findUser(LoginBean bean, String menuPropertiesFilename,
+ @SuppressWarnings("rawtypes") Map additionalParams, HttpServletRequest request) throws Exception {
+ return findUser(bean, menuPropertiesFilename, additionalParams, true, request);
+ }
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ @Transactional
+ public LoginBean findUser(LoginBean bean, String menuPropertiesFilename, Map additionalParams,
+ boolean matchPassword, HttpServletRequest request) throws Exception {
+
+ User user;
+ if (bean.getUserid() != null) {
+ user = findUser(bean, request);
+ } else {
+ if (matchPassword)
+ user = findUser(bean.getLoginId(), bean.getLoginPwd());
+ else
+ user = findUserWithoutPwd(bean.getLoginId());
+ }
+
+ if (user != null) {
+ if (AppUtils.isApplicationLocked()
+ && !UserUtils.hasRole(user, SystemProperties.getProperty(SystemProperties.SYS_ADMIN_ROLE_ID))) {
+ bean.setLoginErrorMessage(SystemProperties.MESSAGE_KEY_LOGIN_ERROR_APPLICATION_LOCKED);
+ }
+
+ // raise an error if the user is inactive
+ if (!user.getActive()) {
+ bean.setLoginErrorMessage(SystemProperties.MESSAGE_KEY_LOGIN_ERROR_USER_INACTIVE);
+ }
+
+ if (!userHasActiveRoles(user)) {
+ bean.setLoginErrorMessage(SystemProperties.MESSAGE_KEY_LOGIN_ERROR_USER_INACTIVE);
+ }
+ // only login the user if no errors have occurred
+ if (bean.getLoginErrorMessage() == null) {
+
+ // this will be a snapshot of the user's information as
+ // retrieved from the database
+ User userCopy = null;
+ try {
+ userCopy = (User) user.clone();
+ } catch (CloneNotSupportedException ex) {
+ // Never happens
+ logger.error(EELFLoggerDelegate.errorLogger, "findUser failed", ex);
+ }
+
+ User appuser = findUserWithoutPwd(user.getLoginId());
+
+ if (appuser == null && userHasRoleFunctions(user)) {
+ createUserIfNecessary(user);
+ } else {
+ appuser.setLastLoginDate(new Date());
+
+ // update the last logged in date for the user
+ dataAccessService.saveDomainObject(appuser, additionalParams);
+ }
+ // update the audit log of the user
+ // Check for the client device type and set log attributes
+ // appropriately
+
+ // save the above changes to the User and their audit trail
+
+ // create the application menu based on the user's privileges
+
+ Set appMenu = getMenuBuilder().getMenu(
+ SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_SET_NAME), dataAccessService);
+ bean.setMenu(appMenu != null ? appMenu : new HashSet());
+ Set businessDirectMenu = getMenuBuilder().getMenu(
+ SystemProperties.getProperty(SystemProperties.BUSINESS_DIRECT_MENU_SET_NAME),
+ dataAccessService);
+ bean.setBusinessDirectMenu(businessDirectMenu != null ? businessDirectMenu : new HashSet());
+
+ bean.setUser(userCopy);
+ }
+ }
+
+ return bean;
+ }
+
+ private void createUserIfNecessary(User user) {
+ logger.debug(EELFLoggerDelegate.debugLogger, "createUser: " + user.getOrgUserId());
+ User user1 = new User();
+ user1.setEmail(user.getEmail());
+ user1.setEmail(user.getEmail());
+ user1.setFirstName(user.getFirstName());
+ user1.setHrid(user.getHrid());
+ user1.setJobTitle(user.getJobTitle());
+ user1.setLastName(user.getLastName());
+ user1.setLoginId(user.getLoginId());
+ user1.setOrgManagerUserId(user.getOrgManagerUserId());
+ user1.setMiddleInitial(user.getMiddleInitial());
+ user1.setOrgCode(user.getOrgCode());
+ user1.setOrgId(user.getOrgId());
+ user1.setPhone(user.getPhone());
+ user1.setOrgUserId(user.getOrgUserId());
+ user1.setActive(user.getActive());
+ user1.setLastLoginDate(new Date());
+
+ try {
+ dataAccessService.saveDomainObject(user1, null);
+ logger.debug(EELFLoggerDelegate.debugLogger, "createdUser Successfully: " + user.getOrgUserId());
+ } catch (Exception ex) {
+ logger.error(EELFLoggerDelegate.errorLogger, "createUserIfNecessary failed", ex);
+ }
+
+ }
+
+ private boolean userHasActiveRoles(User user) {
+ boolean hasActiveRole = false;
+ @SuppressWarnings("rawtypes")
+ Iterator roles = user.getRoles().iterator();
+ while (roles.hasNext()) {
+ Role role = (Role) roles.next();
+ if (role.getActive()) {
+ hasActiveRole = true;
+ break;
+ }
+ }
+ return hasActiveRole;
+ }
+
+ private boolean userHasRoleFunctions(User user) {
+ boolean hasRoleFunctions = false;
+ @SuppressWarnings("rawtypes")
+ Iterator roles = user.getRoles().iterator();
+ while (roles.hasNext()) {
+ Role role = (Role) roles.next();
+ if (role.getActive() && role.getRoleFunctions() != null && !role.getRoleFunctions().isEmpty()) {
+ hasRoleFunctions = true;
+ break;
+ }
+ }
+ return hasRoleFunctions;
+ }
+
+ private User findUser(LoginBean bean, HttpServletRequest request) throws Exception {
+ User user = userApiService.getUser(bean.getUserid(), request);
+ user.setId(getUserIdByOrgUserId(user.getOrgUserId()));
+ user.setLoginId(bean.getUserid());
+ logger.debug(EELFLoggerDelegate.debugLogger, "findUser: Returning final user roles and permissions", user.toString());
+ return user;
+ }
+
+ private Long getUserIdByOrgUserId(String orgUserId) {
+ Map<String, String> params = new HashMap<>();
+ params.put("orgUserId", orgUserId);
+ @SuppressWarnings("rawtypes")
+ List list = dataAccessService.executeNamedQuery("getUserIdByorgUserId", params, null);
+ Long userId = null;
+ if (list != null && !list.isEmpty())
+ userId = (Long) list.get(0);
+ return userId;
+ }
+
+ @SuppressWarnings("rawtypes")
+ private User findUser(String loginId, String password) {
+ Map<String, String> params = new HashMap<>();
+ params.put("login_id", loginId);
+ params.put("login_pwd", password);
+ List list = dataAccessService.executeNamedQuery("getUserByLoginIdLoginPwd", params, new HashMap());
+ return (list == null || list.isEmpty()) ? null : (User) list.get(0);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public User findUserWithoutPwd(String loginId) {
+ Map<String, String> params = new HashMap<>();
+ params.put("org_user_id", loginId);
+ List list = dataAccessService.executeNamedQuery("getUserByOrgUserId", params, new HashMap());
+ return (list == null || list.isEmpty()) ? null : (User) list.get(0);
+ }
+
+ private MenuBuilder getMenuBuilder() {
+ return new MenuBuilder();
+ }
+
+} \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/ErrorTypeEnum.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UserApiService.java
index d6f0fdf0..4e80e1ab 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/format/ErrorTypeEnum.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UserApiService.java
@@ -1,8 +1,8 @@
-/*
+/*-
* ============LICENSE_START==========================================
* ONAP Portal SDK
* ===================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
@@ -35,8 +35,53 @@
*
*
*/
-package org.onap.portalsdk.core.logging.format;
+package org.onap.portalsdk.core.service;
-public enum ErrorTypeEnum {
- RECOVERY, CONFIG_ERROR, SYSTEM_ERROR, DATA_ERROR, CONNECTION_PROBLEM, AUTHENTICATION_PROBLEM
-}
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.onap.portalsdk.core.domain.RoleFunction;
+import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.external.authorization.domain.ExternalAccessPerms;
+import org.onap.portalsdk.external.authorization.exception.UserNotFoundException;
+import org.springframework.http.ResponseEntity;
+
+public interface UserApiService {
+
+ /**
+ * Gets list of all roles associated to user from external system
+ *
+ * @param orgUserId
+ * @return
+ * @throws Exception
+ */
+ User getUser(String orgUserId, HttpServletRequest request) throws UserNotFoundException;
+
+ /**
+ *
+ * @param OrgUserId
+ * @return
+ */
+ List<RoleFunction> getRoleFunctions(String orgUserId) throws Exception;
+
+ /**
+ * Check if user exist in external auth system
+ *
+ * @param username
+ * @param password
+ * @return Response<String>
+ * @throws Exception
+ */
+ ResponseEntity<String> checkUserExists(String username, String password) throws Exception;
+
+ /**
+ * Get if user has any perms
+ *
+ * @param username
+ * @param password
+ * @return List<ExternalAccessPerms>
+ * @throws Exception
+ */
+ List<ExternalAccessPerms> getIfUserPermsExists(String username) throws Exception;
+} \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UserApiServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UserApiServiceImpl.java
new file mode 100644
index 00000000..074419e6
--- /dev/null
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UserApiServiceImpl.java
@@ -0,0 +1,316 @@
+
+
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalsdk.core.service;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.naming.NamingException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.onap.portalsdk.core.command.PostSearchBean;
+import org.onap.portalsdk.core.command.support.SearchResult;
+import org.onap.portalsdk.core.domain.App;
+import org.onap.portalsdk.core.domain.Role;
+import org.onap.portalsdk.core.domain.RoleFunction;
+import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.domain.UserApp;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.portalsdk.external.authorization.domain.ExternalAccessPerms;
+import org.onap.portalsdk.external.authorization.domain.ExternalAccessRole;
+import org.onap.portalsdk.external.authorization.domain.ExternalAccessRoleDescription;
+import org.onap.portalsdk.external.authorization.domain.ExternalAccessUserRoleDetail;
+import org.onap.portalsdk.external.authorization.exception.UserNotFoundException;
+import org.onap.portalsdk.external.authorization.service.AAFRestServiceImpl;
+import org.onap.portalsdk.external.authorization.service.AAFService;
+import org.onap.portalsdk.external.authorization.util.EcompExternalAuthProperties;
+import org.onap.portalsdk.external.authorization.util.EcompExternalAuthUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.type.TypeFactory;
+
+@Service("userApiService")
+public class UserApiServiceImpl implements UserApiService {
+
+
+ private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(UserApiServiceImpl.class);
+
+ @Autowired
+ private LoginExternalAuthService loginAAFService;
+
+ @Autowired
+ private LdapService ldapService;
+
+ @Autowired
+ private PostSearchService postSearchService;
+
+ @Autowired
+ private DataAccessService dataAccessService;
+
+ RestTemplate template = new RestTemplate();
+
+ @Autowired
+ private AppService appService;
+
+
+ private AAFService aafService = new AAFRestServiceImpl();
+
+ @Override
+ public User getUser(String orgUserId, HttpServletRequest request) throws UserNotFoundException {
+ User user = null;
+ try {
+ String namespace = EcompExternalAuthProperties
+ .getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_NAMESPACE);
+
+ HttpHeaders headers = getBasicAuthHeaders();
+ String userRoles = aafService.getUser(orgUserId, request, headers);
+ ObjectMapper mapper = new ObjectMapper();
+ List<ExternalAccessUserRoleDetail> userRoleDetailList = setExternalAccessUserRoles(namespace, userRoles,
+ mapper);
+
+ if (userRoleDetailList.isEmpty()) {
+ throw new UserNotFoundException("User roles not found!");
+ } else {
+ user = convertAAFUserRolesToEcompSDKUser(userRoleDetailList, orgUserId, namespace, request);
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getUser: Failed! ", e);
+ }
+ return user;
+
+ }
+
+ private List<ExternalAccessUserRoleDetail> setExternalAccessUserRoles(String namespace, String userRoles,
+ ObjectMapper mapper) throws IOException, JsonParseException, JsonMappingException, UserNotFoundException {
+ JSONObject userJsonObj;
+ JSONArray userJsonArray;
+ List<ExternalAccessUserRoleDetail> userRoleDetailList = new ArrayList<>();
+ if (!userRoles.equals(EcompExternalAuthUtils.EXT_EMPTY_JSON_STRING)) {
+ userJsonObj = new JSONObject(userRoles);
+ userJsonArray = userJsonObj.getJSONArray(EcompExternalAuthUtils.EXT_ROLE_FIELD);
+ ExternalAccessUserRoleDetail userRoleDetail = null;
+ for (int i = 0; i < userJsonArray.length(); i++) {
+ JSONObject role = userJsonArray.getJSONObject(i);
+ if (!role.getString(EcompExternalAuthUtils.EXT_ROLE_FIELD_NAME)
+ .endsWith(EcompExternalAuthUtils.EXT_ROLE_FIELD_ADMIN)
+ && !role.getString(EcompExternalAuthUtils.EXT_ROLE_FIELD_NAME)
+ .endsWith(EcompExternalAuthUtils.EXT_ROLE_FIELD_OWNER)) {
+ ExternalAccessRoleDescription ecDesc = new ExternalAccessRoleDescription();
+ if (role.has(EcompExternalAuthUtils.EXT_FIELD_DESCRIPTION) && EcompExternalAuthUtils
+ .isJSONValid(role.getString(EcompExternalAuthUtils.EXT_FIELD_DESCRIPTION))) {
+ ecDesc = mapper.readValue(role.getString(EcompExternalAuthUtils.EXT_FIELD_DESCRIPTION),
+ ExternalAccessRoleDescription.class);
+ }
+ List<ExternalAccessPerms> ecPerms = new ArrayList<>();
+ if (role.has(EcompExternalAuthUtils.EXT_FIELD_PERMS)) {
+ JSONArray perms = role.getJSONArray(EcompExternalAuthUtils.EXT_FIELD_PERMS);
+ ecPerms = mapper.readValue(perms.toString(), TypeFactory.defaultInstance()
+ .constructCollectionType(List.class, ExternalAccessPerms.class));
+ }
+ ExternalAccessRole ecRole = new ExternalAccessRole(
+ role.getString(EcompExternalAuthUtils.EXT_ROLE_FIELD_NAME), ecPerms, ecDesc);
+ userRoleDetail = new ExternalAccessUserRoleDetail(ecRole);
+ userRoleDetailList.add(userRoleDetail);
+ }
+ }
+ } else {
+ throw new UserNotFoundException("User roles not found!");
+ }
+ return userRoleDetailList;
+ }
+
+ private User convertAAFUserRolesToEcompSDKUser(List<ExternalAccessUserRoleDetail> userRoleDetailList,
+ String orgUserId, String namespace, HttpServletRequest request) throws Exception {
+ User user = loginAAFService.findUserWithoutPwd(orgUserId);
+ PostSearchBean postSearchBean = new PostSearchBean();
+ if (user == null) {
+ postSearchBean.setOrgUserId(orgUserId);
+ postSearchService.process(request, postSearchBean);
+ postSearchBean.setSearchResult(loadSearchResultData(postSearchBean));
+ user = (User) postSearchBean.getSearchResult().get(0);
+ user.setActive(true);
+ user.setLoginId(orgUserId);
+ dataAccessService.saveDomainObject(user, null);
+ }
+ App app = appService.getApp(1l);
+ try {
+ Set userApps = setUserApps(userRoleDetailList, namespace, user, app);
+ user.setUserApps(userApps);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "createEPUser: createEPUser failed", e);
+ throw e;
+ }
+
+ return user;
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private Set setUserApps(List<ExternalAccessUserRoleDetail> userRoleDetailList, String namespace, User user,
+ App app) {
+ Set userApps = new TreeSet();
+ for (ExternalAccessUserRoleDetail userRoleDetail : userRoleDetailList) {
+ ExternalAccessRole ecRole = userRoleDetail.getRole();
+ ExternalAccessRoleDescription roleDesc = ecRole.getDescription();
+ UserApp userApp = new UserApp();
+ Role role = new Role();
+ Set roleFunctions = new TreeSet<>();
+ if (roleDesc.getName() == null) {
+ role.setActive(true);
+ role.setName(ecRole.getName());
+ } else {
+ role.setActive(Boolean.valueOf(roleDesc.getActive()));
+ role.setId(Long.valueOf(roleDesc.getAppRoleId()));
+ role.setName(roleDesc.getName());
+ if (!roleDesc.getPriority().equals(EcompExternalAuthUtils.EXT_NULL_VALUE)) {
+ role.setPriority(Integer.valueOf(roleDesc.getPriority()));
+ }
+ }
+ for (ExternalAccessPerms extPerm : ecRole.getPerms()) {
+ RoleFunction roleFunction = new RoleFunction();
+ roleFunction.setCode(extPerm.getInstance());
+ roleFunction.setAction(extPerm.getAction());
+ if (extPerm.getDescription() != null
+ && EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) {
+ roleFunction.setName(extPerm.getDescription());
+ } else if (extPerm.getDescription() == null
+ && EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) {
+ roleFunction.setName(extPerm.getType().substring(namespace.length() + 1) + "|"
+ + extPerm.getInstance() + "|" + extPerm.getAction());
+ } else if (extPerm.getDescription() == null
+ && !EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) {
+ roleFunction.setName(extPerm.getType() + "|" + extPerm.getInstance() + "|" + extPerm.getAction());
+ }
+ if (EcompExternalAuthUtils.checkNameSpaceMatching(extPerm.getType(), namespace)) {
+ roleFunction.setType(extPerm.getType().substring(namespace.length() + 1));
+ } else {
+ roleFunction.setType(extPerm.getType());
+ }
+ roleFunctions.add(roleFunction);
+ }
+ role.setRoleFunctions(roleFunctions);
+ userApp.setApp(app);
+ userApp.setRole(role);
+ userApp.setUserId(user.getId());
+ userApps.add(userApp);
+ }
+ return userApps;
+ }
+
+ @Override
+ public List<RoleFunction> getRoleFunctions(String orgUserId) throws Exception {
+ HttpHeaders headers = getBasicAuthHeaders();
+ return aafService.getRoleFunctions(orgUserId,headers);
+ }
+
+
+ private ResponseEntity<String> getPermsFromExternalAuthSystem(HttpEntity<String> entity, String endPoint) {
+ ResponseEntity<String> getResponse = template.exchange(
+ EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_URL) + endPoint,
+ HttpMethod.GET, entity, String.class);
+ if (getResponse.getStatusCode().value() == 200) {
+ logger.debug(EELFLoggerDelegate.debugLogger,
+ "getPermsFromExternalAuthSystem: Finished GET user perms from external auth system and body: {}",
+ getResponse.getBody());
+ }
+ return getResponse;
+ }
+
+ private HttpHeaders getBasicAuthHeaders() throws Exception {
+ String userName = EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_USER_NAME);
+ String encryptedPass = EcompExternalAuthProperties
+ .getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_PASSWORD);
+ String decryptedPass = decryptPass(encryptedPass);
+ return EcompExternalAuthUtils.base64encodeKeyForAAFBasicAuth(userName, decryptedPass);
+ }
+
+ public static String decryptPass(String encrypted) throws Exception {
+ String result = "";
+ if (encrypted != null && encrypted.length() > 0) {
+ try {
+ result = CipherUtil.decryptPKC(encrypted,
+ SystemProperties.getProperty(SystemProperties.Decryption_Key));
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger,"decryptedPassword failed", e);
+ throw e;
+ }
+ }
+ return result;
+ }
+
+
+ private SearchResult loadSearchResultData(PostSearchBean searchCriteria) throws NamingException {
+ return ldapService.searchPost(searchCriteria.getUser(), searchCriteria.getSortBy1(),
+ searchCriteria.getSortBy2(), searchCriteria.getSortBy3(), searchCriteria.getPageNo(),
+ searchCriteria.getNewDataSize(), 1);
+ }
+
+ @Override
+ public ResponseEntity<String> checkUserExists(String username, String password) throws Exception {
+ String encryptedPass = EcompExternalAuthProperties
+ .getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_PASSWORD);
+ String appPassword = decryptPass(encryptedPass);
+ return aafService.checkUserExists(username,password, appPassword);
+ }
+
+
+
+ @Override
+ public List<ExternalAccessPerms> getIfUserPermsExists(String username) throws Exception {
+ HttpHeaders headers = getBasicAuthHeaders();
+ return aafService.getIfUserPermsExists(username,headers);
+ }
+
+} \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/UserUtils.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/UserUtils.java
index 915f6e55..bb58e647 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/UserUtils.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/web/support/UserUtils.java
@@ -393,7 +393,5 @@ public class UserUtils {
ecompRoleFunction.setAction(rolefun.getAction());
return ecompRoleFunction;
}
-
-
}