2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 IBM.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.dmaap.dbcapi.authentication;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.util.Properties;
26 import org.onap.aaf.cadi.CadiException;
27 import org.onap.aaf.cadi.LocatorException;
28 import org.onap.aaf.cadi.PropAccess;
29 import org.onap.aaf.misc.env.APIException;
30 import org.onap.dmaap.dbcapi.aaf.AafLurService;
31 import org.onap.dmaap.dbcapi.aaf.DmaapPerm;
32 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
33 import org.onap.dmaap.dbcapi.util.DmaapConfig;
36 public class AafLurAndFish extends BaseLoggingClass implements ApiAuthorizationCheckInterface {
37 private AafLurService svc;
38 private static String apiNamespace;
39 private static final String ERROR="Error";
41 AafLurAndFish() throws AuthenticationErrorException {
43 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
44 apiNamespace = p.getProperty( "ApiNamespace", "org.onap.dmaap-bc.api");
46 String cadiprop = p.getProperty( "cadi.properties", "/opt/app/osaaf/local/org.onap.dmaap-bc.props");
47 logger.info( "cadiprops in " + cadiprop );
48 Properties props = new Properties();
50 FileInputStream fis = new FileInputStream( cadiprop );
56 } catch ( IOException e ) {
57 errorLogger.error( "Unable to load " + cadiprop );
58 errorLogger.error(ERROR, e);
59 throw new AuthenticationErrorException( );
62 PropAccess myAccess = new PropAccess( props );
64 svc = AafLurService.getInstance(myAccess);
65 } catch (APIException | CadiException | LocatorException e ) {
66 errorLogger.error(ERROR, e);
67 errorLogger.error( e.toString() );
68 throw new AuthenticationErrorException();
73 public void check( String mechid, String pwd, DmaapPerm p ) throws AuthenticationErrorException {
76 if (mechid.isEmpty() || pwd.isEmpty()) {
77 throw new AuthenticationErrorException("No basic authorization value provided");
80 if (!svc.checkPerm( apiNamespace, mechid, pwd, p )) {
81 throw new AuthenticationErrorException();
83 } catch ( IOException | CadiException e ) {
84 errorLogger.error(ERROR, e);
85 errorLogger.error( e.toString() );
86 throw new AuthenticationErrorException();
91 public static void main(String[] args) throws Exception {
92 AafLurAndFish alaf = new AafLurAndFish();
93 DmaapPerm p = new DmaapPerm( "org.onap.dmaap-bc.api.dmaap", "boot", "GET");
96 alaf.check("mmanager@people.osaaf.org", "demo123456!", p);
97 } catch (AuthenticationErrorException aee ) {
98 errorLogger.error(aee.getMessage());
99 errorLogger.error( "Check failed for: " + p.toJSON());
102 errorLogger.info("Check succeeded for: " + p.toJSON());