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.direct;
24 import java.net.Inet4Address;
25 import java.net.UnknownHostException;
27 import org.onap.aaf.auth.dao.cass.LocateDAO;
28 import org.onap.aaf.auth.dao.cass.LocateDAO.Data;
29 import org.onap.aaf.auth.env.AuthzEnv;
30 import org.onap.aaf.cadi.Access;
31 import org.onap.aaf.cadi.CadiException;
32 import org.onap.aaf.cadi.client.Result;
33 import org.onap.aaf.cadi.config.Config;
34 import org.onap.aaf.cadi.register.Registrant;
35 import org.onap.aaf.cadi.util.Split;
37 public class DirectRegistrar implements Registrant<AuthzEnv> {
39 private LocateDAO ldao;
40 public DirectRegistrar(Access access, LocateDAO ldao, String name, String version, int port) throws CadiException {
42 locate = new LocateDAO.Data();
47 String latitude = access.getProperty(Config.CADI_LATITUDE, null);
49 latitude = access.getProperty("AFT_LATITUDE", null);
51 String longitude = access.getProperty(Config.CADI_LONGITUDE, null);
53 longitude = access.getProperty("AFT_LONGITUDE", null);
55 if(latitude==null || longitude==null) {
56 throw new CadiException(Config.CADI_LATITUDE + " and " + Config.CADI_LONGITUDE + " is required");
58 locate.latitude = Float.parseFloat(latitude);
59 locate.longitude = Float.parseFloat(longitude);
61 String split[] = Split.splitTrim('.', version);
62 locate.pkg = split.length>3?Integer.parseInt(split[3]):0;
63 locate.patch = split.length>2?Integer.parseInt(split[2]):0;
64 locate.minor = split.length>1?Integer.parseInt(split[1]):0;
65 locate.major = split.length>0?Integer.parseInt(split[0]):0;
66 locate.hostname = access.getProperty(Config.CADI_REGISTRATION_HOSTNAME, null);
67 if(locate.hostname==null) {
68 locate.hostname = access.getProperty(Config.HOSTNAME, null);
70 if(locate.hostname==null) {
71 locate.hostname = Inet4Address.getLocalHost().getHostName();
73 String subprotocols = access.getProperty(Config.CADI_PROTOCOLS, null);
74 if(subprotocols==null) {
75 locate.protocol="http";
77 locate.protocol="https";
78 for(String s : Split.split(',', subprotocols)) {
79 locate.subprotocol(true).add(s);
82 } catch (NumberFormatException | UnknownHostException e) {
83 throw new CadiException("Error extracting Data from Properties for Registrar",e);
88 public Result<Void> update(AuthzEnv env) {
89 org.onap.aaf.auth.layer.Result<Void> dr = ldao.update(env.newTransNoAvg(), locate);
91 return Result.ok(200, null);
93 return Result.err(503, dr.errorString());
98 * @see org.onap.aaf.auth.server.Registrant#cancel(org.onap.aaf.auth.env.test.AuthzEnv)
101 public Result<Void> cancel(AuthzEnv env) {
102 org.onap.aaf.auth.layer.Result<Void> dr = ldao.delete(env.newTransNoAvg(), locate, false);
104 return Result.ok(200, null);
106 return Result.err(503, dr.errorString());