X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-cass%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fdao%2Fcached%2FFileGetter.java;h=31e5069b206708beaf8e2c4eaf619d4ce6383224;hb=a8d97381d7762c5e5e99f72468cd39596fcca8bc;hp=b7a6c59d4f0c38ec4bb41162f78228f83d3f175c;hpb=4f28c4f6601324557cdc6ce4b65a544f09aab229;p=aaf%2Fauthz.git diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/FileGetter.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/FileGetter.java index b7a6c59d..31e5069b 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/FileGetter.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/FileGetter.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -42,108 +42,109 @@ import org.onap.aaf.cadi.PropAccess; import org.onap.aaf.cadi.util.CSV; public class FileGetter { - private static final String AAF_FILEGETTER = "aaf_filegetter"; - public static boolean isLoaded = false; - private static FileGetter singleton; + private static final String AAF_FILEGETTER = "aaf_filegetter"; + private static boolean isLoaded = false; + private static FileGetter singleton; + private static List EMPTY = new ArrayList<>(); + private Map> data; + private SimpleDateFormat sdf; + private FileGetter(Access access) { + if(access!=null) { + String filename = access.getProperty(AAF_FILEGETTER,null); + if((filename!=null)&&(!isLoaded)) { + data = new TreeMap<>(); + sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss+SSSS"); + CSV csv = new CSV(access, filename).setDelimiter('|'); + try { + access.log(Level.INIT, "Loading Filebased Cred from",filename); + csv.visit(row -> { + if(row.size()<1) { + access.log(Level.INIT, "Bad Row"); + } + int type; + try { + type =Integer.parseInt(row.get(1)); + } catch(Exception e) { + access.log(Level.INIT, e, "skipping ", row.get(0)); + return; + } + if(CredDAO.CERT_SHA256_RSA == type) { + return; + } + CredDAO.Data cdd = new CredDAO.Data(); + cdd.id=row.get(0); + cdd.type = type; + try { + cdd.expires = sdf.parse(row.get(2)); + cdd.cred = ByteBuffer.wrap(Hash.fromHex(row.get(3))); + cdd.notes= row.get(4); + cdd.ns = row.get(5); + cdd.other = Integer.parseInt(row.get(6)); + if(row.size()>8) { + cdd.tag = row.get(8); + } else { + cdd.tag = ""; + } + List lcdd = data.get(cdd.id); + if(lcdd == null) { + lcdd = new ArrayList<>(); + data.put(cdd.id, lcdd); + } + lcdd.add(cdd); + } catch (ParseException e) { + access.log(Level.INIT, e); + } + + }); + access.printf(Level.INIT, "Filebased Cred finished..."); + isLoaded = true; + } catch( CadiException | IOException e) { + access.log(Level.ERROR, e); + } + } + } + } + + public static synchronized FileGetter singleton(Access access) { + if(singleton==null) { + singleton = new FileGetter(access); + } + return singleton; + } + + public Getter getter(String id) { + return new FGetter(id); + } + + public class FGetter implements Getter { + private final List lcdd; + public FGetter(final String id) { + lcdd = data.get(id); + } + @Override + public Result> get() { + return Result.ok(lcdd==null?EMPTY:lcdd); + } + } + + public static void main(String[] args) { + PropAccess access = new PropAccess(args); + access.setProperty(AAF_FILEGETTER,"/opt/app/aaf/data/cred.dat"); + FileGetter fg = FileGetter.singleton(access); - private Map> data; - private SimpleDateFormat sdf; - private FileGetter(Access access) { - if(access!=null) { - String filename = access.getProperty(AAF_FILEGETTER,null); - if(filename!=null) { - if(!isLoaded) { - data = new TreeMap<>(); - sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss+SSSS"); - CSV csv = new CSV(access, filename).setDelimiter('|'); - try { - access.log(Level.INIT, "Loading Filebased Cred from",filename); - csv.visit(row -> { - if(row.size()<1) { - access.log(Level.INIT, "Bad Row"); - } - int type; - try { - type =Integer.parseInt(row.get(1)); - } catch(Exception e) { - access.log(Level.INIT, e, "skipping ", row.get(0)); - return; - } - if(CredDAO.CERT_SHA256_RSA == type) { - return; - } - CredDAO.Data cdd = new CredDAO.Data(); - cdd.id=row.get(0); - cdd.type = type; - try { - cdd.expires = sdf.parse(row.get(2)); - cdd.cred = ByteBuffer.wrap(Hash.fromHex(row.get(3))); - cdd.notes= row.get(4); - cdd.ns = row.get(5); - cdd.other = Integer.parseInt(row.get(6)); - if(row.size()>8) { - cdd.tag = row.get(8); - } else { - cdd.tag = ""; - } - List lcdd = data.get(cdd.id); - if(lcdd == null) { - lcdd = new ArrayList<>(); - data.put(cdd.id, lcdd); - } - lcdd.add(cdd); - - } catch (ParseException e) { - access.log(Level.INIT, e); - } - - }); - access.printf(Level.INIT, "Filebased Cred finished..."); - isLoaded = true; - } catch( CadiException | IOException e) { - access.log(Level.ERROR, e); - } - } - } - } - } + for(String id : new String[] {"m01891@aaf.att.com","bogus"}) { + Getter g = fg.getter(id); + Result> r = g.get(); + if(r.isOKhasData()) { + for(CredDAO.Data cdd : r.value) { + System.out.println(cdd); + } + } + } + } - public static synchronized FileGetter singleton(Access access) { - if(singleton==null) { - singleton = new FileGetter(access); - } - return singleton; - - } - public Getter getter(String id) { - return new FGetter(id); - } - private static List EMPTY = new ArrayList<>(); - public class FGetter implements Getter { - private final List lcdd; - public FGetter(final String id) { - lcdd = data.get(id); - } - @Override - public Result> get() { - return Result.ok(lcdd==null?EMPTY:lcdd); - } - } - - public static void main(String[] args) { - PropAccess access = new PropAccess(args); - access.setProperty(AAF_FILEGETTER,"/Users/jg1555/cred.dat"); - FileGetter fg = FileGetter.singleton(access); - - for(String id : new String[] {"m01891@aaf.att.com","bogus"}) { - Getter g = fg.getter(id); - Result> r = g.get(); - if(r.isOKhasData()) { - for(CredDAO.Data cdd : r.value) { - System.out.println(cdd); - } - } - } - } + public static boolean isLoaded() { + return isLoaded; + } }