Merge "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 import org.onap.portalapp.portal.domain.EPApp;
42 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
43 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
44 import org.onap.portalsdk.core.onboarding.util.KeyConstants;
45 import org.onap.portalsdk.core.onboarding.util.KeyProperties;
46 import org.onap.portalsdk.core.service.WebServiceCallServiceImpl;
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.getAppBasicAuthPassword();
72                 String appUserName = appRecord.getAppBasicAuthUsername();
73                 String decryptedPwd = CipherUtil.decryptPKC(encryptedPwdDB,secretKey == null ? KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY) : secretKey);
74                 if (decryptedPwd.equals(requestPassword) && appUserName.equals(requestAppName))
75                         return true;
76                 else
77                         return false;
78         }
79         
80         /**
81          * currently this method only validates the application key to fetch the application
82          */
83         public boolean verifyAppKeyCredential(String requestUebKey) throws Exception {
84                 String failMessage = "Failed to find application with UEB key " + requestUebKey;
85                 if(requestUebKey == null || requestUebKey.equals("")) {
86                         logger.warn(EELFLoggerDelegate.errorLogger, failMessage);
87                         return false;
88                 }
89                 
90                 EPApp appRecord = findEpApp(requestUebKey);
91                 if (appRecord == null) {
92                         logger.warn(EELFLoggerDelegate.errorLogger, failMessage);
93                         return false;
94                 }
95                 
96                 return true;
97         }
98
99         /**
100          * Searches the FN_APP table for the specified UEB key.
101          * 
102          * @return EPApp object if the key is found; else null.
103          */
104         public EPApp findEpApp(String uebKey) {
105                 List<?> list = null;
106                 StringBuffer criteria = new StringBuffer();
107                 criteria.append(" where ueb_key = '" + uebKey + "'");
108                 list = getDataAccessService().getList(EPApp.class, criteria.toString(), null, null);
109                 return (list == null || list.size() == 0) ? null : (EPApp) list.get(0);
110         }
111
112 }