[PORTAL-7] Rebase
[portal.git] / ecomp-portal-BE-os / src / main / java / org / openecomp / portalapp / service / RemoteWebServiceCallServiceImpl.java
1 /*-
2  * ================================================================================
3  * ECOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 package org.openecomp.portalapp.service;
21
22 import java.util.List;
23
24 import org.openecomp.portalapp.portal.domain.EPApp;
25 import org.openecomp.portalapp.portal.service.AppsCacheService;
26 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
27 import org.openecomp.portalsdk.core.onboarding.util.CipherUtil;
28 import org.openecomp.portalsdk.core.service.WebServiceCallServiceImpl;
29 import org.openecomp.portalsdk.core.util.SystemProperties;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.context.annotation.EnableAspectJAutoProxy;
32 import org.springframework.stereotype.Service;
33 import org.springframework.transaction.annotation.Transactional;
34
35 @Service("remoteWebServiceCallService")
36 @Transactional
37 @org.springframework.context.annotation.Configuration
38 @EnableAspectJAutoProxy
39 public class RemoteWebServiceCallServiceImpl extends WebServiceCallServiceImpl implements RemoteWebServiceCallService {
40
41         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RemoteWebServiceCallServiceImpl.class);
42         @Autowired
43         AppsCacheService appCacheService;
44         
45         /*
46          * (non-Javadoc)
47          * @see org.openecomp.portalapp.service.sessionmgt.RemoteWebServiceCallService#verifyRESTCredential(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
48          */
49         public boolean verifyRESTCredential(String secretKey, String requestUebKey, String requestAppName,
50                         String requestPassword) throws Exception {
51                 EPApp appRecord = findEpApp(requestUebKey);
52                 if (appRecord == null) {
53                         logger.warn(EELFLoggerDelegate.errorLogger, "Failed to find application with UEB key " + requestUebKey);
54                         return false;
55                 }
56                 
57                 String encryptedPwdDB = appRecord.getAppPassword();
58                 String appUserName = appRecord.getUsername();
59                 String decryptedPwd = CipherUtil.decrypt(encryptedPwdDB,
60                                 secretKey == null ? SystemProperties.getProperty(SystemProperties.Decryption_Key) : secretKey);
61                 if (decryptedPwd.equals(requestPassword) && appUserName.equals(requestAppName))
62                         return true;
63                 else
64                         return false;
65         }
66         
67         /**
68          * currently this method only validates the application key to fetch the application
69          */
70         public boolean verifyAppKeyCredential(String requestUebKey) throws Exception {
71                 String failMessage = "Failed to find application with UEB key " + requestUebKey;
72                 if(requestUebKey == null || requestUebKey.equals("")) {
73                         logger.warn(EELFLoggerDelegate.errorLogger, failMessage);
74                         return false;
75                 }
76                 
77                 EPApp appRecord = findEpApp(requestUebKey);
78                 if (appRecord == null) {
79                         logger.warn(EELFLoggerDelegate.errorLogger, failMessage);
80                         return false;
81                 }
82                 
83                 return true;
84         }
85
86         /**
87          * Searches the FN_APP table for the specified UEB key.
88          * 
89          * @return EPApp object if the key is found; else null.
90          */
91         public EPApp findEpApp(String uebKey) {
92                 List<?> list = null;
93                 StringBuffer criteria = new StringBuffer();
94                 criteria.append(" where ueb_key = '" + uebKey + "'");
95                 list = getDataAccessService().getList(EPApp.class, criteria.toString(), null, null);
96                 return (list == null || list.size() == 0) ? null : (EPApp) list.get(0);
97         }
98
99         public static void main(String args[]) throws Exception {
100                 String decryptedPwd = CipherUtil.decrypt("okYTaDrhzibcbGVq5mjkVQ==", "AGLDdG4D04BKm2IxIWEr8o==");
101                 System.out.print(decryptedPwd);
102         }
103         
104 }