2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
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 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.locate.service;
24 import java.util.List;
26 import org.onap.aaf.auth.dao.cass.ConfigDAO;
27 import org.onap.aaf.auth.dao.cass.ConfigDAO.Data;
28 import org.onap.aaf.auth.dao.cass.LocateDAO;
29 import org.onap.aaf.auth.env.AuthzTrans;
30 import org.onap.aaf.auth.layer.Result;
31 import org.onap.aaf.auth.locate.AAF_Locate;
32 import org.onap.aaf.auth.locate.mapper.Mapper;
33 import org.onap.aaf.auth.locate.validation.LocateValidator;
34 import org.onap.aaf.cadi.aaf.AAFPermission;
35 import org.onap.aaf.misc.env.APIException;
37 import locate.v1_0.Endpoints;
38 import locate.v1_0.MgmtEndpoint;
39 import locate.v1_0.MgmtEndpoints;
40 import locate.v1_1.Configuration;
41 import locate.v1_1.Configuration.Props;
43 public class LocateServiceImpl<IN,OUT,ERROR>
44 implements LocateService<IN,OUT,Endpoints,MgmtEndpoints,Configuration,ERROR> {
45 private Mapper<IN,OUT,Endpoints,MgmtEndpoints,Configuration,ERROR> mapper;
46 protected LocateDAO locateDAO;
47 private ConfigDAO configDAO;
48 private boolean permToRegister;
50 public LocateServiceImpl(AuthzTrans trans, AAF_Locate locate, Mapper<IN,OUT,Endpoints,MgmtEndpoints,Configuration,ERROR> mapper) throws APIException {
52 this.locateDAO = locate.locateDAO;
53 this.configDAO = locate.configDAO;
54 permToRegister = false; //TODO Setup a Configuration for this
57 public Mapper<IN,OUT,Endpoints,MgmtEndpoints,Configuration,ERROR> mapper() {return mapper;}
60 public Result<Endpoints> getEndPoints(AuthzTrans trans, String service, String version, String other) {
61 return mapper.endpoints(locateDAO.readByName(trans, service), version, other);
65 * @see org.onap.aaf.auth.locate.service.GwService#putMgmtEndPoints(org.onap.aaf.auth.env.test.AuthzTrans, java.lang.Object)
68 public Result<Void> putMgmtEndPoints(AuthzTrans trans, MgmtEndpoints meps) {
69 LocateValidator v = new LocateValidator().mgmt_endpoints(meps, false);
71 return Result.err(Result.ERR_BadData,v.errs());
74 StringBuilder denied = null;
75 for (MgmtEndpoint me : meps.getMgmtEndpoint()) {
77 int dot = me.getName().lastIndexOf('.'); // Note: Validator checks for NS for getName()
78 AAFPermission p = new AAFPermission(me.getName().substring(0,dot),"locator",me.getHostname(),"write");
81 denied = new StringBuilder("May not register service(s):");
84 denied.append("\n\t");
85 denied.append(p.getKey());
90 LocateDAO.Data data = mapper.locateData(me);
91 locateDAO.update(trans, data, true);
97 return denied==null?Result.err(Result.ERR_NotFound, "No endpoints found")
98 :Result.err(Result.ERR_Security,denied.toString());
103 * @see org.onap.aaf.auth.locate.service.GwService#removeMgmtEndPoints(org.onap.aaf.auth.env.test.AuthzTrans, java.lang.Object)
106 public Result<Void> removeMgmtEndPoints(AuthzTrans trans, MgmtEndpoints meps) {
107 LocateValidator v = new LocateValidator().mgmt_endpoint_key(meps);
109 return Result.err(Result.ERR_BadData,v.errs());
112 StringBuilder denied = null;
113 for (MgmtEndpoint me : meps.getMgmtEndpoint()) {
114 if (permToRegister) {
115 int dot = me.getName().lastIndexOf('.'); // Note: Validator checks for NS for getName()
116 AAFPermission p = new AAFPermission(me.getName().substring(0,dot),"locator",me.getHostname(),"write");
117 if (!trans.fish(p)) {
119 denied = new StringBuilder("May not deregister service(s):");
122 denied.append("\n\t");
123 denied.append(p.getKey());
128 LocateDAO.Data data = mapper.locateData(me);
129 locateDAO.delete(trans, data, true);
135 return denied==null?Result.err(Result.ERR_NotFound, "No endpoints found")
136 :Result.err(Result.ERR_Security,denied.toString());
142 * @see org.onap.aaf.auth.locate.service.LocateService#getConfig(org.onap.aaf.auth.env.AuthzTrans, java.lang.String, java.lang.String)
144 * Note: "id" is put in, in case we need to filter, or direct data change in the future by Permission
147 public Result<Configuration> getConfig(AuthzTrans trans, String id, String type) {
148 Result<List<Data>> dr = configDAO.readName(trans, type);
149 Configuration c = new Configuration();
153 if (dr.isOKhasData()) {
154 for (ConfigDAO.Data data : dr.value) {
157 p.setValue(data.value);
165 //////////////// APIs ///////////////////