X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aaf%2Fauthz.git;a=blobdiff_plain;f=auth%2Fauth-batch%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fbatch%2Fhelpers%2FCred.java;h=e2f37651ee22fe41e730ec926937371c1ec31446;hp=640efae704855e87f52ba61479a208e509404bcb;hb=9a152c4fed4678049b63f53cd94a558b2d6e2cd7;hpb=2eccd7c892fd7166d70c84a710e8e6b58138893c diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java index 640efae7..e2f37651 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/Cred.java @@ -3,13 +3,14 @@ * org.onap.aaf * =========================================================================== * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 IBM. * =========================================================================== * 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. @@ -21,14 +22,15 @@ package org.onap.aaf.auth.batch.helpers; -import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; +import java.util.SortedMap; import java.util.TreeMap; import org.onap.aaf.auth.dao.cass.CredDAO; @@ -46,27 +48,28 @@ import com.datastax.driver.core.SimpleStatement; import com.datastax.driver.core.Statement; public class Cred { - public static final TreeMap data = new TreeMap<>(); - public static final TreeMap> byNS = new TreeMap<>(); + public static final SortedMap data = new TreeMap<>(); + public static final SortedMap> byNS = new TreeMap<>(); public final String id; public final List instances; public final String ns; - + public Cred(String id) { this.id = id; instances = new ArrayList<>(); ns=Question.domain2ns(id); } - + public static class Instance { public final int type; - public final Date expires,written; + public final Date expires; + public final Date written; public final Integer other; public final String tag; public List notes; - + public Instance(int type, Date expires, Integer other, long written, String tag) { this.type = type; this.expires = expires; @@ -74,7 +77,7 @@ public class Cred { this.written = new Date(written); this.tag = tag; } - + /** * Usually returns Null... * @return @@ -82,23 +85,23 @@ public class Cred { public List notes() { return notes; } - + public void addNote(int level, String note) { if(notes==null) { notes=new ArrayList<>(); - } + } notes.add(new Note(level,note)); } - + public String toString() { return expires.toString() + ": " + type + ' ' + tag; } } - + public static class Note { public final int level; public final String note; - + public Note(int level, String note) { this.level = level; this.note = note; @@ -126,7 +129,7 @@ public class Cred { return last; } - + public Set types() { Set types = new HashSet<>(); for (Instance i : instances) { @@ -147,7 +150,7 @@ public class Cred { trans.info().log( "query: " + query ); TimeTaken tt = trans.start("Read Creds", Env.REMOTE); - + ResultSet results; try { Statement stmt = new SimpleStatement( query ); @@ -189,7 +192,7 @@ public class Cred { } public static void add( - final String id, + final String id, final int type, final Date timestamp, final int other, @@ -202,10 +205,11 @@ public class Cred { data.put(id, cred); } cred.instances.add(new Instance(type, timestamp, other, written/1000,tag)); - + List lscd = byNS.get(cred.ns); if (lscd==null) { - byNS.put(cred.ns, (lscd=new ArrayList<>())); + lscd=new ArrayList<>(); + byNS.put(cred.ns,lscd); } boolean found = false; for (Cred c : lscd) { @@ -220,10 +224,10 @@ public class Cred { } - /** + /** * Count entries in Cred data. * Note, as opposed to other methods, need to load the whole cred table for the Types. - * @param numbuckets + * @param numbuckets * @return */ public static CredCount count(int numbuckets) { @@ -237,41 +241,41 @@ public class Cred { } public static class CredCount { - public int raw[]; - public int basic_auth[]; - public int basic_auth_256[]; - public int cert[]; - public int x509Added[]; - public int x509Expired[]; - public Date dates[]; - + public int [] raw; + public int [] basicAuth; + public int [] basicAuth256; + public int [] cert; + public int [] x509Added; + public int [] x509Expired; + public Date [] dates; + public CredCount(int numbuckets) { raw = new int[numbuckets]; - basic_auth = new int[numbuckets]; - basic_auth_256 = new int[numbuckets]; + basicAuth = new int[numbuckets]; + basicAuth256 = new int[numbuckets]; cert = new int[numbuckets]; x509Added = new int[numbuckets]; x509Expired = new int[numbuckets]; dates = new Date[numbuckets]; GregorianCalendar gc = new GregorianCalendar(); dates[0]=gc.getTime(); // now - gc.set(GregorianCalendar.DAY_OF_MONTH, 1); - gc.set(GregorianCalendar.HOUR, 0); - gc.set(GregorianCalendar.MINUTE, 0); - gc.set(GregorianCalendar.SECOND,0); - gc.set(GregorianCalendar.MILLISECOND,0); - gc.add(GregorianCalendar.MILLISECOND, -1); // last milli of month - for (int i=1;i row) { - Long l = Long.parseLong(row.get(5)); - String date = sdf.format(new Date(l)); + long l = Long.parseLong(row.get(5)); + String date = Chrono.batchFmt.format(new Date(l)); sb.append("DELETE from authz.cred WHERE id='"); sb.append(row.get(1)); sb.append("' AND type="); @@ -326,10 +331,7 @@ public class Cred { sb.append(" AND expires='"); sb.append(date); sb.append("';\n"); -// sb.append(" AND expires=dateof(maxtimeuuid("); -// sb.append(row.get(5)); -// sb.append("));\n"); - + } public String toString() { @@ -383,4 +385,7 @@ public class Cred { data.clear(); byNS.clear(); } + + + } \ No newline at end of file