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