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;
24 import org.apache.log4j.Logger;
25 import org.onap.aaf.cadi.CadiException;
26 import org.onap.aaf.cadi.LocatorException;
27 import org.onap.aaf.cadi.PropAccess;
28 import org.onap.aaf.misc.env.APIException;
29 import org.onap.dmaap.dbcapi.aaf.AafLurService;
30 import org.onap.dmaap.dbcapi.aaf.DmaapPerm;
31 import org.onap.dmaap.dbcapi.util.DmaapConfig;
33 import java.io.FileInputStream;
34 import java.io.IOException;
35 import java.util.Properties;
40 public class AafLurAndFish implements ApiAuthorizationCheckInterface {
41 private AafLurService svc;
42 private static String apiNamespace;
43 private static final String ERROR="Error";
44 static final Logger logger = Logger.getLogger(AafLurAndFish.class);
46 AafLurAndFish() throws AuthenticationErrorException {
48 DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
49 apiNamespace = p.getProperty( "ApiNamespace", "org.onap.dmaap-bc.api");
51 String cadiprop = p.getProperty( "cadi.properties", "/opt/app/osaaf/local/org.onap.dmaap-bc.props");
52 logger.info( "cadiprops in " + cadiprop );
53 Properties props = new Properties();
55 FileInputStream fis = new FileInputStream( cadiprop );
61 } catch ( IOException e ) {
62 logger.error( "Unable to load " + cadiprop );
63 logger.error(ERROR, e);
64 throw new AuthenticationErrorException( );
67 PropAccess myAccess = new PropAccess( props );
69 svc = AafLurService.getInstance(myAccess);
70 } catch (APIException | CadiException | LocatorException e ) {
71 logger.error(ERROR, e);
72 logger.error( e.toString() );
73 throw new AuthenticationErrorException();
78 public void check( String mechid, String pwd, DmaapPerm p ) throws AuthenticationErrorException {
81 if (mechid.isEmpty() || pwd.isEmpty()) {
82 throw new AuthenticationErrorException("No basic authorization value provided");
85 if (!svc.checkPerm( apiNamespace, mechid, pwd, p )) {
86 throw new AuthenticationErrorException();
88 } catch ( IOException | CadiException e ) {
89 logger.error(ERROR, e);
90 logger.error( e.toString() );
91 throw new AuthenticationErrorException();
96 public static void main(String[] args) throws Exception {
97 AafLurAndFish alaf = new AafLurAndFish();
98 DmaapPerm p = new DmaapPerm( "org.onap.dmaap-bc.api.dmaap", "boot", "GET");
101 alaf.check("mmanager@people.osaaf.org", "demo123456!", p);
102 } catch (AuthenticationErrorException aee ) {
104 logger.error( "Check failed for: " + p.toJSON());
107 logger.info("Check succeeded for: " + p.toJSON());