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.util.DmaapConfig;
39 public class AafLurAndFish implements ApiAuthorizationCheckInterface {
40 private AafLurService svc;
41 private static String api_namespace;
42 static final Logger logger = Logger.getLogger(AafLurAndFish.class);
44 AafLurAndFish() throws AuthenticationErrorException {
46 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
47 api_namespace = p.getProperty( "ApiNamespace", "org.onap.dmaap-bc.api");
49 String cadiprop = p.getProperty( "cadi.properties", "/opt/app/osaaf/local/org.onap.dmaap-bc.props");
50 logger.info( "cadiprops in " + cadiprop );
51 Properties props = new Properties();
53 FileInputStream fis = new FileInputStream( cadiprop );
59 } catch ( IOException e ) {
60 logger.error( "Unable to load " + cadiprop );
61 logger.error("Error", e);
62 throw new AuthenticationErrorException( );
65 PropAccess myAccess = new PropAccess( props );
67 svc = AafLurService.getInstance(myAccess);
68 } catch (APIException | CadiException | LocatorException e ) {
69 logger.error("Error", e);
70 logger.error( e.toString() );
71 throw new AuthenticationErrorException();
76 public void check( String mechid, String pwd, DmaapPerm p ) throws AuthenticationErrorException {
79 boolean resp = svc.checkPerm( api_namespace, mechid, pwd, p );
82 throw new AuthenticationErrorException();
84 } catch ( IOException | CadiException e ) {
85 logger.error("Error", e);
86 logger.error( e.toString() );
87 throw new AuthenticationErrorException();
92 public static void main(String[] args) throws Exception {
93 AafLurAndFish alaf = new AafLurAndFish();
94 DmaapPerm p = new DmaapPerm( "org.onap.dmaap-bc.api.dmaap", "boot", "GET");
97 alaf.check("mmanager@people.osaaf.org", "demo123456!", p);
98 } catch (AuthenticationErrorException aee ) {
99 logger.error( "Check failed for: " + p.toJSON());
102 logger.info( "Check succeeded for: " + p.toJSON() );