nexus site path corrected
[portal.git] / ecomp-portal-BE / src / main / java / org / openecomp / portalapp / service / sessionmgt / 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.sessionmgt;
21
22 import java.util.List;
23
24 import org.openecomp.portalapp.portal.domain.EPApp;
25 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
26 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
27 import org.openecomp.portalsdk.core.service.WebServiceCallServiceImpl;
28 import org.openecomp.portalsdk.core.util.CipherUtil;
29 import org.openecomp.portalsdk.core.util.SystemProperties;
30 import org.springframework.context.annotation.EnableAspectJAutoProxy;
31 import org.springframework.stereotype.Service;
32 import org.springframework.transaction.annotation.Transactional;
33
34 @Service("remoteWebServiceCallService")
35 @Transactional
36 @org.springframework.context.annotation.Configuration
37 @EnableAspectJAutoProxy
38 @EPMetricsLog
39 public class RemoteWebServiceCallServiceImpl extends WebServiceCallServiceImpl implements RemoteWebServiceCallService {
40
41         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(RemoteWebServiceCallServiceImpl.class);
42         
43         /*
44          * (non-Javadoc)
45          * @see org.openecomp.portalapp.service.sessionmgt.RemoteWebServiceCallService#verifyRESTCredential(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
46          */
47         public boolean verifyRESTCredential(String secretKey, String requestUebKey, String requestAppName,
48                         String requestPassword) throws Exception {
49                 EPApp appRecord = findEpApp(requestUebKey);
50                 if (appRecord == null) {
51                         logger.warn(EELFLoggerDelegate.errorLogger, "Failed to find application with UEB key " + requestUebKey);
52                         return false;
53                 }
54                 
55                 String encryptedPwdDB = appRecord.getAppPassword();
56                 String appUserName = appRecord.getUsername();
57                 String decryptedPwd = CipherUtil.decrypt(encryptedPwdDB,
58                                 secretKey == null ? SystemProperties.getProperty(SystemProperties.Decryption_Key) : secretKey);
59                 if (decryptedPwd.equals(requestPassword) && appUserName.equals(requestAppName))
60                         return true;
61                 else
62                         return false;
63         }
64
65         /**
66          * Searches the FN_APP table for the specified UEB key.
67          * 
68          * @return EPApp object if the key is found; else null.
69          */
70         public EPApp findEpApp(String uebKey) {
71                 List<?> list = null;
72                 StringBuffer criteria = new StringBuffer();
73                 criteria.append(" where ueb_key = '" + uebKey + "'");
74                 list = getDataAccessService().getList(EPApp.class, criteria.toString(), null, null);
75                 return (list == null || list.size() == 0) ? null : (EPApp) list.get(0);
76         }
77
78         public static void main(String args[]) throws Exception {
79                 String decryptedPwd = CipherUtil.decrypt("okYTaDrhzibcbGVq5mjkVQ==", "AGLDdG4D04BKm2IxIWEr8o==");
80                 System.out.print(decryptedPwd);
81         }
82         
83 }