2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
20 package org.openecomp.portalapp.portal.service;
22 import java.util.ArrayList;
23 import java.util.List;
25 import org.hibernate.criterion.Criterion;
26 import org.hibernate.criterion.Restrictions;
27 import org.openecomp.portalapp.portal.domain.BasicAuthCredentials;
28 import org.openecomp.portalapp.portal.domain.EPEndpoint;
29 import org.openecomp.portalapp.portal.domain.EPEndpointAccount;
30 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
31 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
32 import org.openecomp.portalsdk.core.service.DataAccessService;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.context.annotation.EnableAspectJAutoProxy;
35 import org.springframework.stereotype.Service;
37 @Service("basicAuthenticationCredentialService")
38 @EnableAspectJAutoProxy
40 public class BasicAuthenticationCredentialServiceImpl implements BasicAuthenticationCredentialService {
42 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(BasicAuthenticationCredentialServiceImpl.class);
45 private DataAccessService dataAccessService;
48 public BasicAuthCredentials getBasicAuthCredentialByUsernameAndPassword(String username, String password) {
50 List<Criterion> restrictionsList = new ArrayList<Criterion>();
51 Criterion contextUserNameCrit = Restrictions.eq("username", username);
52 restrictionsList.add(contextUserNameCrit);
53 Criterion contextPasswordCrit = Restrictions.eq("password", password);
54 restrictionsList.add(contextPasswordCrit);
56 @SuppressWarnings("unchecked")
57 List<BasicAuthCredentials> credList = (List<BasicAuthCredentials>) dataAccessService
58 .getList(BasicAuthCredentials.class, null, restrictionsList, null);
59 if (credList == null || credList.size() == 0) {
60 logger.error(EELFLoggerDelegate.errorLogger,
61 "getBasicAuthCredentialByAppName: no credential(s) for " + username);
64 logger.debug(EELFLoggerDelegate.debugLogger,
65 "getBasicAuthCredentialByAppName: cred list size: " + credList.size());
66 BasicAuthCredentials cred = (BasicAuthCredentials) credList.get(0);
67 cred.setEndpoints(getEndpointsByAccountId(cred.getId()));
71 private List<EPEndpoint> getEndpointsByAccountId(long id) {
72 List<EPEndpoint> list = new ArrayList<>();
73 List<Criterion> restrictionsList = new ArrayList<Criterion>();
74 Criterion contextIdCrit = Restrictions.eq("account_id", id);
75 restrictionsList.add(contextIdCrit);
76 @SuppressWarnings("unchecked")
77 List<EPEndpointAccount> epList = (List<EPEndpointAccount>) dataAccessService.getList(EPEndpointAccount.class,
78 null, restrictionsList, null);
79 for (EPEndpointAccount ep : epList) {
80 list.add((EPEndpoint) dataAccessService.getDomainObject(EPEndpoint.class, ep.getEp_id(), null));