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=========================================================
20 package org.onap.dmaap.dbcapi.authentication;
23 import java.io.FileInputStream;
24 import java.io.IOException;
25 import java.util.Properties;
27 import org.apache.log4j.Logger;
28 import org.onap.aaf.cadi.CadiException;
29 import org.onap.aaf.cadi.LocatorException;
30 import org.onap.aaf.cadi.PropAccess;
31 import org.onap.aaf.misc.env.APIException;
32 import org.onap.dmaap.dbcapi.aaf.AafLurService;
33 import org.onap.dmaap.dbcapi.aaf.DmaapPerm;
34 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
35 import org.onap.dmaap.dbcapi.server.Main;
36 import org.onap.dmaap.dbcapi.util.DmaapConfig;
41 public class AafLurAndFish implements ApiAuthorizationCheckInterface {
42 private AafLurService svc;
43 private static String api_namespace;
44 static final Logger logger = Logger.getLogger(AafLurAndFish.class);
46 AafLurAndFish() throws AuthenticationErrorException {
48 String[] args = new String[1];
49 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
50 api_namespace = p.getProperty( "ApiNamespace", "org.onap.dmaap-bc.api");
52 String cadiprop = p.getProperty( "cadi.properties", "/opt/app/osaaf/local/org.onap.dmaap-bc.props");
53 logger.info( "cadiprops in " + cadiprop );
54 Properties props = new Properties();
56 FileInputStream fis = new FileInputStream( cadiprop );
62 } catch ( IOException e ) {
63 logger.error( "Unable to load " + cadiprop );
64 throw new AuthenticationErrorException( );
67 PropAccess myAccess = new PropAccess( props );
69 svc = AafLurService.getInstance(myAccess);
70 } catch (APIException | CadiException | LocatorException e ) {
71 logger.error( e.toString() );
72 throw new AuthenticationErrorException();
77 public void check( String mechid, String pwd, DmaapPerm p ) throws AuthenticationErrorException {
80 boolean resp = svc.checkPerm( api_namespace, mechid, pwd, p );
81 if ( resp == false ) {
82 throw new AuthenticationErrorException();
84 } catch ( IOException | CadiException e ) {
85 logger.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");
95 alaf.check("demo@people.osaaf.org", "demo123456!", p);