diff options
Diffstat (limited to 'auth/auth-cass/src/main')
51 files changed, 820 insertions, 822 deletions
diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/AbsCassDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/AbsCassDAO.java index d0e4eaab..de0efdfd 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/AbsCassDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/AbsCassDAO.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. @@ -54,14 +54,14 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { protected static final int ASSIGNMENT_COMMAS = 2; protected static final int WHERE_ANDS = 3; - private Cluster cluster; + private Cluster cluster; /* * From DataStax * com.datastax.driver.core.Session - A session holds connections to a Cassandra cluster, allowing it to be queried. Each session maintains multiple connections to the cluster nodes, - provides policies to choose which node to use for each query (round-robin on all nodes of the cluster by default), and handles retries for + A session holds connections to a Cassandra cluster, allowing it to be queried. Each session maintains multiple connections to the cluster nodes, + provides policies to choose which node to use for each query (round-robin on all nodes of the cluster by default), and handles retries for failed query (when it makes sense), etc... - Session instances are thread-safe and usually a single instance is enough per application. However, a given session can only be set to one + Session instances are thread-safe and usually a single instance is enough per application. However, a given session can only be set to one keyspace at a time, so one instance per keyspace is necessary. */ private Session session; @@ -76,7 +76,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { private static final Deque<ResetRequest> resetDeque = new ConcurrentLinkedDeque<ResetRequest>(); private static boolean resetTrigger = false; private static long nextAvailableReset = 0; - + public AbsCassDAO(TRANS trans, String name, Cluster cluster, String keyspace, Class<DATA> dataClass) { this.name = name; this.cluster = cluster; @@ -95,7 +95,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { owningDAO = aDao; this.dataClass = dataClass; } - + // Not used since 2015 // public static void setSessionSlot(Slot slot) { // sessionSlot = slot; @@ -117,7 +117,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { /** * Create a PSInfo and create Prepared Statement - * + * * @param trans * @param theCQL * @param loader @@ -137,7 +137,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { } else { crud = CRUD.read; } - + int idx = 0, count=0; while ((idx=cql.indexOf('?',idx))>=0) { ++idx; @@ -145,14 +145,14 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { } size=count; } - + public synchronized void reset() { ps = null; } - + private synchronized BoundStatement ps(TransStore trans) throws APIException, IOException { /* From Datastax - You should prepare only once, and cache the PreparedStatement in your application (it is thread-safe). + You should prepare only once, and cache the PreparedStatement in your application (it is thread-safe). If you call prepare multiple times with the same query string, the driver will log a warning. */ if (ps==null) { @@ -173,7 +173,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { /** * Execute a Prepared Statement by extracting from DATA object - * + * * @param trans * @param text * @param data @@ -194,7 +194,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { /** * Execute a Prepared Statement on Object[] key - * + * * @param trans * @param text * @param objs @@ -211,15 +211,15 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { tt.done(); } } - - /* + + /* * Note: - * + * */ /** * Execute a Prepared Statement by extracting from DATA object - * + * * @param trans * @param text * @param data @@ -231,15 +231,15 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { /* * "execute" (and executeAsync) * Executes the provided query. - This method blocks until at least some result has been received from the database. However, - for SELECT queries, it does not guarantee that the result has been received in full. But it - does guarantee that some response has been received from the database, and in particular + This method blocks until at least some result has been received from the database. However, + for SELECT queries, it does not guarantee that the result has been received in full. But it + does guarantee that some response has been received from the database, and in particular guarantee that if the request is invalid, an exception will be thrown by this method. Parameters: statement - the CQL query to execute (that can be any Statement). Returns: - the result of the query. That result will never be null but can be empty (and will + the result of the query. That result will never be null but can be empty (and will be for any non SELECT query). */ return Result.ok(getSession(trans).execute( @@ -254,7 +254,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { /** * Execute a Prepared Statement on Object[] key - * + * * @param trans * @param text * @param objs @@ -281,12 +281,12 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { */ public Result<List<DATA>> read(TRANS trans, String text, Object[] key) { TimeTaken tt = trans.start(text,Env.REMOTE); - + ResultSet rs; try { rs = getSession(trans).execute(key==null?ps(trans):ps(trans).bind(key)); -/// TEST CODE for Exception -// boolean force = true; +/// TEST CODE for Exception +// boolean force = true; // if (force) { // Map<InetSocketAddress, Throwable> misa = new HashMap<>(); // //misa.put(new InetSocketAddress(444),new Exception("no host was tried")); @@ -301,20 +301,20 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { } finally { tt.done(); } - + return extract(loader,rs,null /*let Array be created if necessary*/,dflt); } - + public Result<List<DATA>> read(TRANS trans, String text, DATA data) { return read(trans,text, loader.extract(data, size, crud)); } - + public Object[] keyFrom(DATA data) { return loader.extract(data, size, CRUD.delete); // Delete is key only } /* - * Note: in case PSInfos are deleted, we want to remove them from list. This is not expected, + * Note: in case PSInfos are deleted, we want to remove them from list. This is not expected, * but we don't want a data leak if it does. Finalize doesn't have to happen quickly */ @Override @@ -339,7 +339,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { } else { DATA d; List<DATA> data = indata==null?new ArrayList<>(rows.size()):indata; - + for (Row row : rows) { try { d = loader.load(dataClass.newInstance(),row); @@ -353,7 +353,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { return Result.ok(data); } } - + private static final String NEW_CASSANDRA_SESSION_CREATED = "New Cassandra Session Created"; private static final String NEW_CASSANDRA_CLUSTER_OBJECT_CREATED = "New Cassandra Cluster Object Created"; private static final String NEW_CASSANDRA_SESSION = "New Cassandra Session"; @@ -363,14 +363,14 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { //package on purpose Session session; long timestamp; - + public ResetRequest(Session session) { this.session = session; timestamp = System.currentTimeMillis(); } } - + public static final void primePSIs(TransStore trans) throws APIException, IOException { for (AbsCassDAO<? extends TransStore, ?>.PSInfo psi : psinfos) { if (psi.ps==null) { @@ -378,7 +378,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { } } } - + public final Session getSession(TransStore trans) throws APIException, IOException { // SessionFilter unused since 2015 // Try to use Trans' session, if exists @@ -388,12 +388,12 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { // return sess; // } // } - + // If there's an owning DAO, use it's session - if (owningDAO!=null) { + if (owningDAO!=null) { return owningDAO.getSession(trans); } - + // OK, nothing else works... get our own. if (session==null || resetTrigger) { Cluster tempCluster = null; @@ -414,7 +414,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { } } } - + if (reset || session == null) { TimeTaken tt = trans.start(NEW_CASSANDRA_SESSION, Env.SUB); try { @@ -458,7 +458,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { } return session; } - + public final boolean reportPerhapsReset(TransStore trans, Exception e) { if (owningDAO!=null) { return owningDAO.reportPerhapsReset(trans, e); @@ -468,7 +468,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { trans.warn().printf("Session Reset called for %s by %s ",session==null?"":session,e==null?"Mgmt Command":e.getClass().getName()); resetDeque.addFirst(new ResetRequest(session)); rv = resetTrigger = true; - } + } trans.error().log(e); return rv; } @@ -494,7 +494,7 @@ public abstract class AbsCassDAO<TRANS extends TransStore,DATA> { protected void wasModified(TRANS trans, CRUD modified, DATA data, String ... override) { } - + protected interface Accept<DATA> { public boolean ok(DATA data); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Bytification.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Bytification.java index 965ee2c2..617f7727 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Bytification.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Bytification.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. diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CIDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CIDAO.java index b148e87a..13bd350b 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CIDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CIDAO.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. @@ -30,7 +30,7 @@ public interface CIDAO<TRANS extends Trans> { /** * Touch the date field for given Table - * + * * @param trans * @param name * @return @@ -39,9 +39,9 @@ public interface CIDAO<TRANS extends Trans> { /** * Read all Info entries, and set local Date objects - * + * * This is to support regular data checks on the Database to speed up Caching behavior - * + * */ public abstract Result<Void> check(TRANS trans); diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cacheable.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cacheable.java index 818ae148..18946829 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cacheable.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cacheable.java @@ -8,9 +8,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. @@ -24,9 +24,9 @@ package org.onap.aaf.auth.dao; /** * Interface to obtain Segment Integer from DAO Data * for use in Caching mechanism - * + * * This should typically be obtained by getting the Hash of the key, then using modulus on the size of segment. - * + * * @author Jonathan * */ diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cached.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cached.java index 5605d653..a3fe1757 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cached.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Cached.java @@ -9,9 +9,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. @@ -40,7 +40,7 @@ import org.onap.aaf.misc.env.Trans; public class Cached<TRANS extends Trans, DATA extends Cacheable> extends Cache<TRANS,DATA> { // Java does not allow creation of Arrays with Generics in them... protected final CIDAO<TRANS> info; - + private static Timer infoTimer; private Object cache[]; public final int segSize; @@ -73,7 +73,7 @@ public class Cached<TRANS extends Trans, DATA extends Cacheable> extends Cache<T } return h%segSize; } - + public void add(String key, List<DATA> data) { @SuppressWarnings("unchecked") Map<String,Dated> map = ((Map<String,Dated>)cache[cacheIdx(key)]); @@ -105,21 +105,21 @@ public class Cached<TRANS extends Trans, DATA extends Cacheable> extends Cache<T public interface Getter<D> { public abstract Result<List<D>> get(); }; - + // TODO utilize Segmented Caches, and fold "get" into "reads" @SuppressWarnings("unchecked") public Result<List<DATA>> get(TRANS trans, String key, Getter<DATA> getter) { List<DATA> ld = null; Result<List<DATA>> rld = null; - + int cacheIdx = cacheIdx(key); Map<String, Dated> map = ((Map<String,Dated>)cache[cacheIdx]); - + // Check for saved element in cache Dated cached = map.get(key); // Note: These Segment Timestamps are kept up to date with DB Date dbStamp = info.get(trans, name,cacheIdx); - + // Check for cache Entry and whether it is still good (a good Cache Entry is same or after DBEntry, so we use "before" syntax) if (cached!=null && dbStamp!=null && dbStamp.before(cached.timestamp)) { ld = (List<DATA>)cached.data; @@ -139,7 +139,7 @@ public class Cached<TRANS extends Trans, DATA extends Cacheable> extends Cache<T * @param dao */ public static void startCleansing(AuthzEnv env, CachedDAO<?,?,?> ... dao) { - for (CachedDAO<?,?,?> d : dao) { + for (CachedDAO<?,?,?> d : dao) { for (int i=0;i<d.segSize;++i) { startCleansing(env, d.table()+i); } @@ -150,11 +150,11 @@ public class Cached<TRANS extends Trans, DATA extends Cacheable> extends Cache<T public static<T extends Trans> void startRefresh(AuthzEnv env, CIDAO<AuthzTrans> cidao) { if (infoTimer==null) { infoTimer = new Timer("CachedDAO Info Refresh Timer"); - int minRefresh = 10*1000*60; // 10 mins Integer.parseInt(env.getProperty(CACHE_MIN_REFRESH_INTERVAL,"2000")); // 2 second minimum refresh + int minRefresh = 10*1000*60; // 10 mins Integer.parseInt(env.getProperty(CACHE_MIN_REFRESH_INTERVAL,"2000")); // 2 second minimum refresh infoTimer.schedule(new Refresh(env,cidao, minRefresh), 1000, minRefresh); // note: Refresh from DB immediately } } - + public static void stopTimer() { Cache.stopTimer(); if (infoTimer!=null) { @@ -162,21 +162,21 @@ public class Cached<TRANS extends Trans, DATA extends Cacheable> extends Cache<T infoTimer = null; } } - + private static final class Refresh extends TimerTask { private static final int MAXREFRESH = 2*60*10000; // 20 mins private AuthzEnv env; private CIDAO<AuthzTrans> cidao; private int minRefresh; private long lastRun; - + public Refresh(AuthzEnv env, CIDAO<AuthzTrans> cidao, int minRefresh) { this.env = env; this.cidao = cidao; this.minRefresh = minRefresh; lastRun = System.currentTimeMillis()-MAXREFRESH-1000; } - + @Override public void run() { // Evaluate whether to refresh based on transaction rate diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CachedDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CachedDAO.java index cf410d0b..4e2cd72a 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CachedDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CachedDAO.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. @@ -30,25 +30,25 @@ import org.onap.aaf.misc.env.Trans; /** * CachedDAO - * - * Cache the response of "get" of any DAO. - * - * For simplicity's sake, at this time, we only do this for single Object keys - * + * + * Cache the response of "get" of any DAO. + * + * For simplicity's sake, at this time, we only do this for single Object keys + * * @author Jonathan * * @param <DATA> */ -public class CachedDAO<TRANS extends Trans,D extends DAO<TRANS,DATA>,DATA extends Cacheable> +public class CachedDAO<TRANS extends Trans,D extends DAO<TRANS,DATA>,DATA extends Cacheable> extends Cached<TRANS,DATA> implements DAO_RO<TRANS,DATA>{ -// private final String dirty_str; - +// private final String dirty_str; + private final D dao; public CachedDAO(D dao, CIDAO<TRANS> info, int segsize, long expireIn) { super(info, dao.table(), segsize, expireIn); - - // Instantiate a new Cache per DAO name (so separate instances use the same cache) + + // Instantiate a new Cache per DAO name (so separate instances use the same cache) this.dao = dao; //read_str = "Cached READ for " + dao.table(); // dirty_str = "Cache DIRTY on " + dao.table(); @@ -56,8 +56,8 @@ public class CachedDAO<TRANS extends Trans,D extends DAO<TRANS,DATA>,DATA extend ((CassDAOImpl<?,?>)dao).cache = this; } } - - public static<T extends Trans, DA extends DAO<T,DT>, DT extends Cacheable> + + public static<T extends Trans, DA extends DAO<T,DT>, DT extends Cacheable> CachedDAO<T,DA,DT> create(DA dao, CIDAO<T> info, int segsize, long expireIn) { return new CachedDAO<T,DA,DT>(dao,info, segsize, expireIn); } @@ -68,7 +68,7 @@ public class CachedDAO<TRANS extends Trans,D extends DAO<TRANS,DATA>,DATA extend list.add(data); super.add(key,list); } - + // public void invalidate(TRANS trans, Object ... objs) { // TimeTaken tt = trans.start(dirty_str, Env.SUB); // try { @@ -122,7 +122,7 @@ public class CachedDAO<TRANS extends Trans,D extends DAO<TRANS,DATA>,DATA extend this.dao = dao; this.objs = objs; } - + /** * Separated into single call for easy overloading * @return @@ -130,7 +130,7 @@ public class CachedDAO<TRANS extends Trans,D extends DAO<TRANS,DATA>,DATA extend public Result<List<DATA>> call() { return dao.read(trans, objs); } - + @Override public final Result<List<DATA>> get() { return call(); @@ -144,7 +144,7 @@ public class CachedDAO<TRANS extends Trans,D extends DAO<TRANS,DATA>,DATA extend @Override public Result<List<DATA>> read(final TRANS trans, final Object ... objs) { - DAOGetter getter = new DAOGetter(trans,dao,objs); + DAOGetter getter = new DAOGetter(trans,dao,objs); return get(trans, keyFromObjs(objs),getter); // if (ld!=null) { // return Result.ok(ld);//.emptyList(ld.isEmpty()); @@ -156,9 +156,9 @@ public class CachedDAO<TRANS extends Trans,D extends DAO<TRANS,DATA>,DATA extend // return getter.result; } - // Slight Improved performance available when String and Obj versions are known. + // Slight Improved performance available when String and Obj versions are known. public Result<List<DATA>> read(final String key, final TRANS trans, final Object[] objs) { - DAOGetter getter = new DAOGetter(trans,dao,objs); + DAOGetter getter = new DAOGetter(trans,dao,objs); return get(trans, key, getter); // if (ld!=null) { // return Result.ok(ld);//.emptyList(ld.isEmpty()); @@ -169,7 +169,7 @@ public class CachedDAO<TRANS extends Trans,D extends DAO<TRANS,DATA>,DATA extend // } // return getter.result; } - + @Override public Result<List<DATA>> read(TRANS trans, DATA data) { return read(trans,dao.keyFrom(data)); @@ -202,24 +202,24 @@ public class CachedDAO<TRANS extends Trans,D extends DAO<TRANS,DATA>,DATA extend data.invalidate(this); return rv; } - + @Override public void close(TRANS trans) { if (dao!=null) { dao.close(trans); } } - + @Override public String table() { return dao.table(); } - + public D dao() { return dao; } - + public void invalidate(TRANS trans, DATA data) { if (info.touch(trans, dao.table(),data.invalidate(this)).notOK()) { trans.error().log("Cannot touch CacheInfo for Role"); diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassAccess.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassAccess.java index c5ad4599..4246d314 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassAccess.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassAccess.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. @@ -93,7 +93,7 @@ public class CassAccess { cb.withCredentials(str, env.decryptor().decrypt(epass)); } } - + str = env.getProperty(pre+CASSANDRA_RESET_EXCEPTIONS,env.getProperty(CASSANDRA_RESET_EXCEPTIONS,null)); if (str!=null) { env.init().log("Cass ResetExceptions = ",str ); @@ -101,7 +101,7 @@ public class CassAccess { resetExceptions.add(new Resettable(env,ex)); } } - + str = env.getProperty(Config.CADI_LATITUDE); Double lat = str!=null && !str.isEmpty()?Double.parseDouble(str):null; str = env.getProperty(Config.CADI_LONGITUDE); @@ -109,9 +109,9 @@ public class CassAccess { if (lat == null || lon == null) { throw new APIException(Config.CADI_LATITUDE + " and/or " + Config.CADI_LONGITUDE + " are not set"); } - + env.init().printf("Service Latitude,Longitude = %f,%f",lat,lon); - + str = env.getProperty(pre+CASSANDRA_CLUSTERS,env.getProperty(CASSANDRA_CLUSTERS,"localhost")); env.init().printf("Cass Clusters = '%s'\n",str ); String[] machs = Split.split(',', str); @@ -124,7 +124,7 @@ public class CassAccess { if (minfo.length>0) { cpoints[i]=minfo[0]; } - + if (minfo.length>3) { if (minfo[1].equals(bestDC)) { ++numInBestDC; @@ -143,9 +143,9 @@ public class CassAccess { } } } - + cb.addContactPoints(cpoints); - + if (bestDC!=null) { // 8/26/2016 Management has determined that Accuracy is preferred over speed in bad situations // Local DC Aware Load Balancing appears to have the highest normal performance, with the best @@ -166,11 +166,11 @@ public class CassAccess { cb.withSocketOptions(new SocketOptions().setReadTimeoutMillis(6500000)); return cb.build(); } - + private static class Resettable { private Class<? extends Exception> cls; private List<String> messages; - + @SuppressWarnings("unchecked") public Resettable(Env env, String propData) throws APIException { if (propData!=null && propData.length()>1) { @@ -195,7 +195,7 @@ public class CassAccess { } } } - + public boolean matches(Exception ex) { if (ex.getClass().equals(cls)) { if (messages!=null) { @@ -210,7 +210,7 @@ public class CassAccess { return false; } } - + public static final boolean isResetException(Exception e) { if (e==null) { return true; diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassDAOImpl.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassDAOImpl.java index 68ec2e8b..bb4e2103 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassDAOImpl.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/CassDAOImpl.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. @@ -62,7 +62,7 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS protected final String U_TEXT = getClass().getSimpleName() + " UPDATE"; protected final String D_TEXT = getClass().getSimpleName() + " DELETE"; private String table; - + protected final ConsistencyLevel readConsistency; protected final ConsistencyLevel writeConsistency; @@ -71,7 +71,7 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS protected PSInfo updatePS; protected PSInfo deletePS; protected boolean async=false; - + // Setteable only by CachedDAO protected Cached<?, ?> cache; @@ -89,7 +89,7 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS readConsistency = read; writeConsistency = write; } - + /** * A Constructor to share Session with other DAOs. * @@ -113,18 +113,18 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS public final String[] setCRUD(TRANS trans, String table, Class<?> dc,Loader<DATA> loader) { return setCRUD(trans, table, dc, loader, -1); } - + public final String[] setCRUD(TRANS trans, String table, Class<?> dc,Loader<DATA> loader, int max) { Field[] fields = dc.getDeclaredFields(); int end = max>=0 && max<fields.length?max:fields.length; // get keylimit from a non-null Loader int keylimit = loader.keylimit(); - + StringBuilder sbfc = new StringBuilder(); StringBuilder sbq = new StringBuilder(); StringBuilder sbwc = new StringBuilder(); StringBuilder sbup = new StringBuilder(); - + if (keylimit>0) { for (int i=0;i<end;++i) { if (i>0) { @@ -148,18 +148,18 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS sbwc.append("=?"); } } - + createPS = new PSInfo(trans, "INSERT INTO " + table + " ("+ sbfc +") VALUES ("+ sbq +");",loader,writeConsistency); - + readPS = new PSInfo(trans, SELECT_SP + sbfc + " FROM " + table + WHERE + sbwc + ';',loader,readConsistency); - + // Note: UPDATES can't compile if there are no fields besides keys... Use "Insert" if (sbup.length()==0) { updatePS = createPS; // the same as an insert } else { updatePS = new PSInfo(trans, UPDATE_SP + table + " SET " + sbup + WHERE + sbwc + ';',loader,writeConsistency); } - + deletePS = new PSInfo(trans, "DELETE FROM " + table + WHERE + sbwc + ';',loader,writeConsistency); } return new String[] {sbfc.toString(), sbq.toString(), sbup.toString(), sbwc.toString()}; @@ -191,7 +191,7 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS } } - + /** * Given a DATA object, extract the individual elements from the Data into an Object Array for the * execute element. @@ -231,7 +231,7 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS } return readPS.read(trans, R_TEXT, key); } - + public Result<DATA> readPrimKey(TRANS trans, Object ... key) { if (readPS==null) { return Result.err(Result.ERR_NotImplemented,READ_IS_DISABLED,getClass().getSimpleName()); @@ -267,7 +267,7 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS return Result.err(rs); } } - + wasModified(trans, CRUD.update, data); return Result.ok(); } @@ -286,7 +286,7 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS if (rd.isEmpty()) { return Result.err(Status.ERR_NotFound,"Not Found"); } - for (DATA d : rd.value) { + for (DATA d : rd.value) { if (async) { Result<ResultSetFuture> rs = deletePS.execAsync(trans, D_TEXT, d); if (rs.notOK()) { @@ -316,7 +316,7 @@ public class CassDAOImpl<TRANS extends TransStore,DATA> extends AbsCassDAO<TRANS } return Result.ok(); } - + public final Object[] keyFrom(DATA data) { return createPS.keyFrom(data); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/DAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/DAO.java index 38759075..8d9185ba 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/DAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/DAO.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. diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/DAOException.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/DAOException.java index 7871e875..5045f6ec 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/DAOException.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/DAOException.java @@ -8,9 +8,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. @@ -25,7 +25,7 @@ package org.onap.aaf.auth.dao; public class DAOException extends Exception { /** - * + * */ private static final long serialVersionUID = 1527904125585539823L; diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/DAO_RO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/DAO_RO.java index ca4277e1..b8f3448c 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/DAO_RO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/DAO_RO.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. @@ -28,11 +28,11 @@ import org.onap.aaf.misc.env.Trans; /** * DataAccessObject - ReadOnly - * + * * It is useful to have a ReadOnly part of the interface for CachedDAO - * + * * Normal DAOs will implement full DAO - * + * * @author Jonathan * * @param <DATA> diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Loader.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Loader.java index 4a078f90..93203810 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Loader.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Loader.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. @@ -40,11 +40,11 @@ public abstract class Loader<DATA> { public Loader(int keylimit) { this.keylimit = keylimit; } - + public int keylimit() { return keylimit; } - + protected abstract DATA load(DATA data, Row row); protected abstract void key(DATA data, int idx, Object[] obj); protected abstract void body(DATA data, int idx, Object[] obj); @@ -74,7 +74,7 @@ public abstract class Loader<DATA> { } return rv; } - + public static void writeString(DataOutputStream os, String s) throws IOException { if (s==null) { os.writeInt(-1); @@ -90,11 +90,11 @@ public abstract class Loader<DATA> { } } } - - + + /** * We use bytes here to set a Maximum - * + * * @param is * @param MAX * @return @@ -118,10 +118,10 @@ public abstract class Loader<DATA> { /** * Write a set with proper sizing - * + * * Note: at the moment, this is just String. Probably can develop system where types * are supported too... but not now. - * + * * @param os * @param set * @throws IOException @@ -137,7 +137,7 @@ public abstract class Loader<DATA> { } } - + public static Set<String> readStringSet(DataInputStream is, byte[] buff) throws IOException { int l = is.readInt(); if (l<0) { @@ -149,7 +149,7 @@ public abstract class Loader<DATA> { } return set; } - + public static List<String> readStringList(DataInputStream is, byte[] buff) throws IOException { int l = is.readInt(); if (l<0) { @@ -162,7 +162,7 @@ public abstract class Loader<DATA> { return list; } - /** + /** * Write a map * @param os * @param map @@ -198,7 +198,7 @@ public abstract class Loader<DATA> { os.writeInt(magic); os.writeInt(version); } - + public static int readHeader(DataInputStream is, final int magic, final int version) throws IOException { if (is.readInt()!=magic) { throw new IOException("Corrupted Data Stream"); diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Streamer.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Streamer.java index af3567eb..a072289f 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Streamer.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Streamer.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. diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Touchable.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Touchable.java index 0fcda19c..2707f7a0 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Touchable.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/Touchable.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. diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedCertDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedCertDAO.java index c0a2c49c..9b86f80c 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedCertDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedCertDAO.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. @@ -33,19 +33,19 @@ public class CachedCertDAO extends CachedDAO<AuthzTrans, CertDAO, CertDAO.Data> public CachedCertDAO(CertDAO dao, CIDAO<AuthzTrans> info, long expiresIn) { super(dao, info, CertDAO.CACHE_SEG, expiresIn); } - + /** * Pass through Cert ID Lookup - * + * * @param trans * @param ns * @return */ - + public Result<List<CertDAO.Data>> readID(AuthzTrans trans, final String id) { return dao().readID(trans, id); } - + public Result<List<CertDAO.Data>> readX500(AuthzTrans trans, final String x500) { return dao().readX500(trans, x500); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedCredDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedCredDAO.java index a8a3796a..9c55d464 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedCredDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedCredDAO.java @@ -8,9 +8,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. @@ -35,7 +35,7 @@ import org.onap.aaf.auth.layer.Result; public class CachedCredDAO extends CachedDAO<AuthzTrans, CredDAO, CredDAO.Data> { private final ReadID readID; private final ReadID readIDBath; - + public CachedCredDAO(CredDAO dao, CIDAO<AuthzTrans> info, long expiresIn) { super(dao, info, CredDAO.CACHE_SEG, expiresIn); if(FileGetter.isLoaded) { @@ -52,12 +52,12 @@ public class CachedCredDAO extends CachedDAO<AuthzTrans, CredDAO, CredDAO.Data> @Override public Result<List<Data>> read(AuthzTrans trans, final String id) { DAOGetter getter = new DAOGetter(trans,dao()) { - @Override + @Override public Result<List<CredDAO.Data>> call() { return dao().readID(trans, id); } }; - + Result<List<CredDAO.Data>> lurd = get(trans, id, getter); if (lurd.isOK() && lurd.isEmpty()) { return Result.err(Status.ERR_UserNotFound,"No User Cred found"); @@ -65,17 +65,17 @@ public class CachedCredDAO extends CachedDAO<AuthzTrans, CredDAO, CredDAO.Data> return lurd; } }; - + readIDBath = new ReadID() { @Override public Result<List<Data>> read(AuthzTrans trans, final String id) { DAOGetter getter = new DAOGetter(trans,dao()) { - @Override + @Override public Result<List<CredDAO.Data>> call() { return dao().readIDBAth(trans, id); } }; - + Result<List<CredDAO.Data>> lurd = get(trans, id, getter); if (lurd.isOK() && lurd.isEmpty()) { return Result.err(Status.ERR_UserNotFound,"No User Cred found"); @@ -85,18 +85,18 @@ public class CachedCredDAO extends CachedDAO<AuthzTrans, CredDAO, CredDAO.Data> }; } } - + /** * Pass through Cred Lookup - * + * * Unlike Role and Perm, we don't need or want to cache these elements... Only used for NS Delete. - * + * * @param trans * @param ns * @return */ public Result<List<CredDAO.Data>> readNS(AuthzTrans trans, final String ns) { - + return dao().readNS(trans, ns); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedNSDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedNSDAO.java index e639767c..df089d00 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedNSDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedNSDAO.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. diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedPermDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedPermDAO.java index 13180ab1..7ea7dd75 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedPermDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedPermDAO.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. @@ -44,12 +44,12 @@ public class CachedPermDAO extends CachedDAO<AuthzTrans,PermDAO, PermDAO.Data> { return dao.readNS(trans, ns); } }; - + Result<List<Data>> lurd = get(trans, ns, getter); if (lurd.isOKhasData()) { return lurd; } else { - + } // if (getter.result==null) { // if (lurd==null) { @@ -66,7 +66,7 @@ public class CachedPermDAO extends CachedDAO<AuthzTrans,PermDAO, PermDAO.Data> { } /** - * + * * @param trans * @param ns * @param type @@ -78,7 +78,7 @@ public class CachedPermDAO extends CachedDAO<AuthzTrans,PermDAO, PermDAO.Data> { return dao.readByType(trans, ns, type); } }; - + // Note: Can reuse index1 here, because there is no name collision versus response Result<List<Data>> lurd = get(trans, ns+'|'+type, getter); if (lurd.isOK() && lurd.isEmpty()) { @@ -86,10 +86,10 @@ public class CachedPermDAO extends CachedDAO<AuthzTrans,PermDAO, PermDAO.Data> { } return lurd; } - + /** * Add desciption to this permission - * + * * @param trans * @param ns * @param type @@ -98,12 +98,12 @@ public class CachedPermDAO extends CachedDAO<AuthzTrans,PermDAO, PermDAO.Data> { * @param description * @return */ - public Result<Void> addDescription(AuthzTrans trans, String ns, String type, + public Result<Void> addDescription(AuthzTrans trans, String ns, String type, String instance, String action, String description) { //TODO Invalidate? return dao().addDescription(trans, ns, type, instance, action, description); } - + public Result<Void> addRole(AuthzTrans trans, PermDAO.Data perm, RoleDAO.Data role) { Result<Void> rv = dao().addRole(trans,perm,role.encode()); if (trans.debug().isLoggable()) diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedRoleDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedRoleDAO.java index 99fac2da..b90c3579 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedRoleDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedRoleDAO.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. @@ -43,7 +43,7 @@ public class CachedRoleDAO extends CachedDAO<AuthzTrans,RoleDAO, RoleDAO.Data> { return dao.readNS(trans, ns); } }; - + Result<List<Data>> lurd = get(trans, ns, getter); if (lurd.isOK() && lurd.isEmpty()) { return Result.err(Status.ERR_RoleNotFound,"No Role found"); @@ -57,7 +57,7 @@ public class CachedRoleDAO extends CachedDAO<AuthzTrans,RoleDAO, RoleDAO.Data> { return dao().readName(trans, name); } }; - + Result<List<Data>> lurd = get(trans, name, getter); if (lurd.isOK() && lurd.isEmpty()) { return Result.err(Status.ERR_RoleNotFound,"No Role found"); @@ -87,10 +87,10 @@ public class CachedRoleDAO extends CachedDAO<AuthzTrans,RoleDAO, RoleDAO.Data> { invalidate(trans, rd); return rv; } - + /** * Add description to this role - * + * * @param trans * @param ns * @param name diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedUserRoleDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedUserRoleDAO.java index c1aa9017..c3f353e0 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedUserRoleDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cached/CachedUserRoleDAO.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,7 +42,7 @@ public class CachedUserRoleDAO extends CachedDAO<AuthzTrans,UserRoleDAO, UserRol } /** - * Special Case. + * Special Case. * User Roles by User are very likely to be called many times in a Transaction, to validate "May User do..." * Pull result, and make accessible by the Trans, which is always keyed by User. * @param trans @@ -71,7 +71,7 @@ public class CachedUserRoleDAO extends CachedDAO<AuthzTrans,UserRoleDAO, UserRol return lurd; } - + public Result<List<Data>> readByRole(AuthzTrans trans, final String role) { DAOGetter getter = new DAOGetter(trans,dao()) { public Result<List<Data>> call() { 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 a8c86fa5..702f989a 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,107 +42,105 @@ 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"; + public static boolean isLoaded = false; + private static FileGetter singleton; + + private Map<String,List<CredDAO.Data>> 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<CredDAO.Data> 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<CredDAO.Data> getter(String id) { + return new FGetter(id); + } + private static List<CredDAO.Data> EMPTY = new ArrayList<>(); + public class FGetter implements Getter<CredDAO.Data> { + private final List<CredDAO.Data> lcdd; + public FGetter(final String id) { + lcdd = data.get(id); + } + @Override + public Result<List<Data>> get() { + return Result.ok(lcdd==null?EMPTY:lcdd); + } + } - private Map<String,List<CredDAO.Data>> 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<CredDAO.Data> 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 void main(String[] args) { + PropAccess access = new PropAccess(args); + access.setProperty(AAF_FILEGETTER,"/Users/jg1555/cred.dat"); + FileGetter fg = FileGetter.singleton(access); - public static synchronized FileGetter singleton(Access access) { - if(singleton==null) { - singleton = new FileGetter(access); - } - return singleton; - - } - public Getter<CredDAO.Data> getter(String id) { - return new FGetter(id); - } - private static List<CredDAO.Data> EMPTY = new ArrayList<>(); - public class FGetter implements Getter<CredDAO.Data> { - private final List<CredDAO.Data> lcdd; - public FGetter(final String id) { - lcdd = data.get(id); - } - @Override - public Result<List<Data>> 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<CredDAO.Data> g = fg.getter(id); - Result<List<CredDAO.Data>> r = g.get(); - if(r.isOKhasData()) { - for(CredDAO.Data cdd : r.value) { - System.out.println(cdd); - } - } - } - } + for(String id : new String[] {"m01891@aaf.att.com","bogus"}) { + Getter<CredDAO.Data> g = fg.getter(id); + Result<List<CredDAO.Data>> r = g.get(); + if(r.isOKhasData()) { + for(CredDAO.Data cdd : r.value) { + System.out.println(cdd); + } + } + } + } } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/ApprovalDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/ApprovalDAO.java index 5583dc03..139e85a9 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/ApprovalDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/ApprovalDAO.java @@ -9,9 +9,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. @@ -48,7 +48,7 @@ public class ApprovalDAO extends CassDAOImpl<AuthzTrans,ApprovalDAO.Data> { public static final String PENDING = "pending"; public static final String DENIED = "denied"; public static final String APPROVED = "approved"; - + private static final String TABLE = "approval"; private static final String TABLELOG = "approved"; private HistoryDAO historyDAO; @@ -58,7 +58,7 @@ public class ApprovalDAO extends CassDAOImpl<AuthzTrans,ApprovalDAO.Data> { private PSInfo psByStatus; private static final int KEYLIMIT = 1; - + public ApprovalDAO(AuthzTrans trans, Cluster cluster, String keyspace) { super(trans, ApprovalDAO.class.getSimpleName(),cluster,keyspace,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); historyDAO = new HistoryDAO(trans, this); @@ -83,14 +83,14 @@ public class ApprovalDAO extends CassDAOImpl<AuthzTrans,ApprovalDAO.Data> { public String operation; public Date updated; } - + private static class ApprovalLoader extends Loader<Data> { public static final ApprovalLoader deflt = new ApprovalLoader(KEYLIMIT); - + public ApprovalLoader(int keylimit) { super(keylimit); } - + @Override public Data load(Data data, Row row) { data.id = row.getUUID(0); @@ -101,7 +101,7 @@ public class ApprovalDAO extends CassDAOImpl<AuthzTrans,ApprovalDAO.Data> { data.status = row.getString(5); data.memo = row.getString(6); data.operation = row.getString(7); - // This is used to get "WRITETIME(STATUS)" from Approval, which gives us an "updated" + // This is used to get "WRITETIME(STATUS)" from Approval, which gives us an "updated" if (row.getColumnDefinitions().size()>8) { // Rows reported in MicroSeconds data.updated = new Date(row.getLong(8)/1000); @@ -125,19 +125,19 @@ public class ApprovalDAO extends CassDAOImpl<AuthzTrans,ApprovalDAO.Data> { obj[++idx]=data.memo; obj[++idx]=data.operation; } - } - + } + private void init(AuthzTrans trans) { String[] helpers = setCRUD(trans, TABLE, Data.class, ApprovalLoader.deflt,8); - psByUser = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + ", WRITETIME(status) FROM " + TABLE + + psByUser = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + ", WRITETIME(status) FROM " + TABLE + " WHERE user = ?", new ApprovalLoader(1) { @Override protected void key(Data data, int idx, Object[] obj) { obj[idx]=data.user; } }, readConsistency); - - psByApprover = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + ", WRITETIME(status) FROM " + TABLE + + + psByApprover = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + ", WRITETIME(status) FROM " + TABLE + " WHERE approver = ?", new ApprovalLoader(1) { @Override protected void key(Data data, int idx, Object[] obj) { @@ -145,7 +145,7 @@ public class ApprovalDAO extends CassDAOImpl<AuthzTrans,ApprovalDAO.Data> { } }, readConsistency); - psByTicket = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + ", WRITETIME(status) FROM " + TABLE + + psByTicket = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + ", WRITETIME(status) FROM " + TABLE + " WHERE ticket = ?", new ApprovalLoader(1) { @Override protected void key(Data data, int idx, Object[] obj) { @@ -153,7 +153,7 @@ public class ApprovalDAO extends CassDAOImpl<AuthzTrans,ApprovalDAO.Data> { } }, readConsistency); - psByStatus = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + ", WRITETIME(status) FROM " + TABLE + + psByStatus = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + ", WRITETIME(status) FROM " + TABLE + " WHERE status = ?", new ApprovalLoader(1) { @Override protected void key(Data data, int idx, Object[] obj) { @@ -177,7 +177,7 @@ public class ApprovalDAO extends CassDAOImpl<AuthzTrans,ApprovalDAO.Data> { if (rs.notOK()) { return Result.err(rs); } - return Result.ok(data); + return Result.ok(data); } @@ -195,7 +195,7 @@ public class ApprovalDAO extends CassDAOImpl<AuthzTrans,ApprovalDAO.Data> { public Result<List<ApprovalDAO.Data>> readByStatus(AuthzTrans trans, String status) { return psByStatus.read(trans, R_TEXT, new Object[]{status}); - } + } /* (non-Javadoc) * @see org.onap.aaf.auth.dao.CassDAOImpl#delete(com.att.inno.env.TransStore, java.lang.Object, boolean) @@ -209,7 +209,7 @@ public class ApprovalDAO extends CassDAOImpl<AuthzTrans,ApprovalDAO.Data> { } ApprovalLoader.deflt.load(data, rd.value.one()); } - if (APPROVED.equals(data.status) || DENIED.equals(data.status)) { + if (APPROVED.equals(data.status) || DENIED.equals(data.status)) { StringBuilder sb = new StringBuilder("BEGIN BATCH\n"); sb.append("INSERT INTO "); sb.append(TABLELOG); diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/ArtiDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/ArtiDAO.java index e0c0c0d4..08de28ec 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/ArtiDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/ArtiDAO.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. @@ -43,16 +43,16 @@ import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Row; /** - * CredDAO manages credentials. + * CredDAO manages credentials. * @author Jonathan * Date: 7/19/13 */ public class ArtiDAO extends CassDAOImpl<AuthzTrans,ArtiDAO.Data> { public static final String TABLE = "artifact"; - + private HistoryDAO historyDAO; private PSInfo psByMechID,psByMachine, psByNs; - + public ArtiDAO(AuthzTrans trans, Cluster cluster, String keyspace) { super(trans, ArtiDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); init(trans); @@ -78,7 +78,7 @@ public class ArtiDAO extends CassDAOImpl<AuthzTrans,ArtiDAO.Data> { public Date expires; public int renewDays; public Set<String> sans; - + // // Getters public Set<String> type(boolean mutable) { if (type == null) { @@ -104,7 +104,7 @@ public class ArtiDAO extends CassDAOImpl<AuthzTrans,ArtiDAO.Data> { ArtifactLoader.deflt.marshal(this,new DataOutputStream(baos)); return ByteBuffer.wrap(baos.toByteArray()); } - + @Override public void reconstitute(ByteBuffer bb) throws IOException { ArtifactLoader.deflt.unmarshal(this, toDIS(bb)); @@ -118,7 +118,7 @@ public class ArtiDAO extends CassDAOImpl<AuthzTrans,ArtiDAO.Data> { private static class ArtifactLoader extends Loader<Data> implements Streamer<Data>{ public static final int MAGIC=95829343; public static final int VERSION=1; - public static final int BUFF_SIZE=48; // Note: + public static final int BUFF_SIZE=48; // Note: public static final ArtifactLoader deflt = new ArtifactLoader(KEYLIMIT); public ArtifactLoader(int keylimit) { @@ -225,10 +225,10 @@ public class ArtiDAO extends CassDAOImpl<AuthzTrans,ArtiDAO.Data> { if (historyDAO==null) { historyDAO = new HistoryDAO(trans,this); } - + String[] helpers = setCRUD(trans, TABLE, Data.class, ArtifactLoader.deflt); - psByMechID = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + psByMechID = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE mechid = ?", new ArtifactLoader(1) { @Override protected void key(Data data, int idx, Object[] obj) { @@ -236,7 +236,7 @@ public class ArtiDAO extends CassDAOImpl<AuthzTrans,ArtiDAO.Data> { } },readConsistency); - psByMachine = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + psByMachine = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE machine = ?", new ArtifactLoader(1) { @Override protected void key(Data data, int idx, Object[] obj) { @@ -244,7 +244,7 @@ public class ArtiDAO extends CassDAOImpl<AuthzTrans,ArtiDAO.Data> { } },readConsistency); - psByNs = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + psByNs = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE ns = ?", new ArtifactLoader(1) { @Override protected void key(Data data, int idx, Object[] obj) { @@ -253,8 +253,8 @@ public class ArtiDAO extends CassDAOImpl<AuthzTrans,ArtiDAO.Data> { },readConsistency); } - - + + public Result<List<Data>> readByMechID(AuthzTrans trans, String mechid) { return psByMechID.read(trans, R_TEXT, new Object[]{mechid}); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java index eea3c4c2..6a32a365 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheInfoDAO.java @@ -9,9 +9,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. @@ -69,7 +69,7 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl public static final Map<String,Date[]> info = new ConcurrentHashMap<>(); private static CacheUpdate cacheUpdate; - + // Hold current time stamps from Tables private final Date startTime; private final boolean cacheNotify; @@ -79,7 +79,7 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl // Data Definition, matches Cassandra DM ////////////////////////////////////////// private static final int KEYLIMIT = 2; - + public CacheInfoDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { super(trans, CacheInfoDAO.class.getSimpleName(),cluster,keyspace,Data.class,TABLE,readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); startTime = new Date(); @@ -94,8 +94,8 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl cacheNotify = noK8s(trans); } - /** - * Need a different point to point cache clear strategy for K8s... + /** + * Need a different point to point cache clear strategy for K8s... * @param trans * @return */ @@ -124,11 +124,11 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl private static class InfoLoader extends Loader<Data> { public static final InfoLoader dflt = new InfoLoader(KEYLIMIT); - + public InfoLoader(int keylimit) { super(keylimit); } - + @Override public Data load(Data data, Row row) { // Int more efficient @@ -151,7 +151,7 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl obj[idx]=data.touched; } } - + public static synchronized <T extends Trans> void startUpdate(AuthzEnv env, HMangr hman, SecuritySetter<HttpURLConnection> ss, String ip, int port) { if (cacheUpdate==null) { cacheUpdate = new CacheUpdate(env,hman,ss, ip,port); @@ -176,15 +176,15 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl private SecuritySetter<HttpURLConnection> ss; private final String authority; public boolean go = true; - + public CacheUpdate(AuthzEnv env, HMangr hman, SecuritySetter<HttpURLConnection> ss, String ip, int port) { this.env = env; this.hman = hman; this.ss = ss; - + this.authority = ip+':'+port; } - + private static class Transfer { public String table; public int segs[]; @@ -198,7 +198,7 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl private AuthzTrans trans; private String type; private String segs; - + public CacheClear(AuthzTrans trans) { this.trans = trans; } @@ -207,7 +207,7 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl type = es.getKey(); segs = es.getValue().toString(); } - + @Override public Integer code(Rcli<?> client) throws APIException, CadiException { URI to = client.getURI(); @@ -222,11 +222,11 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl return total; } } - + private class IntHolder { private int[] raw; HashSet<Integer> set; - + public IntHolder(int ints[]) { raw = ints; set = null; @@ -234,7 +234,7 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl public void add(int[] ints) { if (set==null) { set = new HashSet<>(); - + for (int i=0;i<raw.length;++i) { set.add(raw[i]); } @@ -270,7 +270,7 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl return sb.toString(); } } - + @Override public void run() { do { @@ -279,7 +279,7 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl if (data==null) { continue; } - + int count = 0; CacheClear cc = null; Map<String,IntHolder> gather = null; @@ -319,7 +319,7 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl sb.append(count); if (count==1) { sb.append(" entry for "); - } else { + } else { sb.append(" entries for "); } int peers = count<=0?0:cc.total/count; @@ -354,13 +354,13 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl /* (non-Javadoc) * @see org.onap.aaf.auth.dao.cass.CIDAO#touch(org.onap.aaf.auth.env.test.AuthzTrans, java.lang.String, int) */ - + @Override public Result<Void> touch(AuthzTrans trans, String name, int ... seg) { ///////////// // Direct Service Cache Invalidation ///////////// - // ConcurrentQueues are open-ended. We don't want any Memory leaks + // ConcurrentQueues are open-ended. We don't want any Memory leaks // Note: we keep a separate counter, because "size()" on a Linked Queue is expensive if (cacheNotify && cacheUpdate!=null) { try { @@ -389,7 +389,7 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl sb.append(name); sb.append("' AND seg = "); sb.append(s); - sb.append(";\n"); + sb.append(";\n"); if (first) { first =false; } else { @@ -425,7 +425,7 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl } finally { tt.done(); } - + String lastName = null; Date[] dates = null; for (Row row : rs.all()) { @@ -451,7 +451,7 @@ public class CacheInfoDAO extends CassDAOImpl<AuthzTrans,CacheInfoDAO.Data> impl } return Result.ok(); } - + /* (non-Javadoc) * @see org.onap.aaf.auth.dao.cass.CIDAO#get(java.lang.String, int) */ diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheableData.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheableData.java index be7c44ae..0b0ca7fa 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheableData.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CacheableData.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. @@ -26,10 +26,10 @@ import org.onap.aaf.auth.dao.Cached; import org.onap.aaf.auth.dao.CachedDAO; public abstract class CacheableData implements Cacheable { - // WARNING: DON'T attempt to add any members here, as it will + // WARNING: DON'T attempt to add any members here, as it will // be treated by system as fields expected in Tables protected int seg(Cached<?,?> cache, Object ... fields) { return cache==null?0:cache.invalidate(CachedDAO.keyFromObjs(fields)); } - + } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CertDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CertDAO.java index 6c23938f..59248868 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CertDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CertDAO.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. @@ -43,18 +43,18 @@ import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Row; /** - * CredDAO manages credentials. + * CredDAO manages credentials. * @author Jonathan * Date: 7/19/13 */ public class CertDAO extends CassDAOImpl<AuthzTrans,CertDAO.Data> { public static final String TABLE = "x509"; public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F - + private HistoryDAO historyDAO; private CIDAO<AuthzTrans> infoDAO; private PSInfo psX500,psID; - + public CertDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { super(trans, CertDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); init(trans); @@ -66,10 +66,10 @@ public class CertDAO extends CassDAOImpl<AuthzTrans,CertDAO.Data> { infoDAO = ciDao; init(trans); } - + public static final int KEYLIMIT = 2; public static class Data extends CacheableData implements Bytification { - + public String ca; public BigInteger serial; public String id; @@ -82,14 +82,14 @@ public class CertDAO extends CassDAOImpl<AuthzTrans,CertDAO.Data> { seg(cache,ca,serial) }; } - + @Override public ByteBuffer bytify() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); CertLoader.deflt.marshal(this,new DataOutputStream(baos)); return ByteBuffer.wrap(baos.toByteArray()); } - + @Override public void reconstitute(ByteBuffer bb) throws IOException { CertLoader.deflt.unmarshal(this, toDIS(bb)); @@ -99,7 +99,7 @@ public class CertDAO extends CassDAOImpl<AuthzTrans,CertDAO.Data> { private static class CertLoader extends Loader<Data> implements Streamer<Data>{ public static final int MAGIC=85102934; public static final int VERSION=1; - public static final int BUFF_SIZE=48; // Note: + public static final int BUFF_SIZE=48; // Note: public static final CertLoader deflt = new CertLoader(KEYLIMIT); public CertLoader(int keylimit) { @@ -133,7 +133,7 @@ public class CertDAO extends CassDAOImpl<AuthzTrans,CertDAO.Data> { obj[++idx] = data.x500; obj[++idx] = data.x509; - + } @Override @@ -172,7 +172,7 @@ public class CertDAO extends CassDAOImpl<AuthzTrans,CertDAO.Data> { } } } - + public Result<List<CertDAO.Data>> read(AuthzTrans trans, Object ... key) { // Translate BigInteger to Byte array for lookup return super.read(trans, key[0],ByteBuffer.wrap(((BigInteger)key[1]).toByteArray())); @@ -194,9 +194,9 @@ public class CertDAO extends CassDAOImpl<AuthzTrans,CertDAO.Data> { psX500 = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE x500 = ?", CertLoader.deflt,readConsistency); - + } - + public Result<List<Data>> readX500(AuthzTrans trans, String x500) { return psX500.read(trans, R_TEXT, new Object[]{x500}); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/ConfigDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/ConfigDAO.java index 9f402adc..1228fce5 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/ConfigDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/ConfigDAO.java @@ -9,9 +9,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. @@ -40,7 +40,7 @@ import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Row; /** - * CredDAO manages credentials. + * CredDAO manages credentials. * @author Jonathan * Date: 6/25/18 */ @@ -49,7 +49,7 @@ public class ConfigDAO extends CassDAOImpl<AuthzTrans,ConfigDAO.Data> { public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F public static final int KEYLIMIT = 2; private PSInfo psName; - + public ConfigDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { super(trans, ConfigDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE_NAME, readConsistency(trans,TABLE_NAME), writeConsistency(trans,TABLE_NAME)); init(trans); @@ -69,7 +69,7 @@ public class ConfigDAO extends CassDAOImpl<AuthzTrans,ConfigDAO.Data> { private static class ConfigLoader extends Loader<Data> implements Streamer<Data>{ public static final int MAGIC=2673849; public static final int VERSION=1; - public static final int BUFF_SIZE=48; + public static final int BUFF_SIZE=48; public static final ConfigLoader deflt = new ConfigLoader(KEYLIMIT); public ConfigLoader(int keylimit) { @@ -113,14 +113,14 @@ public class ConfigDAO extends CassDAOImpl<AuthzTrans,ConfigDAO.Data> { data.value = readString(is,buff); } } - + private void init(AuthzTrans trans) throws APIException, IOException { String[] helpers = setCRUD(trans, TABLE_NAME, Data.class, ConfigLoader.deflt); psName = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE_NAME + " WHERE name = ?", ConfigLoader.deflt,readConsistency); } - + /** * Log Modification statements to History @@ -133,7 +133,7 @@ public class ConfigDAO extends CassDAOImpl<AuthzTrans,ConfigDAO.Data> { protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) { // not an auditable table. } - + public Result<List<Data>> readName(AuthzTrans trans, String name) { return psName.read(trans, R_TEXT, new Object[]{name}); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CredDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CredDAO.java index 5acc836e..137969e6 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CredDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/CredDAO.java @@ -8,9 +8,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. @@ -46,7 +46,7 @@ import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Row; /** - * CredDAO manages credentials. + * CredDAO manages credentials. * @author Jonathan * Date: 7/19/13 */ @@ -60,13 +60,13 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { public static final int BASIC_AUTH_SHA256 = 2; public static final int CERT_SHA256_RSA =200; public static final SecureRandom srand = new SecureRandom(); - + private HistoryDAO historyDAO; private CIDAO<AuthzTrans> infoDAO; private PSInfo psNS; private PSInfo psID; private PSInfo psIDBath; - + public CredDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { super(trans, CredDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); init(trans); @@ -81,7 +81,7 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { public static final int KEYLIMIT = 3; public static class Data extends CacheableData implements Bytification { - + public String id; public Integer type; public Date expires; @@ -98,14 +98,14 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { seg(cache,id) // cache is for all entities }; } - + @Override public ByteBuffer bytify() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); CredLoader.deflt.marshal(this,new DataOutputStream(baos)); return ByteBuffer.wrap(baos.toByteArray()); } - + @Override public void reconstitute(ByteBuffer bb) throws IOException { CredLoader.deflt.unmarshal(this, toDIS(bb)); @@ -119,7 +119,7 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { public static class CredLoader extends Loader<Data> implements Streamer<Data>{ public static final int MAGIC=153323443; public static final int VERSION=2; - public static final int BUFF_SIZE=48; // Note: + public static final int BUFF_SIZE=48; // Note: public static final CredLoader deflt = new CredLoader(KEYLIMIT); public CredLoader(int keylimit) { @@ -132,10 +132,10 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { data.type = row.getInt(1); // NOTE: in datastax driver, If the int value is NULL, 0 is returned! data.expires = row.getTimestamp(2); data.other = row.getInt(3); - data.ns = row.getString(4); + data.ns = row.getString(4); data.tag = row.getString(5); data.notes = row.getString(6); - data.cred = row.getBytesUnsafe(7); + data.cred = row.getBytesUnsafe(7); return data; } @@ -163,7 +163,7 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { public void marshal(Data data, DataOutputStream os) throws IOException { writeHeader(os,MAGIC,VERSION); writeString(os, data.id); - os.writeInt(data.type); + os.writeInt(data.type); os.writeLong(data.expires==null?-1:data.expires.getTime()); os.writeInt(data.other==null?0:data.other); writeString(os, data.ns); @@ -185,14 +185,14 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { byte[] buff = new byte[BUFF_SIZE]; data.id = readString(is,buff); data.type = is.readInt(); - + long l = is.readLong(); data.expires = l<0?null:new Date(l); data.other = is.readInt(); data.ns = readString(is,buff); data.tag = readString(is,buff); data.notes = readString(is,buff); - + int i = is.readInt(); data.cred=null; if (i>=0) { @@ -213,16 +213,16 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { if (infoDAO==null) { infoDAO = new CacheInfoDAO(trans,this); } - + String[] helpers = setCRUD(trans, TABLE, Data.class, CredLoader.deflt); - + psNS = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE ns = ?", CredLoader.deflt,readConsistency); - + psID = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE id = ?", CredLoader.deflt,readConsistency); - + // NOTE: (type) in ((1),(2)) is valid for Cass 2.1.14. After 2.1.14, more obvious // syntax of type in (1,2) is available // ALSO, 1 & 2 STAND FOR BASIC_AUTH (MD5) AND BASIC_AUTH_SHA256(with salt). @@ -232,7 +232,7 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { psIDBath = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE id = ? and (type) in ((1),(2))", CredLoader.deflt,readConsistency); } - + /* (non-Javadoc) * @see org.onap.aaf.auth.dao.CassDAOImpl#create(org.onap.aaf.misc.env.TransStore, java.lang.Object) */ @@ -252,11 +252,11 @@ public class CredDAO extends CassDAOImpl<AuthzTrans,CredDAO.Data> { public Result<List<Data>> readNS(AuthzTrans trans, String ns) { return psNS.read(trans, R_TEXT, new Object[]{ns}); } - + public Result<List<Data>> readID(AuthzTrans trans, String id) { return psID.read(trans, R_TEXT, new Object[]{id}); } - + public Result<List<Data>> readIDBAth(AuthzTrans trans, String id) { return psIDBath.read(trans, R_TEXT, new Object[] {id}); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/DelegateDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/DelegateDAO.java index e7749bd5..1f7afb8c 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/DelegateDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/DelegateDAO.java @@ -9,9 +9,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. @@ -47,7 +47,7 @@ public class DelegateDAO extends CassDAOImpl<AuthzTrans, DelegateDAO.Data> { public static final String TABLE = "delegate"; private PSInfo psByDelegate; private static final int KEYLIMIT = 1; - + public DelegateDAO(AuthzTrans trans, Cluster cluster, String keyspace) { super(trans, DelegateDAO.class.getSimpleName(),cluster,keyspace,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); init(trans); @@ -57,8 +57,8 @@ public class DelegateDAO extends CassDAOImpl<AuthzTrans, DelegateDAO.Data> { super(trans, DelegateDAO.class.getSimpleName(),aDao,Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); init(trans); } - - + + public static class Data implements Bytification { public String user; public String delegate; @@ -70,13 +70,13 @@ public class DelegateDAO extends CassDAOImpl<AuthzTrans, DelegateDAO.Data> { DelegateLoader.dflt.marshal(this,new DataOutputStream(baos)); return ByteBuffer.wrap(baos.toByteArray()); } - + @Override public void reconstitute(ByteBuffer bb) throws IOException { DelegateLoader.dflt.unmarshal(this, toDIS(bb)); } } - + private static class DelegateLoader extends Loader<Data> implements Streamer<Data>{ public static final int MAGIC=0xD823ACF2; public static final int VERSION=1; @@ -87,7 +87,7 @@ public class DelegateDAO extends CassDAOImpl<AuthzTrans, DelegateDAO.Data> { public DelegateLoader(int keylimit) { super(keylimit); } - + @Override public Data load(Data data, Row row) { data.user = row.getString(0); @@ -126,8 +126,8 @@ public class DelegateDAO extends CassDAOImpl<AuthzTrans, DelegateDAO.Data> { data.delegate = readString(is,buff); data.expires = new Date(is.readLong()); } - } - + } + private void init(AuthzTrans trans) { String[] helpers = setCRUD(trans, TABLE, Data.class, DelegateLoader.dflt); psByDelegate = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/FutureDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/FutureDAO.java index eafdb884..15c2b557 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/FutureDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/FutureDAO.java @@ -9,9 +9,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. @@ -38,9 +38,9 @@ import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; /** - * FutureDAO stores Construction information to create + * FutureDAO stores Construction information to create * elements at another time. - * + * * @author Jonathan * 8/20/2013 */ @@ -152,7 +152,7 @@ public class FutureDAO extends CassDAOImpl<AuthzTrans,FutureDAO.Data> { return Result.err(rs); } wasModified(trans, CRUD.create, data, null, id); - return Result.ok(data); + return Result.ok(data); } /** @@ -172,10 +172,10 @@ public class FutureDAO extends CassDAOImpl<AuthzTrans,FutureDAO.Data> { hd.target = TABLE; hd.subject = subject?override[1]:""; hd.memo = memo?String.format("%s by %s", override[0], hd.user):data.memo; - + if (historyDAO.create(trans, hd).status!=Status.OK) { trans.error().log("Cannot log to History"); } } - + } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/HistoryDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/HistoryDAO.java index 82874ce9..c994dd53 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/HistoryDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/HistoryDAO.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. @@ -40,16 +40,16 @@ import com.datastax.driver.core.Row; /** * History - * + * * Originally written PE3617 * @author Jonathan - * + * * History is a special case, because we don't want Updates or Deletes... Too likely to mess up history. - * + * * Jonathan 9-9-2013 - Found a problem with using "Prepare". You cannot prepare anything with a "now()" in it, as * it is evaluated once during the prepare, and kept. That renders any use of "now()" pointless. Therefore * the Create function needs to be run fresh everytime. - * + * * Fixed in Cassandra 1.2.6 https://issues.apache.org/jira/browse/CASSANDRA-5616 * */ @@ -84,7 +84,7 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> { public String memo; public ByteBuffer reconstruct; } - + public static class HistLoader extends Loader<Data> { public HistLoader(int keylimit) { super(keylimit); @@ -118,10 +118,10 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> { obj[++idx]=data.subject; obj[++idx]=data.memo; // obj[++idx]=data.detail; - obj[++idx]=data.reconstruct; + obj[++idx]=data.reconstruct; } }; - + private void init(AuthzTrans trans) { // Loader must match fields order defLoader = new HistLoader(KEYLIMIT); @@ -130,9 +130,9 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> { // Need a specialty Creator to handle the "now()" // 9/9/2013 - Jonathan - Just great... now() is evaluated once on Client side, invalidating usage (what point is a now() from a long time in the past? // Unless this is fixed, we're putting in non-prepared statement - // Solved in Cassandra. Make sure you are running 1.2.6 Cassandra or later. https://issues.apache.org/jira/browse/CASSANDRA-5616 + // Solved in Cassandra. Make sure you are running 1.2.6 Cassandra or later. https://issues.apache.org/jira/browse/CASSANDRA-5616 replace(CRUD.create, new PSInfo(trans, "INSERT INTO history (" + helpers[FIELD_COMMAS] + - ") VALUES(now(),?,?,?,?,?,?,?)", + ") VALUES(now(),?,?,?,?,?,?,?)", new HistLoader(0) { @Override protected void key(Data data, int idx, Object[] obj) { @@ -140,9 +140,9 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> { },writeConsistency) ); // disable(CRUD.Create); - + replace(CRUD.read, new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + - " FROM history WHERE id = ?", defLoader,readConsistency) + " FROM history WHERE id = ?", defLoader,readConsistency) // new HistLoader(2) { // @Override // protected void key(Data data, int idx, Object[] obj) { @@ -153,12 +153,12 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> { ); disable(CRUD.update); disable(CRUD.delete); - - readByUser = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + + + readByUser = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM history WHERE user = ?", defLoader,readConsistency); - readBySubject = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + + readBySubject = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM history WHERE subject = ? and target = ? ALLOW FILTERING", defLoader,readConsistency); - readByYRMN = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + + readByYRMN = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM history WHERE yr_mon = ?", defLoader,readConsistency); async(true); //TODO dropping messages with Async } @@ -169,9 +169,9 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> { // Sonar claims that SimpleDateFormat is not thread safe, so we can't be static data.yr_mon = Integer.parseInt(new SimpleDateFormat("yyyyMM").format(now)); // data.day_time = Integer.parseInt(dayTimeFormat.format(now)); - return data; + return data; } - + public void createBatch(StringBuilder sb, Data data) { sb.append("INSERT INTO history ("); sb.append(helpers[FIELD_COMMAS]); @@ -213,7 +213,7 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> { } return extract(defLoader,rs.value,null,yyyymm.length>0?new YYYYMM(yyyymm):dflt); } - + public Result<List<Data>> readBySubject(AuthzTrans trans, String subject, String target, int ... yyyymm) { if (yyyymm.length==0) { return Result.err(Status.ERR_BadData, "No or invalid yyyymm specified"); @@ -224,7 +224,7 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> { } return extract(defLoader,rs.value,null,yyyymm.length>0?new YYYYMM(yyyymm):dflt); } - + private class YYYYMM implements Accept<Data> { private int[] yyyymm; public YYYYMM(int yyyymm[]) { @@ -240,7 +240,7 @@ public class HistoryDAO extends CassDAOImpl<AuthzTrans, HistoryDAO.Data> { } return false; } - + }; - + } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/LocateDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/LocateDAO.java index 478cceb0..3fad6a7a 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/LocateDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/LocateDAO.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. @@ -44,14 +44,14 @@ import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Row; /** - * LocateDAO manages credentials. + * LocateDAO manages credentials. * @author Jonathan * Date: 10/11/17 */ public class LocateDAO extends CassDAOImpl<AuthzTrans,LocateDAO.Data> { public static final String TABLE = "locate"; private AbsCassDAO<AuthzTrans, Data>.PSInfo psName; - + public LocateDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { super(trans, LocateDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); init(trans); @@ -61,10 +61,10 @@ public class LocateDAO extends CassDAOImpl<AuthzTrans,LocateDAO.Data> { super(trans, LocateDAO.class.getSimpleName(), adao, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); init(trans); } - + public static final int KEYLIMIT = 3; public static class Data implements Bytification { - + public String name; public String hostname; public int port; @@ -87,14 +87,14 @@ public class LocateDAO extends CassDAOImpl<AuthzTrans,LocateDAO.Data> { } return subprotocol; } - + @Override public ByteBuffer bytify() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); LocateLoader.deflt.marshal(this,new DataOutputStream(baos)); return ByteBuffer.wrap(baos.toByteArray()); } - + @Override public void reconstitute(ByteBuffer bb) throws IOException { LocateLoader.deflt.unmarshal(this, toDIS(bb)); @@ -122,8 +122,8 @@ public class LocateDAO extends CassDAOImpl<AuthzTrans,LocateDAO.Data> { private static class LocateLoader extends Loader<Data> implements Streamer<Data>{ public static final int MAGIC=85102934; public static final int VERSION=1; - public static final int BUFF_SIZE=48; // Note: - + public static final int BUFF_SIZE=48; // Note: + public static final LocateLoader deflt = new LocateLoader(KEYLIMIT); public LocateLoader(int keylimit) { super(keylimit); @@ -188,7 +188,7 @@ public class LocateDAO extends CassDAOImpl<AuthzTrans,LocateDAO.Data> { writeString(os,s); } } - + writeString(os,data.port_key==null?"":data.port_key.toString()); } @@ -207,7 +207,7 @@ public class LocateDAO extends CassDAOImpl<AuthzTrans,LocateDAO.Data> { data.latitude = is.readFloat(); data.longitude = is.readFloat(); data.protocol = readString(is,buff); - + int size = is.readInt(); data.subprotocol = new HashSet<>(size); for (int i=0;i<size;++i) { @@ -221,7 +221,7 @@ public class LocateDAO extends CassDAOImpl<AuthzTrans,LocateDAO.Data> { } } } - + public Result<List<LocateDAO.Data>> readByName(AuthzTrans trans, String service) { return psName.read(trans, "Read By Name", new Object[] {service}); } @@ -235,7 +235,7 @@ public class LocateDAO extends CassDAOImpl<AuthzTrans,LocateDAO.Data> { psName = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE name = ?", new LocateLoader(1),readConsistency); } - + /** * Log Modification statements to History * diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/Namespace.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/Namespace.java index 192887b9..3e669483 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/Namespace.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/Namespace.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. @@ -49,7 +49,7 @@ public class Namespace implements Bytification { public Integer type; public String parent; public Namespace() {} - + public Namespace(NsDAO.Data ndd) { name = ndd.name; description = ndd.description; @@ -62,7 +62,7 @@ public class Namespace implements Bytification { } } } - + public Namespace(NsDAO.Data ndd,List<String> owner, List<String> admin) { name = ndd.name; this.owner = owner; @@ -108,7 +108,7 @@ public class Namespace implements Bytification { DataInputStream is = CassDAOImpl.toDIS(bb); /*int version = */Loader.readHeader(is,MAGIC,VERSION); // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields - + byte[] buff = new byte[BUFF_SIZE]; name = Loader.readString(is, buff); type = is.readInt(); @@ -116,7 +116,7 @@ public class Namespace implements Bytification { owner = Loader.readStringList(is,buff); description = Loader.readString(is,buff); parent = Loader.readString(is,buff); - + } /* (non-Javadoc) @@ -126,7 +126,7 @@ public class Namespace implements Bytification { public int hashCode() { return name.hashCode(); } - + /* (non-Javadoc) * @see java.lang.Object#toString() diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/NsDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/NsDAO.java index 10e7844c..24bd01de 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/NsDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/NsDAO.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. @@ -54,9 +54,9 @@ import com.datastax.driver.core.exceptions.DriverException; /** * NsDAO - * + * * Data Access Object for Namespace Data - * + * * @author Jonathan * */ @@ -73,7 +73,7 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { private static final String APPLY_BATCH = "\nAPPLY BATCH;\n"; private static final String SQSCCR = "';\n"; private static final String SQCSQ = "','"; - + private HistoryDAO historyDAO; private CacheInfoDAO infoDAO; private PSInfo psNS; @@ -97,7 +97,7 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { private static final int KEYLIMIT = 1; /** * Data class that matches the Cassandra Table "role" - * + * * @author Jonathan */ public static class Data extends CacheableData implements Bytification { @@ -135,19 +135,19 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { NSLoader.deflt.marshal(this,new DataOutputStream(baos)); return ByteBuffer.wrap(baos.toByteArray()); } - + @Override public void reconstitute(ByteBuffer bb) throws IOException { NSLoader.deflt.unmarshal(this,toDIS(bb)); } - + @Override public String toString() { return name; } - + } - + private void init(AuthzTrans trans) throws APIException, IOException { // Set up sub-DAOs if (historyDAO==null) { @@ -158,19 +158,19 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { } String[] helpers = setCRUD(trans, TABLE, Data.class, NSLoader.deflt,4/*need to skip attrib */); - + psNS = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE parent = ?", new NSLoader(1),readConsistency); } - + private static final class NSLoader extends Loader<Data> implements Streamer<Data> { public static final int MAGIC=250935515; public static final int VERSION=1; public static final int BUFF_SIZE=48; public static final NSLoader deflt = new NSLoader(KEYLIMIT); - + public NSLoader(int keylimit) { super(keylimit); } @@ -198,7 +198,7 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { obj[++idx]=data.description; obj[++idx]=data.parent; } - + @Override public void marshal(Data data, DataOutputStream os) throws IOException { writeHeader(os,MAGIC,VERSION); @@ -221,7 +221,7 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { public void unmarshal(Data data, DataInputStream is) throws IOException { /*int version = */readHeader(is,MAGIC,VERSION); // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields - + byte[] buff = new byte[BUFF_SIZE]; data.name = readString(is, buff); data.type = is.readInt(); @@ -237,7 +237,7 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { } } - + @Override public Result<Data> create(AuthzTrans trans, Data data) { String ns = data.name; @@ -253,8 +253,8 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { stmt.append(APPLY_BATCH); try { getSession(trans).execute(stmt.toString()); -//// TEST CODE for Exception -// boolean force = true; +//// TEST CODE for Exception +// boolean force = true; // if (force) { // throw new com.datastax.driver.core.exceptions.NoHostAvailableException(new HashMap<>()); //// throw new com.datastax.driver.core.exceptions.AuthenticationException(new InetSocketAddress(9999),"Sample Message"); @@ -293,7 +293,7 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { attribUpdateStmt(stmt, ns, es.getKey(),es.getValue()); } } - + // No point in deleting... insert overwrites... // for (Entry<String, String> es : remoteAttr.entrySet()) { // str = localAttr.get(es.getKey()); @@ -320,7 +320,7 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { @Override public Result<List<Data>> read(AuthzTrans trans, Data data) { Result<List<Data>> rld = super.read(trans, data); - + if (rld.isOKhasData()) { for (Data d : rld.value) { // Note: Map is null at this point, save time/mem by assignment @@ -375,17 +375,17 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { return super.delete(trans, data, reread); } - + public Result<Map<String,String>> readAttribByNS(AuthzTrans trans, String ns) { Map<String,String> map = new HashMap<>(); TimeTaken tt = trans.start("readAttribByNS " + ns, Env.REMOTE); try { - ResultSet rs = getSession(trans).execute("SELECT key,value FROM " - + TABLE_ATTRIB + ResultSet rs = getSession(trans).execute("SELECT key,value FROM " + + TABLE_ATTRIB + " WHERE ns='" + ns + "';"); - + for (Iterator<Row> iter = rs.iterator();iter.hasNext(); ) { Row r = iter.next(); map.put(r.getString(0), r.getString(1)); @@ -403,12 +403,12 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { Set<String> set = new HashSet<>(); TimeTaken tt = trans.start("readNsBykey " + key, Env.REMOTE); try { - ResultSet rs = getSession(trans).execute("SELECT ns FROM " - + TABLE_ATTRIB + ResultSet rs = getSession(trans).execute("SELECT ns FROM " + + TABLE_ATTRIB + " WHERE key='" + key + "';"); - + for (Iterator<Row> iter = rs.iterator();iter.hasNext(); ) { Row r = iter.next(); set.add(r.getString(0)); @@ -431,7 +431,7 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); } } - + private StringBuilder attribInsertStmt(StringBuilder sb, String ns, String key, String value) { sb.append("INSERT INTO "); sb.append(TABLE_ATTRIB); @@ -457,7 +457,7 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { sb.append("';"); return sb; } - + public Result<Void> attribRemove(AuthzTrans trans, String ns, String key) { try { @@ -468,7 +468,7 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { return Result.err(Result.ERR_Backend, CassAccess.ERR_ACCESS_MSG); } } - + private StringBuilder attribDeleteStmt(StringBuilder stmt, String ns, String key) { stmt.append("DELETE FROM "); stmt.append(TABLE_ATTRIB); @@ -479,7 +479,7 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { stmt.append("';"); return stmt; } - + private void attribDeleteAllStmt(StringBuilder stmt, Data data) { stmt.append(" DELETE FROM "); stmt.append(TABLE_ATTRIB); @@ -505,7 +505,7 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { */ public Result<Void> addDescription(AuthzTrans trans, String ns, String description) { try { - getSession(trans).execute(UPDATE_SP + TABLE + " SET description = '" + getSession(trans).execute(UPDATE_SP + TABLE + " SET description = '" + description.replace("'", "''") + "' WHERE name = '" + ns + "';"); } catch (DriverException | APIException | IOException e) { reportPerhapsReset(trans,e); @@ -521,11 +521,11 @@ public class NsDAO extends CassDAOImpl<AuthzTrans,NsDAO.Data> { public Result<List<Data>> getChildren(AuthzTrans trans, String parent) { return psNS.read(trans, R_TEXT, new Object[]{parent}); } - + /** * Log Modification statements to History - * + * * @param modified which CRUD action was done * @param data entity data that needs a log entry * @param overrideMessage if this is specified, we use it rather than crafting a history message based on data diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/NsSplit.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/NsSplit.java index 2beeaf38..017c813a 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/NsSplit.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/NsSplit.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. @@ -25,7 +25,7 @@ public class NsSplit { public final String ns; public final String name; public final NsDAO.Data nsd; - + public NsSplit(NsDAO.Data nsd, String child) { this.nsd = nsd; if (child.startsWith(nsd.name)) { @@ -41,7 +41,7 @@ public class NsSplit { ns = null; } } - + public NsSplit(String ns, String name) { this.ns = ns; this.name = name; diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/NsType.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/NsType.java index e656a555..bc7aa227 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/NsType.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/NsType.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. @@ -29,19 +29,19 @@ package org.onap.aaf.auth.dao.cass; public enum NsType { UNKNOWN (-1), DOT (0), - ROOT (1), - COMPANY (2), - APP (3), - STACKED_APP (10), + ROOT (1), + COMPANY (2), + APP (3), + STACKED_APP (10), STACK (11); - + public final int type; private NsType(int t) { type = t; } /** * This is not the Ordinal, but the Type that is stored in NS Tables - * + * * @param t * @return */ @@ -53,7 +53,7 @@ public enum NsType { } return UNKNOWN; } - + /** * Use this one rather than "valueOf" to avoid Exception * @param s @@ -70,5 +70,5 @@ public enum NsType { return UNKNOWN; } - + } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/OAuthTokenDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/OAuthTokenDAO.java index 5d0f084b..a84490d0 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/OAuthTokenDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/OAuthTokenDAO.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. @@ -44,19 +44,19 @@ import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Row; /** - * CredDAO manages credentials. + * CredDAO manages credentials. * @author Jonathan * Date: 7/19/13 */ public class OAuthTokenDAO extends CassDAOImpl<AuthzTrans,OAuthTokenDAO.Data> { public static final String TABLE = "oauth_token"; private AbsCassDAO<AuthzTrans, Data>.PSInfo psByUser; - + public OAuthTokenDAO(AuthzTrans trans, Cluster cluster, String keyspace) { super(trans, OAuthTokenDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); init(trans); } - + public OAuthTokenDAO(AuthzTrans trans, AbsCassDAO<AuthzTrans,?> aDao) { super(trans, OAuthTokenDAO.class.getSimpleName(),aDao, Data.class, TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); init(trans); @@ -73,7 +73,7 @@ public class OAuthTokenDAO extends CassDAOImpl<AuthzTrans,OAuthTokenDAO.Data> { public String refresh; public Date expires; public long exp_sec; - public String content; + public String content; public Set<String> scopes; public String state; public String req_ip; // requesting @@ -93,7 +93,7 @@ public class OAuthTokenDAO extends CassDAOImpl<AuthzTrans,OAuthTokenDAO.Data> { OAuthLoader.deflt.marshal(this,new DataOutputStream(baos)); return ByteBuffer.wrap(baos.toByteArray()); } - + @Override public void reconstitute(ByteBuffer bb) throws IOException { OAuthLoader.deflt.unmarshal(this, toDIS(bb)); @@ -107,13 +107,13 @@ public class OAuthTokenDAO extends CassDAOImpl<AuthzTrans,OAuthTokenDAO.Data> { private static class OAuthLoader extends Loader<Data> implements Streamer<Data>{ public static final int MAGIC=235677843; public static final int VERSION=1; - public static final int BUFF_SIZE=96; // Note: only used when - + public static final int BUFF_SIZE=96; // Note: only used when + public static final OAuthLoader deflt = new OAuthLoader(KEYLIMIT); public OAuthLoader(int keylimit) { super(keylimit); } - + @Override public Data load(Data data, Row row) { data.id = row.getString(0); diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/PermDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/PermDAO.java index 699d6e28..a59682c4 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/PermDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/PermDAO.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. @@ -53,10 +53,10 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F private static final String STAR = "*"; - + private final HistoryDAO historyDAO; private final CacheInfoDAO infoDAO; - + private PSInfo psNS, psChildren, psByType; public PermDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException { @@ -80,11 +80,11 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { public String type; public String instance; public String action; - public Set<String> roles; + public Set<String> roles; public String description; public Data() {} - + public Data(NsSplit nss, String instance, String action) { ns = nss.ns; type = nss.name; @@ -103,7 +103,7 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { sb.append(type); return sb.toString(); } - + public String fullPerm() { StringBuilder sb = new StringBuilder(); if(ns==null) { @@ -123,10 +123,10 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { public String encode() { return ns + '|' + type + '|' + instance + '|' + action; } - + /** * Decode Perm String, including breaking into appropriate Namespace - * + * * @param trans * @param q * @param p @@ -158,7 +158,7 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { /** * Decode Perm String, including breaking into appropriate Namespace - * + * * @param trans * @param q * @param p @@ -169,7 +169,7 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { if (ss[2]==null) { return Result.err(Status.ERR_BadData,"Perm Encodings must be separated by '|'"); } - + if (ss[3]==null) { // older 3 part encoding must be evaluated for NS ss[3] = ss[2]; ss[2] = ss[1]; @@ -206,7 +206,7 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { } return rv; } - + public static Data create(AuthzTrans trans, Question q, String name) { String[] s = name.split("\\|"); Result<NsSplit> rdns = q.deriveNsSplit(trans, s[0]); @@ -240,7 +240,7 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { } return rv; } - + //////////////////////////////////////// // Getters public Set<String> roles(boolean mutable) { @@ -268,7 +268,7 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { PermLoader.deflt.marshal(this, new DataOutputStream(baos)); return ByteBuffer.wrap(baos.toByteArray()); } - + @Override public void reconstitute(ByteBuffer bb) throws IOException { PermLoader.deflt.unmarshal(this, toDIS(bb)); @@ -279,18 +279,18 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { return encode(); } } - + private static class PermLoader extends Loader<Data> implements Streamer<Data> { public static final int MAGIC=283939453; public static final int VERSION=1; public static final int BUFF_SIZE=96; public static final PermLoader deflt = new PermLoader(KEYLIMIT); - + public PermLoader(int keylimit) { super(keylimit); } - + @Override public Data load(Data data, Row row) { // Int more efficient Match "fields" string @@ -343,25 +343,25 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { data.description = readString(is,buff); } } - + private void init(AuthzTrans trans) { // the 3 is the number of key fields String[] helpers = setCRUD(trans, TABLE, Data.class, PermLoader.deflt); - + // Other SELECT style statements... match with a local Method - psByType = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + psByType = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE ns = ? AND type = ?", new PermLoader(2) { @Override protected void key(Data data, int idx, Object[] obj) { obj[idx]=data.type; } },readConsistency); - + psNS = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE ns = ?", new PermLoader(1),readConsistency); - - psChildren = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + - " WHERE ns=? AND type > ? AND type < ?", + + psChildren = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE ns=? AND type > ? AND type < ?", new PermLoader(3) { @Override protected void key(Data data, int _idx, Object[] obj) { @@ -377,7 +377,7 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { /** * Add a single Permission to the Role's Permission Collection - * + * * @param trans * @param roleFullName * @param perm @@ -438,11 +438,11 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { } - + /** - * Additional method: + * Additional method: * Select all Permissions by Name - * + * * @param name * @return * @throws DAOException @@ -450,7 +450,7 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { public Result<List<Data>> readByType(AuthzTrans trans, String ns, String type) { return psByType.read(trans, R_TEXT, new Object[]{ns, type}); } - + public Result<List<Data>> readChildren(AuthzTrans trans, String ns, String type) { return psChildren.read(trans, R_TEXT, new Object[]{ns, type+DOT, type + DOT_PLUS_ONE}); } @@ -461,7 +461,7 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { /** * Add description to this permission - * + * * @param trans * @param ns * @param type @@ -473,7 +473,7 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { public Result<Void> addDescription(AuthzTrans trans, String ns, String type, String instance, String action, String description) { try { - getSession(trans).execute(UPDATE_SP + TABLE + " SET description = '" + getSession(trans).execute(UPDATE_SP + TABLE + " SET description = '" + description + "' WHERE ns = '" + ns + "' AND type = '" + type + "'" + "AND instance = '" + instance + "' AND action = '" + action + "';"); } catch (DriverException | APIException | IOException e) { @@ -486,11 +486,11 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { data.type=type; data.instance=instance; data.action=action; - wasModified(trans, CRUD.update, data, "Added description " + description + " to permission " + wasModified(trans, CRUD.update, data, "Added description " + description + " to permission " + data.encode(), null ); return Result.ok(); } - + /** * Log Modification statements to History */ @@ -510,7 +510,7 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { } else { hd.memo = String.format("%sd %s|%s|%s", modified.name(),data.fullType(),data.instance,data.action); } - + if (modified==CRUD.delete) { try { hd.reconstruct = data.bytify(); @@ -518,7 +518,7 @@ public class PermDAO extends CassDAOImpl<AuthzTrans,PermDAO.Data> { trans.error().log(e,"Could not serialize PermDAO.Data"); } } - + if (historyDAO.create(trans, hd).status!=Status.OK) { trans.error().log("Cannot log to History"); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/RoleDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/RoleDAO.java index e5c97559..ae8d525d 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/RoleDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/RoleDAO.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. @@ -50,7 +50,7 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { public static final String TABLE = "role"; public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F - + private final HistoryDAO historyDAO; private final CacheInfoDAO infoDAO; @@ -96,34 +96,34 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { } return perms; } - + public static Data create(NsDAO.Data ns, String name) { - NsSplit nss = new NsSplit(ns,name); + NsSplit nss = new NsSplit(ns,name); RoleDAO.Data rv = new Data(); rv.ns = nss.ns; rv.name=nss.name; return rv; } - + public String fullName() { StringBuilder sb = new StringBuilder(); if(ns==null) { sb.append('.'); } else { sb.append(ns); - sb.append(ns.indexOf('@')<0?'.':':'); + sb.append(ns.indexOf('@')<0?'.':':'); } sb.append(name); return sb.toString(); } - + public String encode() { return ns + '|' + name; } - + /** * Decode Perm String, including breaking into appropriate Namespace - * + * * @param trans * @param q * @param r @@ -171,7 +171,7 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { /** * Decode Perm String, including breaking into appropriate Namespace - * + * * @param trans * @param q * @param p @@ -189,7 +189,7 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { } return Result.ok(ss); } - + @Override public int[] invalidate(Cached<?,?> cache) { return new int[] { @@ -205,7 +205,7 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { RoleLoader.deflt.marshal(this,new DataOutputStream(baos)); return ByteBuffer.wrap(baos.toByteArray()); } - + @Override public void reconstitute(ByteBuffer bb) throws IOException { RoleLoader.deflt.unmarshal(this, toDIS(bb)); @@ -223,11 +223,11 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { public static final int BUFF_SIZE=96; public static final RoleLoader deflt = new RoleLoader(KEYLIMIT); - + public RoleLoader(int keylimit) { super(keylimit); } - + @Override public Data load(Data data, Row row) { // Int more efficient @@ -275,15 +275,15 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { private void init(AuthzTrans trans) { String[] helpers = setCRUD(trans, TABLE, Data.class, RoleLoader.deflt); - + psNS = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE ns = ?", new RoleLoader(1),readConsistency); psName = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE name = ?", new RoleLoader(1),readConsistency); - psChildren = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + - " WHERE ns=? AND name > ? AND name < ?", + psChildren = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE ns=? AND name > ? AND name < ?", new RoleLoader(3) { @Override protected void key(Data data, int _idx, Object[] obj) { @@ -293,7 +293,7 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { obj[++idx]=data.name + DOT_PLUS_ONE; } },readConsistency); - + } public Result<List<Data>> readNS(AuthzTrans trans, String ns) { @@ -306,7 +306,7 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { public Result<List<Data>> readChildren(AuthzTrans trans, String ns, String role) { if (role.length()==0 || "*".equals(role)) { - return psChildren.read(trans, R_TEXT, new Object[]{ns, FIRST_CHAR, LAST_CHAR}); + return psChildren.read(trans, R_TEXT, new Object[]{ns, FIRST_CHAR, LAST_CHAR}); } else { return psChildren.read(trans, R_TEXT, new Object[]{ns, role+DOT, role+DOT_PLUS_ONE}); } @@ -314,7 +314,7 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { /** * Add a single Permission to the Role's Permission Collection - * + * * @param trans * @param role * @param perm @@ -326,7 +326,7 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { // Note: Prepared Statements for Collection updates aren't supported String pencode = perm.encode(); try { - getSession(trans).execute(UPDATE_SP + TABLE + " SET perms = perms + {'" + + getSession(trans).execute(UPDATE_SP + TABLE + " SET perms = perms + {'" + pencode + "'} WHERE " + "ns = '" + role.ns + "' AND name = '" + role.name + "';"); } catch (DriverException | APIException | IOException e) { @@ -351,10 +351,10 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { // Note: Prepared Statements for Collection updates aren't supported String pencode = perm.encode(); - + //ResultSet rv = try { - getSession(trans).execute(UPDATE_SP + TABLE + " SET perms = perms - {'" + + getSession(trans).execute(UPDATE_SP + TABLE + " SET perms = perms - {'" + pencode + "'} WHERE " + "ns = '" + role.ns + "' AND name = '" + role.name + "';"); } catch (DriverException | APIException | IOException e) { @@ -366,10 +366,10 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { wasModified(trans, CRUD.update, role, "Removed permission " + pencode + " from role " + role.fullName() ); return Result.ok(); } - + /** * Add description to role - * + * * @param trans * @param ns * @param name @@ -378,7 +378,7 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { */ public Result<Void> addDescription(AuthzTrans trans, String ns, String name, String description) { try { - getSession(trans).execute(UPDATE_SP + TABLE + " SET description = '" + getSession(trans).execute(UPDATE_SP + TABLE + " SET description = '" + description + "' WHERE ns = '" + ns + "' AND name = '" + name + "';"); } catch (DriverException | APIException | IOException e) { reportPerhapsReset(trans,e); @@ -391,8 +391,8 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { wasModified(trans, CRUD.update, data, "Added description " + description + " to role " + data.fullName(), null ); return Result.ok(); } - - + + /** * Log Modification statements to History * @param modified which CRUD action was done @@ -426,5 +426,5 @@ public class RoleDAO extends CassDAOImpl<AuthzTrans,RoleDAO.Data> { } } - + }
\ No newline at end of file diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/Status.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/Status.java index a4d0bf4d..3a05eb31 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/Status.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/Status.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. @@ -28,7 +28,7 @@ import org.onap.aaf.auth.layer.Result; /** * Add additional Behavior for Specific Applications for Results - * + * * In this case, we add additional BitField information accessible by * method ( * @author Jonathan @@ -36,11 +36,11 @@ import org.onap.aaf.auth.layer.Result; * @param <RV> */ public class Status<RV> extends Result<RV> { - + // Jonathan 10/1/2013: Initially, I used enum, but it's not extensible. public final static int ERR_NsNotFound = Result.ERR_General+1, ERR_RoleNotFound = Result.ERR_General+2, - ERR_PermissionNotFound = Result.ERR_General+3, + ERR_PermissionNotFound = Result.ERR_General+3, ERR_UserNotFound = Result.ERR_General+4, ERR_UserRoleNotFound = Result.ERR_General+5, ERR_DelegateNotFound = Result.ERR_General+6, @@ -51,9 +51,9 @@ public class Status<RV> extends Result<RV> { ACC_Future = Result.ERR_General+11, ERR_ChoiceNeeded = Result.ERR_General+12, ERR_FutureNotRequested = Result.ERR_General+13; - + /** - * Constructor for Result set. + * Constructor for Result set. * @param data * @param status */ @@ -66,7 +66,7 @@ public class Status<RV> extends Result<RV> { case OK: return "OK"; case ERR_NsNotFound: return "ERR_NsNotFound"; case ERR_RoleNotFound: return "ERR_RoleNotFound"; - case ERR_PermissionNotFound: return "ERR_PermissionNotFound"; + case ERR_PermissionNotFound: return "ERR_PermissionNotFound"; case ERR_UserNotFound: return "ERR_UserNotFound"; case ERR_UserRoleNotFound: return "ERR_UserRoleNotFound"; case ERR_DelegateNotFound: return "ERR_DelegateNotFound"; @@ -81,8 +81,8 @@ public class Status<RV> extends Result<RV> { case ERR_NotFound: return "ERR_NotFound"; case ERR_ChoiceNeeded: return "ERR_ChoiceNeeded"; } - //case ERR_General: or unknown... + //case ERR_General: or unknown... return "ERR_General"; } - + } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/UserRoleDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/UserRoleDAO.java index b6cbcf82..813f55ac 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/UserRoleDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/UserRoleDAO.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. @@ -47,15 +47,15 @@ import com.datastax.driver.core.Row; public class UserRoleDAO extends CassDAOImpl<AuthzTrans,UserRoleDAO.Data> { public static final String TABLE = "user_role"; - + public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F private static final String TRANS_UR_SLOT = "_TRANS_UR_SLOT_"; public Slot transURSlot; - + private final HistoryDAO historyDAO; private final CacheInfoDAO infoDAO; - + private PSInfo psByUser, psByRole, psUserInRole; @@ -82,10 +82,10 @@ public class UserRoleDAO extends CassDAOImpl<AuthzTrans,UserRoleDAO.Data> { public static class Data extends CacheableData implements Bytification { public String user; public String role; - public String ns; - public String rname; + public String ns; + public String rname; public Date expires; - + @Override public int[] invalidate(Cached<?,?> cache) { // Note: I'm not worried about Name collisions, because the formats are different: @@ -105,7 +105,7 @@ public class UserRoleDAO extends CassDAOImpl<AuthzTrans,UserRoleDAO.Data> { URLoader.deflt.marshal(this,new DataOutputStream(baos)); return ByteBuffer.wrap(baos.toByteArray()); } - + @Override public void reconstitute(ByteBuffer bb) throws IOException { URLoader.deflt.unmarshal(this, toDIS(bb)); @@ -116,14 +116,14 @@ public class UserRoleDAO extends CassDAOImpl<AuthzTrans,UserRoleDAO.Data> { this.rname = rname; this.role = ns + '.' + rname; } - + public void role(RoleDAO.Data rdd) { ns = rdd.ns; rname = rdd.name; role = rdd.fullName(); } - + public boolean role(AuthzTrans trans, Question ques, String role) { this.role = role; Result<NsSplit> rnss = ques.deriveNsSplit(trans, role); @@ -141,12 +141,12 @@ public class UserRoleDAO extends CassDAOImpl<AuthzTrans,UserRoleDAO.Data> { return user + '|' + ns + '|' + rname + '|' + Chrono.dateStamp(expires); } } - + private static class URLoader extends Loader<Data> implements Streamer<Data> { public static final int MAGIC=738469903; public static final int VERSION=1; public static final int BUFF_SIZE=48; - + public static final URLoader deflt = new URLoader(KEYLIMIT); public URLoader(int keylimit) { @@ -177,7 +177,7 @@ public class UserRoleDAO extends CassDAOImpl<AuthzTrans,UserRoleDAO.Data> { obj[++idx]=data.rname; obj[++idx]=data.expires; } - + @Override public void marshal(Data data, DataOutputStream os) throws IOException { writeHeader(os,MAGIC,VERSION); @@ -193,7 +193,7 @@ public class UserRoleDAO extends CassDAOImpl<AuthzTrans,UserRoleDAO.Data> { public void unmarshal(Data data, DataInputStream is) throws IOException { /*int version = */readHeader(is,MAGIC,VERSION); // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields - + byte[] buff = new byte[BUFF_SIZE]; data.user = readString(is,buff); data.role = readString(is,buff); @@ -204,27 +204,27 @@ public class UserRoleDAO extends CassDAOImpl<AuthzTrans,UserRoleDAO.Data> { } }; - + private void init(AuthzTrans trans) { String[] helper = setCRUD(trans, TABLE, Data.class, URLoader.deflt); - - psByUser = new PSInfo(trans, SELECT_SP + helper[FIELD_COMMAS] + " FROM user_role WHERE user = ?", + + psByUser = new PSInfo(trans, SELECT_SP + helper[FIELD_COMMAS] + " FROM user_role WHERE user = ?", new URLoader(1) { @Override protected void key(Data data, int idx, Object[] obj) { obj[idx]=data.user; } },readConsistency); - + // Note: We understand this call may have poor performance, so only should be used in Management (Delete) func - psByRole = new PSInfo(trans, SELECT_SP + helper[FIELD_COMMAS] + " FROM user_role WHERE role = ? ALLOW FILTERING", + psByRole = new PSInfo(trans, SELECT_SP + helper[FIELD_COMMAS] + " FROM user_role WHERE role = ? ALLOW FILTERING", new URLoader(1) { @Override protected void key(Data data, int idx, Object[] obj) { obj[idx]=data.role; } },readConsistency); - + psUserInRole = new PSInfo(trans,SELECT_SP + helper[FIELD_COMMAS] + " FROM user_role WHERE user = ? AND role = ?", URLoader.deflt,readConsistency); } @@ -243,7 +243,7 @@ public class UserRoleDAO extends CassDAOImpl<AuthzTrans,UserRoleDAO.Data> { public Result<List<Data>> readByRole(AuthzTrans trans, String role) { return psByRole.read(trans, R_TEXT + " by Role " + role, new Object[]{role}); } - + /** * Direct Lookup of User Role * Don't forget to check for Expiration @@ -266,7 +266,7 @@ public class UserRoleDAO extends CassDAOImpl<AuthzTrans,UserRoleDAO.Data> { HistoryDAO.Data hd = HistoryDAO.newInitedData(); HistoryDAO.Data hdRole = HistoryDAO.newInitedData(); - + hd.user = hdRole.user = trans.user(); hd.action = modified.name(); // Modifying User/Role is an Update to Role, not a Create. Jonathan, 07-14-2015 @@ -276,17 +276,17 @@ public class UserRoleDAO extends CassDAOImpl<AuthzTrans,UserRoleDAO.Data> { hd.subject = subject?override[1] : (data.user + '|'+data.role); hdRole.subject = data.role; switch(modified) { - case create: + case create: hd.memo = hdRole.memo = memo ? String.format("%s by %s", override[0], hd.user) - : String.format("%s added to %s",data.user,data.role); + : String.format("%s added to %s",data.user,data.role); break; - case update: + case update: hd.memo = hdRole.memo = memo ? String.format("%s by %s", override[0], hd.user) : String.format("%s - %s was updated",data.user,data.role); break; - case delete: + case delete: hd.memo = hdRole.memo = memo ? String.format("%s by %s", override[0], hd.user) : String.format("%s removed from %s",data.user,data.role); @@ -305,7 +305,7 @@ public class UserRoleDAO extends CassDAOImpl<AuthzTrans,UserRoleDAO.Data> { if (historyDAO.create(trans, hd).status!=Status.OK) { trans.error().log("Cannot log to History"); } - + if (historyDAO.create(trans, hdRole).status!=Status.OK) { trans.error().log("Cannot log to History"); } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/CassExecutor.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/CassExecutor.java index a92de21c..27a18821 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/CassExecutor.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/CassExecutor.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. diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Function.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Function.java index dd367c51..d8096188 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Function.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Function.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. @@ -64,17 +64,17 @@ public class Function { public enum FUTURE_OP { C("Create"),U("Update"),D("Delete"),G("Grant"),UG("UnGrant"),A("Approval"); - + private String desc; - + private FUTURE_OP(String desc) { this.desc = desc; } - + public String desc() { return desc; } - + /** * Same as valueOf(), but passes back null instead of throwing Exception * @param value @@ -94,7 +94,7 @@ public class Function { public enum OP_STATUS { E("Executed"),D("Denied"),P("Pending"),L("Lapsed"); - + private String desc; public final static Result<OP_STATUS> RE = Result.ok(OP_STATUS.E); public final static Result<OP_STATUS> RD = Result.ok(OP_STATUS.D); @@ -104,11 +104,11 @@ public class Function { private OP_STATUS(String desc) { this.desc = desc; } - + public String desc() { return desc; } - + } public static final String FOP_CRED = "cred"; @@ -159,16 +159,16 @@ public class Function { /** * createNS - * + * * Create Namespace - * + * * @param trans * @param org * @param ns * @param user * @return * @throws DAOException - * + * * To create an NS, you need to: 1) validate permission to * modify parent NS 2) Does NS exist already? 3) Create NS with * a) "user" as owner. NOTE: Per 10-15 request for AAF 1.0 4) @@ -185,7 +185,7 @@ public class Function { Identity orgUser = org.getIdentity(trans, u); String reason; if (orgUser == null) { - return Result.err(Status.ERR_Policy,"%s is not a valid user at %s",u,org.getName()); + return Result.err(Status.ERR_Policy,"%s is not a valid user at %s",u,org.getName()); } else if ((reason=orgUser.mayOwn())!=null) { if (org.isTestEnv()) { String reason2; @@ -242,7 +242,7 @@ public class Function { return Result.err(Status.ERR_ConflictAlreadyExists, "Target Namespace already exists"); } - + // 2.1) Does role exist with that name if(cname!=null && q.roleDAO().read(trans, parent, cname).isOKhasData()) { return Result.err(Status.ERR_ConflictAlreadyExists, @@ -347,7 +347,7 @@ public class Function { trans.error().log(rpdd.errorString()); } } - + // Save off Old keys String delP1 = rdd.ns; String delP2 = rdd.name; @@ -356,7 +356,7 @@ public class Function { rdd.ns = namespace.name; rdd.name = (delP2.length() > targetNameDot) ? delP2 .substring(targetNameDot) : ""; - + // Need to use non-cached, because switching namespaces, not // "create" per se if ((rq = q.roleDAO().create(trans, rdd)).isOK()) { @@ -364,7 +364,7 @@ public class Function { for (PermDAO.Data pdd : lpdd) { q.permDAO().addRole(trans, pdd, rdd); } - // Change data for User Roles + // Change data for User Roles Result<List<UserRoleDAO.Data>> rurd = q.userRoleDAO().readByRole(trans, rdd.fullName()); if (rurd.isOKhasData()) { for (UserRoleDAO.Data urd : rurd.value) { @@ -391,7 +391,7 @@ public class Function { for (PermDAO.Data pdd : rpdc.value) { // Remove old Perm from Roles, save them off List<RoleDAO.Data> lrdd = new ArrayList<>(); - + for (String rl : pdd.roles(false)) { Result<RoleDAO.Data> rrdd = RoleDAO.Data.decode(trans,q,rl); if (rrdd.isOKhasData()) { @@ -402,7 +402,7 @@ public class Function { trans.error().log(rrdd.errorString()); } } - + // Save off Old keys String delP1 = pdd.ns; String delP2 = pdd.type; @@ -481,9 +481,9 @@ public class Function { /** * deleteNS - * + * * Delete Namespace - * + * * @param trans * @param org * @param ns @@ -491,8 +491,8 @@ public class Function { * @param user * @return * @throws DAOException - * - * + * + * * To delete an NS, you need to: 1) validate permission to * modify this NS 2) Find all Roles with this NS, and 2a) if * Force, delete them, else modify to Parent NS 3) Find all @@ -723,7 +723,7 @@ public class Function { if (rq.notOK()) { return Result.err(rq); } - + rq = q.mayUser(trans, trans.user(), rq.value, Access.write); if (rq.notOK()) { Result<List<UserRoleDAO.Data>> ruinr = q.userRoleDAO().readUserInRole(trans, trans.user(),ns+".owner"); @@ -757,7 +757,7 @@ public class Function { return Result.err(Status.ERR_Security, "%s is not a valid AAF Credential", user); } - + for (CredDAO.Data cd : cdr.value) { if (cd.expires.after(now)) { return Result.ok(); @@ -792,7 +792,7 @@ public class Function { } rq = q.mayUser(trans, trans.user(), rq.value, Access.write); - if (rq.notOK()) { + if (rq.notOK()) { // Even though not a "writer", Owners still determine who gets to be an Admin Result<List<UserRoleDAO.Data>> ruinr = q.userRoleDAO().readUserInRole(trans, trans.user(),ns+".owner"); if (!(ruinr.isOKhasData() && ruinr.value.get(0).expires.after(new Date()))) { @@ -806,7 +806,7 @@ public class Function { /** * Helper function that moves permissions from a namespace being deleted to * its parent namespace - * + * * @param trans * @param parent * @param sb @@ -827,7 +827,7 @@ public class Function { } // Remove old Perm from Roles, save them off List<RoleDAO.Data> lrdd = new ArrayList<>(); - + for (String rl : pdd.roles(false)) { Result<RoleDAO.Data> rrdd = RoleDAO.Data.decode(trans,q,rl); if (rrdd.isOKhasData()) { @@ -838,7 +838,7 @@ public class Function { trans.error().log(rrdd.errorString()); } } - + // Save off Old keys String delP1 = pdd.ns; NsSplit nss = new NsSplit(parent, pdd.fullType()); @@ -872,7 +872,7 @@ public class Function { /** * Helper function that moves roles from a namespace being deleted to its * parent namespace - * + * * @param trans * @param parent * @param sb @@ -903,7 +903,7 @@ public class Function { trans.error().log(rpdd.errorString()); } } - + // Save off Old keys String delP1 = rdd.ns; @@ -938,9 +938,9 @@ public class Function { /** * Create Permission (and any missing Permission between this and Parent) if * we have permission - * + * * Pass in the desired Management Permission for this Permission - * + * * If Force is set, then Roles listed will be created, if allowed, * pre-granted. */ @@ -1008,7 +1008,7 @@ public class Function { Result<PermDAO.Data> pdr = q.permDAO().create(trans, perm); if (pdr.isOK()) { return Result.ok(); - } else { + } else { return Result.err(pdr); } } @@ -1118,10 +1118,10 @@ public class Function { /** * Only owner of Permission may add to Role - * + * * If force set, however, Role will be created before Grant, if User is * allowed to create. - * + * * @param trans * @param role * @param pd @@ -1129,7 +1129,7 @@ public class Function { */ public Result<Void> addPermToRole(AuthzTrans trans, RoleDAO.Data role,PermDAO.Data pd, boolean fromApproval) { String user = trans.user(); - + if (!fromApproval) { Result<NsDAO.Data> rRoleCo = q.deriveFirstNsForType(trans, role.ns, NsType.COMPANY); if (rRoleCo.notOK()) { @@ -1148,14 +1148,14 @@ public class Function { return Result.err(r); } } - + // Must be Perm Admin, or Granted Special Permission Result<NsDAO.Data> ucp = q.mayUser(trans, user, pd, Access.write); if (ucp.notOK()) { // Don't allow CLI potential Grantees to change their own AAF // Perms, - if ((ROOT_NS.equals(pd.ns) && Question.NS.equals(pd.type)) + if ((ROOT_NS.equals(pd.ns) && Question.NS.equals(pd.type)) || !q.isGranted(trans, trans.user(),ROOT_NS,Question.PERM, rPermCo.value.name, "grant")) { // Not otherwise granted // TODO Needed? @@ -1233,7 +1233,7 @@ public class Function { /** * Either Owner of Role or Permission may delete from Role - * + * * @param trans * @param role * @param pd @@ -1332,10 +1332,10 @@ public class Function { /** * Add a User to Role - * + * * 1) Role must exist 2) User must be a known Credential (i.e. mechID ok if * Credential) or known Organizational User - * + * * @param trans * @param org * @param urData @@ -1352,9 +1352,9 @@ public class Function { rv = checkValidID(trans, new Date(), urData.user); } if (rv.notOK()) { - return rv; + return rv; } - + // Check if record exists if (q.userRoleDAO().read(trans, urData).isOKhasData()) { return Result.err(Status.ERR_ConflictAlreadyExists, @@ -1366,8 +1366,8 @@ public class Function { } urData.expires = trans.org().expiration(null, Expiration.UserInRole, urData.user).getTime(); - - + + Result<UserRoleDAO.Data> udr = q.userRoleDAO().create(trans, urData); if (udr.status == OK) { return Result.ok(); @@ -1392,9 +1392,9 @@ public class Function { /** * Extend User Role. - * + * * extend the Expiration data, according to Organization rules. - * + * * @param trans * @param org * @param urData @@ -1406,7 +1406,7 @@ public class Function { return Result.err(Status.ERR_UserRoleNotFound, "User Role does not exist"); } - + if (q.roleDAO().read(trans, urData.ns, urData.rname).notOKorIsEmpty()) { return Result.err(Status.ERR_RoleNotFound, "Role [%s.%s] does not exist", urData.ns,urData.rname); @@ -1485,13 +1485,13 @@ public class Function { } } } - + if (owners.isEmpty()) { return Result.err(Result.ERR_NotFound,"No Owners found for " + nsd.name); } - + // Create Future Object - + Result<FutureDAO.Data> fr = q.futureDAO().create(trans, data, id); if (fr.isOK()) { sb.append("Created Future: "); @@ -1518,7 +1518,7 @@ public class Function { } catch (Exception e) { return Result.err(e); } - + return Result.ok(sb.toString()); } @@ -1528,7 +1528,7 @@ public class Function { public interface Lookup<T> { T get(AuthzTrans trans, Object ... keys); } - + public Lookup<UserRoleDAO.Data> urDBLookup = new Lookup<UserRoleDAO.Data>() { @Override public UserRoleDAO.Data get(AuthzTrans trans, Object ... keys) { @@ -1542,11 +1542,11 @@ public class Function { }; /** - * Note: if "allApprovals for Ticket is null, it will be looked up. + * Note: if "allApprovals for Ticket is null, it will be looked up. * if "fdd" is null, it will be looked up, but - * + * * They can be passed for performance reasons. - * + * * @param trans * @param cd * @param allApprovalsForTicket @@ -1575,7 +1575,7 @@ public class Function { return Result.err(Result.ERR_BadData,"Cannot reconstitute %1",curr.memo); } } - + boolean aDenial = false; int cntSuper=0, appSuper=0,cntOwner=0, appOwner=0; for (ApprovalDAO.Data add : la.get(trans)) { @@ -1603,7 +1603,7 @@ public class Function { break; } } - + Result<OP_STATUS> ros=null; if (aDenial) { ros = OP_STATUS.RD; @@ -1624,7 +1624,7 @@ public class Function { } } } - + // Decision: If not Denied, and at least owner, if exists, and at least one Super, if exists boolean goDecision = (cntOwner>0?appOwner>0:true) && (cntSuper>0?appSuper>0:true); @@ -1720,7 +1720,7 @@ public class Function { if (fop == FUTURE_OP.C) { ros = set(OP_STATUS.RE, q.credDAO().dao().create(trans, data)); } - } + } } catch (Exception e) { trans.error().log("Exception: ", e.getMessage(), " \n occurred while performing", curr.memo, @@ -1732,7 +1732,7 @@ public class Function { //return Result.err(Status.ACC_Future, "Full Approvals not obtained: No action taken"); ros = OP_STATUS.RP; } - + return ros; } @@ -1745,7 +1745,7 @@ public class Function { } } - private Result<ApprovalDAO.Data> addIdentity(AuthzTrans trans, StringBuilder sb, + private Result<ApprovalDAO.Data> addIdentity(AuthzTrans trans, StringBuilder sb, Boolean[] first, String user, String memo, FUTURE_OP op, Identity u, UUID ticket, String type) throws OrganizationException { ApprovalDAO.Data ad = new ApprovalDAO.Data(); // Note ad.id is set by ApprovalDAO Create diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/PermLookup.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/PermLookup.java index 3f0e92e7..5a27e5ec 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/PermLookup.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/PermLookup.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. @@ -38,9 +38,9 @@ import org.onap.aaf.auth.env.AuthzTrans; import org.onap.aaf.auth.layer.Result; /** - * PermLookup is a Storage class for the various pieces of looking up Permission + * PermLookup is a Storage class for the various pieces of looking up Permission * during Transactions to avoid duplicate processing - * + * * @author Jonathan * */ @@ -53,9 +53,9 @@ public class PermLookup { private Result<List<RoleDAO.Data>> roles = null; private Result<Set<String>> permNames = null; private Result<List<PermDAO.Data>> perms = null; - + private PermLookup() {} - + public static PermLookup get(AuthzTrans trans, Question q, String user) { PermLookup lp=null; Map<String, PermLookup> permMap = trans.get(Question.PERMS, null); @@ -74,7 +74,7 @@ public class PermLookup { } return lp; } - + public Result<List<UserRoleDAO.Data>> getUserRoles() { if (userRoles==null) { userRoles = q.userRoleDAO().readByUser(trans,user); @@ -143,7 +143,7 @@ public class PermLookup { return permNames; } } - + public Result<List<PermDAO.Data>> getPerms(boolean lookup) { if (perms==null) { // Note: It should be ok for a Valid user to have no permissions - @@ -156,7 +156,7 @@ public class PermLookup { Map<String,PermDAO.Data> mspdd = new TreeMap<>(); Result<String[]> ap = PermDAO.Data.decodeToArray(trans, q, perm); if (ap.isOK()) { - + Result<List<PermDAO.Data>> rlpd = q.permDAO().read(perm,trans,ap.value); if (rlpd.isOKhasData()) { for (PermDAO.Data pData : rlpd.value) { @@ -174,7 +174,7 @@ public class PermLookup { pdd.description = pData.description; lpdd.add(pdd); } - pdd.roles(true).add(pdr); + pdd.roles(true).add(pdr); break; } } diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java index c7ee5938..1809686a 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/hl/Question.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. @@ -81,9 +81,9 @@ import com.datastax.driver.core.Cluster; /** * Question HL DAO - * + * * A Data Access Combination Object which asks Security and other Questions - * + * * @author Jonathan * */ @@ -135,57 +135,57 @@ public class Question { public HistoryDAO historyDAO() { return historyDAO; } - + private final CachedNSDAO nsDAO; public CachedNSDAO nsDAO() { return nsDAO; } - + private final CachedRoleDAO roleDAO; public CachedRoleDAO roleDAO() { return roleDAO; } - + private final CachedPermDAO permDAO; public CachedPermDAO permDAO() { return permDAO; } - + private final CachedUserRoleDAO userRoleDAO; public CachedUserRoleDAO userRoleDAO() { return userRoleDAO; } - + private final CachedCredDAO credDAO; public CachedCredDAO credDAO() { return credDAO; } - + private final CachedCertDAO certDAO; public CachedCertDAO certDAO() { return certDAO; } - + private final DelegateDAO delegateDAO; public DelegateDAO delegateDAO() { return delegateDAO; } - + private final FutureDAO futureDAO; public FutureDAO futureDAO() { return futureDAO; } - + private final ApprovalDAO approvalDAO; public ApprovalDAO approvalDAO() { return approvalDAO; } - + public final LocateDAO locateDAO; public LocateDAO locateDAO() { return locateDAO; } - + private final CacheInfoDAO cacheInfoDAO; private final int cldays; private final boolean alwaysSpecial; @@ -216,18 +216,18 @@ public class Question { if (specialLogSlot==null) { specialLogSlot = trans.slot(AuthzTransFilter.SPECIAL_LOG_SLOT); } - + if (transIDSlot==null) { transIDSlot = trans.slot(AuthzTransFilter.TRANS_ID_SLOT); } - + AbsCassDAO.primePSIs(trans); - + cldays = Integer.parseInt(trans.getProperty(Config.AAF_CRED_WARN_DAYS, Config.AAF_CRED_WARN_DAYS_DFT)); - + alwaysSpecial = Boolean.parseBoolean(trans.getProperty("aaf_always_special", Boolean.FALSE.toString())); } - + /** * Note: This Constructor created for JUNIT Purposes. Do not use otherwise. */ @@ -259,7 +259,7 @@ public class Question { CachedDAO.startCleansing(env, credDAO, userRoleDAO); CachedDAO.startRefresh(env, cacheInfoDAO); } - + public void close(AuthzTrans trans) { historyDAO.close(trans); cacheInfoDAO.close(trans); @@ -283,7 +283,7 @@ public class Question { pdd.type = type.substring(colon+1); pdd.instance = instance; pdd.action = action; - + return Result.ok(pdd); } else { return Result.err(Result.ERR_BadData,"Could not extract ns and type from " + type); @@ -301,10 +301,10 @@ public class Question { /** * getPermsByUser - * + * * Because this call is frequently called internally, AND because we already * look for it in the initial Call, we cache within the Transaction - * + * * @param trans * @param user * @return @@ -312,26 +312,26 @@ public class Question { public Result<List<PermDAO.Data>> getPermsByUser(AuthzTrans trans, String user, boolean lookup) { return PermLookup.get(trans, this, user).getPerms(lookup); } - + public Result<List<PermDAO.Data>> getPermsByUserFromRolesFilter(AuthzTrans trans, String user, String forUser) { PermLookup plUser = PermLookup.get(trans, this, user); Result<Set<String>> plPermNames = plUser.getPermNames(); if (plPermNames.notOK()) { return Result.err(plPermNames); } - + Set<String> nss; if (forUser.equals(user)) { nss = null; } else { - // Setup a TreeSet to check on Namespaces to + // Setup a TreeSet to check on Namespaces to nss = new TreeSet<>(); PermLookup fUser = PermLookup.get(trans, this, forUser); Result<Set<String>> forUpn = fUser.getPermNames(); if (forUpn.notOK()) { return Result.err(forUpn); } - + for (String pn : forUpn.value) { Result<String[]> decoded = PermDAO.Data.decodeToArray(trans, this, pn); if (decoded.isOKhasData()) { @@ -356,7 +356,7 @@ public class Question { trans.error().log(pn,", derived from a Role, is invalid. Run Data Cleanup:",rpdd.errorString()); } } - return Result.ok(rlpUser); + return Result.ok(rlpUser); } public Result<List<PermDAO.Data>> getPermsByType(AuthzTrans trans, String type) { @@ -389,7 +389,7 @@ public class Question { if (nss.notOK()) { return Result.err(nss); } - + return permDAO.read(trans, nss.value.ns, nss.value.name, instance,action); } } @@ -462,22 +462,22 @@ public class Question { /** * Derive NS - * + * * Given a Child Namespace, figure out what the best Namespace parent is. - * + * * For instance, if in the NS table, the parent "org.osaaf" exists, but not * "org.osaaf.child" or "org.osaaf.a.b.c", then passing in either * "org.osaaf.child" or "org.osaaf.a.b.c" will return "org.osaaf" - * + * * Uses recursive search on Cached DAO data - * + * * @param trans * @param child * @return */ public Result<NsDAO.Data> deriveNs(AuthzTrans trans, String child) { Result<List<NsDAO.Data>> r = nsDAO.read(trans, child); - + if (r.isOKhasData()) { return Result.ok(r.value.get(0)); } else { @@ -502,7 +502,7 @@ public class Question { return Result.ok(nsd); } else { int dot = str.lastIndexOf('.'); - + if (dot < 0) { return Result.err(Status.ERR_NsNotFound, "No Namespace for [%s]", str); } else { @@ -511,7 +511,7 @@ public class Question { } } else { int dot = str.lastIndexOf('.'); - + if (dot < 0) { return Result.err(Status.ERR_NsNotFound,"There is no valid Company Namespace for %s",str); } else { @@ -539,9 +539,9 @@ public class Question { /** * Translate an ID into it's domain - * + * * i.e. myid1234@aaf.att.com results in domain of com.att.aaf - * + * * @param id * @return */ @@ -568,9 +568,9 @@ public class Question { /** * Validate Namespace of ID@Domain - * + * * Namespace is reverse order of Domain. - * + * * @param trans * @param id * @return @@ -584,7 +584,7 @@ public class Question { ns = domain2ns(id); } if (ns.length() > 0) { - if (!trans.org().getDomain().equals(ns)) { + if (!trans.org().getDomain().equals(ns)) { Result<List<NsDAO.Data>> rlnsd = nsDAO.read(trans, ns); if (rlnsd.isOKhasData()) { return Result.ok(rlnsd.value.get(0)); @@ -611,7 +611,7 @@ public class Question { ns = ns.substring(0, last); } } while (last >= 0); - + // SAFETY - Do not allow these when NS is Root if(!isRoot) { // com.att.aaf.ns|:<client ns>:ns|<access> @@ -681,7 +681,7 @@ public class Question { // Check if Access to Whole NS // AAF-724 - Make consistent response for May User", and not take the // last check... too confusing. - Result<org.onap.aaf.auth.dao.cass.NsDAO.Data> rv = mayUserVirtueOfNS(trans, user, ndd, + Result<org.onap.aaf.auth.dao.cass.NsDAO.Data> rv = mayUserVirtueOfNS(trans, user, ndd, ":" + rdd.ns + ":ns", access.name()); if (rv.isOK()) { return rv; @@ -717,7 +717,7 @@ public class Question { if (isGranted(trans, user, pdd.ns, pdd.type, pdd.instance, pdd.action)) { return Result.ok(ndd); } - + String permInst = ":perm:" + pdd.type + ':' + pdd.instance + ':' + pdd.action; // <ns>.access|:role:<role name>|<read|write> String ns = ndd.name; @@ -795,7 +795,7 @@ public class Question { break; case read: case write: - if (!isUser && !isDelegate && + if (!isUser && !isDelegate && !isGranted(trans, trans.user(), ROOT_NS,DELG,org.getDomain(), access.name())) { return Result.err(Status.ERR_Denied, "[%s] may not %s delegates for [%s]", trans.user(), @@ -818,14 +818,14 @@ public class Question { String ns = nsd.name; // If an ADMIN of the Namespace, then allow - + Result<List<UserRoleDAO.Data>> rurd; if ((rurd = userRoleDAO.readUserInRole(trans, user, ns+DOT_ADMIN)).isOKhasData()) { return Result.ok(nsd); } else if (rurd.status==Result.ERR_Backend) { return Result.err(rurd); } - + // If Specially granted Global Permission if (isGranted(trans, user, ROOT_NS,NS, ns_and_type, access)) { return Result.ok(nsd); @@ -851,13 +851,13 @@ public class Question { ns_and_type); } - + /** * isGranted - * + * * Important function - Check internal Permission Schemes for Permission to * do things - * + * * @param trans * @param type * @param instance @@ -871,7 +871,7 @@ public class Question { if (ns.equals(pd.ns)) { if (type.equals(pd.type)) { if (PermEval.evalInstance(pd.instance, instance)) { - if (PermEval.evalAction(pd.action, action)) { // don't return action here, might miss other action + if (PermEval.evalAction(pd.action, action)) { // don't return action here, might miss other action return true; } } @@ -900,32 +900,32 @@ public class Question { } } else { Date now = new Date(); - // Bug noticed 6/22. Sorting on the result can cause Concurrency Issues. + // Bug noticed 6/22. Sorting on the result can cause Concurrency Issues. // 9/14/2019. Use TreeSet for sorting, and using only the LAST of a Tagged entry Collection<CredDAO.Data> cddl; if (result.value.size() > 1) { - Map<String,CredDAO.Data> mcdd = new TreeMap<>(); - CredDAO.Data cdd; - String tag; - int pseudoTag = 0; + Map<String,CredDAO.Data> mcdd = new TreeMap<>(); + CredDAO.Data cdd; + String tag; + int pseudoTag = 0; for (CredDAO.Data rcdd : result.value) { if (rcdd.type==CredDAO.BASIC_AUTH || rcdd.type==CredDAO.BASIC_AUTH_SHA256) { - if(rcdd.tag==null) { - mcdd.put(Integer.toString(++pseudoTag),rcdd); - } else { - tag = rcdd.tag; - cdd = mcdd.get(tag); - if(cdd==null || cdd.expires.before(rcdd.expires)) { - mcdd.put(tag,rcdd); - } - } + if(rcdd.tag==null) { + mcdd.put(Integer.toString(++pseudoTag),rcdd); + } else { + tag = rcdd.tag; + cdd = mcdd.get(tag); + if(cdd==null || cdd.expires.before(rcdd.expires)) { + mcdd.put(tag,rcdd); + } + } } } cddl = mcdd.values(); } else { cddl = result.value; } - + Date expired = null; StringBuilder debug = willSpecialLog(trans,user)?new StringBuilder():null; for (CredDAO.Data cdd : cddl) { @@ -934,7 +934,7 @@ public class Question { } if (cdd.expires.after(now)) { byte[] dbcred = cdd.cred.array(); - + try { switch(cdd.type) { case CredDAO.BASIC_AUTH: @@ -952,7 +952,7 @@ public class Question { bb.putInt(cdd.other); bb.put(cred); byte[] hash = Hash.hashSHA256(bb.array()); - + if (Hash.compareTo(hash,dbcred)==0) { checkLessThanDays(trans,cldays,now,cdd); trans.setTag(cdd.tag); @@ -974,7 +974,7 @@ public class Question { } } } // end for each - + if (expired!=null) { // Note: this is only returned if there are no good Credentials rv = Result.err(Status.ERR_Security, @@ -1015,7 +1015,7 @@ public class Question { if (cexp<close) { int daysLeft = days-(int)((close-cexp)/86400000); trans.audit().printf("user=%s,ip=%s,expires=%s,days=%d,tag=%s,msg=\"Password expires in less than %d day%s\"", - cdd.id,trans.ip(),Chrono.dateOnlyStamp(cdd.expires),daysLeft, cdd.tag, + cdd.id,trans.ip(),Chrono.dateOnlyStamp(cdd.expires),daysLeft, cdd.tag, daysLeft,daysLeft==1?"":"s"); } } @@ -1038,14 +1038,14 @@ public class Question { } finally { tt.done(); } - + } else if (cred.type==CredDAO.FQI) { cred.cred = null; return Result.ok(cred); } return Result.err(Status.ERR_Security,"invalid/unreadable credential"); } - + public Result<Boolean> userCredCheck(AuthzTrans trans, CredDAO.Data orig, final byte[] raw) { Result<Boolean> rv; TimeTaken tt = trans.start("CheckCred Cred", Env.SUB); @@ -1205,7 +1205,7 @@ public class Question { } return b; } - + public static void logEncryptTrace(AuthzTrans trans, String data) { long ti; trans.put(transIDSlot, ti=nextTraceID()); @@ -1222,7 +1222,7 @@ public class Question { } boolean rc = specialLog.add(id); if (rc) { - trans.trace().printf("Trace on for %s requested by %s",id,trans.user()); + trans.trace().printf("Trace on for %s requested by %s",id,trans.user()); } return rc; } @@ -1236,12 +1236,12 @@ public class Question { specialLog = null; } if (rv) { - trans.trace().printf("Trace off for %s requested by %s",id,trans.user()); + trans.trace().printf("Trace off for %s requested by %s",id,trans.user()); } return rv; } - /** + /** * canMove * Which Types can be moved * @param nsType @@ -1274,7 +1274,7 @@ public class Question { }; return false; } - + public boolean isOwner(AuthzTrans trans, String user, String ns) { Result<List<UserRoleDAO.Data>> rur = userRoleDAO().read(trans, user,ns+DOT_OWNER); if (rur.isOKhasData()) {for (UserRoleDAO.Data urdd : rur.value){ @@ -1297,14 +1297,14 @@ public class Question { }}; return count; } - + /** * Return a Unique String, (same string, if it is already unique), with only * lowercase letters, digits and the '.' character. - * + * * @param name * @return - * @throws IOException + * @throws IOException */ public static String toUnique(String name) throws IOException { byte[] from = name.getBytes(); @@ -1317,7 +1317,7 @@ public class Question { } return sb.toString(); } - + public static String fromUnique(String name) throws IOException { byte[] from = name.getBytes(); StringBuilder sb = new StringBuilder(); diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFLocator.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFLocator.java index bd297e7d..f8362553 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFLocator.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFLocator.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. @@ -50,18 +50,18 @@ public class DirectAAFLocator extends AbsAAFLocator<AuthzTrans> { private final URI uri; /** - * + * * @param env * @param ldao * @param key must be one or more of service, version, other in that order - * @throws LocatorException + * @throws LocatorException */ public DirectAAFLocator(AuthzEnv env, LocateDAO ldao, String name, String version) throws LocatorException { - super(env.access(), name, 1000L /* Don't hit DB more than once a second */); + super(env.access(), name, 1000L /* Don't hit DB more than once a second */); this.env = env; this.ldao = ldao; if (version!=null) { - try { + try { String[] v = Split.split('.',version); if (v.length>0) {major = Integer.parseInt(v[0]);} if (v.length>1) {minor = Integer.parseInt(v[1]);} @@ -71,7 +71,7 @@ public class DirectAAFLocator extends AbsAAFLocator<AuthzTrans> { throw new LocatorException("Invalid Version String: " + version); } } - + try { String aaf_url; if(name.indexOf('.')>=0) { @@ -87,10 +87,10 @@ public class DirectAAFLocator extends AbsAAFLocator<AuthzTrans> { throw new LocatorException(e); } myhostname=null; - myport = 0; + myport = 0; } - - + + @Override public boolean refresh() { AuthzTrans trans = env.newTransNoAvg(); @@ -119,7 +119,7 @@ public class DirectAAFLocator extends AbsAAFLocator<AuthzTrans> { for (String s : d.subprotocol(false)) { endpoint.getSubprotocol().add(s); } - + try { epl.add(new EP(endpoint,latitude,longitude)); } catch (URISyntaxException e) { diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFLur.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFLur.java index 59613961..2ccbd236 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFLur.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFLur.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. @@ -44,7 +44,7 @@ import org.onap.aaf.misc.env.util.Split; public class DirectAAFLur implements Lur { private final AuthzEnv env; private final Question question; - + public DirectAAFLur(AuthzEnv env, Question question/*, TokenMgr tm*/) { this.env = env; this.question = question; @@ -55,7 +55,7 @@ public class DirectAAFLur implements Lur { public boolean fish(Principal bait, Permission ... pond) { return fish(env.newTransNoAvg(),bait,pond); } - + public boolean fish(AuthzTrans trans, Principal bait, Permission ... pond) { boolean rv = false; Result<List<Data>> pdr = question.getPermsByUser(trans, bait.getName(),false); @@ -94,7 +94,7 @@ public class DirectAAFLur implements Lur { env.error().log("Can't access Cassandra to fulfill Permission Query: ",pdr.status,"-", pdr.details); } } - + @Override public void destroy() { } @@ -103,7 +103,7 @@ public class DirectAAFLur implements Lur { public boolean handlesExclusively(Permission ... pond) { return false; } - + /** * Small Class implementing CADI's Permission with Cassandra Data * @author Jonathan @@ -111,15 +111,15 @@ public class DirectAAFLur implements Lur { */ public static class PermPermission implements Permission { private PermDAO.Data data; - + public PermPermission(PermDAO.Data d) { data = d; } - + public PermPermission(AuthzTrans trans, Question q, String p) { data = PermDAO.Data.create(trans, q, p); } - + public PermPermission(String ns, String type, String instance, String action) { data = new PermDAO.Data(); data.ns = ns; @@ -161,12 +161,12 @@ public class DirectAAFLur implements Lur { public String permType() { return "AAFLUR"; } - + } - + public String toString() { return "DirectAAFLur is enabled"; - + } /* (non-Javadoc) diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFUserPass.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFUserPass.java index bdeb77f3..f5b7779b 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFUserPass.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectAAFUserPass.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. @@ -37,14 +37,14 @@ import org.onap.aaf.cadi.CredVal; /** * DirectAAFUserPass is intended to provide password Validation directly from Cassandra Database, and is only * intended for use in AAF itself. The normal "AAF Taf" objects are, of course, clients. - * + * * @author Jonathan * */ public class DirectAAFUserPass implements CredVal { private final AuthzEnv env; private final Question question; - + public DirectAAFUserPass(AuthzEnv env, Question question) { this.env = env; this.question = question; @@ -55,7 +55,7 @@ public class DirectAAFUserPass implements CredVal { if(user==null || type==null || pass==null) { return false; } - + try { AuthzTrans trans; boolean transfer = false; diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectCertIdentity.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectCertIdentity.java index f3351dae..d78ddcaa 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectCertIdentity.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectCertIdentity.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. @@ -40,10 +40,10 @@ import org.onap.aaf.cadi.taf.cert.X509Taf; /** * Direct view of CertIdentities - * - * Warning: this class is difficult to instantiate. The only service that can use it is AAF itself, and is thus + * + * Warning: this class is difficult to instantiate. The only service that can use it is AAF itself, and is thus * entered in the "init" after the CachedCertDAO is created. - * + * * @author Jonathan * */ @@ -62,7 +62,7 @@ public class DirectCertIdentity implements CertIdentity { byte[] fingerprint = X509Taf.getFingerPrint(certBytes); AuthzTrans trans = (AuthzTrans) req.getAttribute(TransFilter.TRANS_TAG); - + Result<List<Data>> cresp = certDAO.read(trans, ByteBuffer.wrap(fingerprint)); if (cresp.isOKhasData()) { Data cdata = cresp.value.get(0); diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectLocatorCreator.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectLocatorCreator.java index aa6bf8c5..2ea6830c 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectLocatorCreator.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectLocatorCreator.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. @@ -31,12 +31,12 @@ public class DirectLocatorCreator implements AbsAAFLocator.LocatorCreator { private final LocateDAO locateDAO; private String myhostname; private int myport; - + public DirectLocatorCreator(AuthzEnv env, LocateDAO locateDAO) { this.env = env; this.locateDAO = locateDAO; } - + @Override public AbsAAFLocator<?> create(String key, String version) throws LocatorException { DirectAAFLocator dal = new DirectAAFLocator(env,locateDAO,key,version); @@ -45,7 +45,7 @@ public class DirectLocatorCreator implements AbsAAFLocator.LocatorCreator { } return dal; } - + /** * Make sure DirectAAFLocator created does not include self. * @param hostname diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectRegistrar.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectRegistrar.java index ce9d5930..75830863 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectRegistrar.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/direct/DirectRegistrar.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. @@ -39,7 +39,7 @@ import locate.v1_0.MgmtEndpoints; public class DirectRegistrar implements Registrant<AuthzEnv> { private LocateDAO ldao; - private List<LocateDAO.Data> ldd; + private List<LocateDAO.Data> ldd; public DirectRegistrar(Access access, LocateDAO ldao, int port) throws CadiException { this.ldao = ldao; ldd = new ArrayList<>(); @@ -70,7 +70,7 @@ public class DirectRegistrar implements Registrant<AuthzEnv> { @Override public Result<Void> update(AuthzEnv env) { - AuthzTrans trans = env.newTransNoAvg(); + AuthzTrans trans = env.newTransNoAvg(); StringBuilder sb = null; for(LocateDAO.Data ld : ldd) { org.onap.aaf.auth.layer.Result<Void> dr = ldao.update(trans, ld); @@ -83,7 +83,7 @@ public class DirectRegistrar implements Registrant<AuthzEnv> { } } } - + if(sb==null) { return Result.ok(200, null); } else { @@ -96,7 +96,7 @@ public class DirectRegistrar implements Registrant<AuthzEnv> { */ @Override public Result<Void> cancel(AuthzEnv env) { - AuthzTrans trans = env.newTransNoAvg(); + AuthzTrans trans = env.newTransNoAvg(); StringBuilder sb = null; for(LocateDAO.Data ld : ldd) { org.onap.aaf.auth.layer.Result<Void> dr = ldao.delete(trans, ld, false); @@ -109,7 +109,7 @@ public class DirectRegistrar implements Registrant<AuthzEnv> { } } } - + if(sb==null) { return Result.ok(200, null); } else { |