From 1296352d8eafee57f982a4342ad79ada4aa56d28 Mon Sep 17 00:00:00 2001 From: Instrumental Date: Tue, 15 Oct 2019 08:19:50 -0500 Subject: Sonar Fixes, Formatting Issue-ID: AAF-1019 Change-Id: Ica49d9e7323aad9622ff9d95cc21b87430c22c54 Signed-off-by: Instrumental --- .../java/org/onap/aaf/auth/dao/AbsCassDAO.java | 86 ++++----- .../java/org/onap/aaf/auth/dao/Bytification.java | 4 +- .../src/main/java/org/onap/aaf/auth/dao/CIDAO.java | 10 +- .../main/java/org/onap/aaf/auth/dao/Cacheable.java | 8 +- .../main/java/org/onap/aaf/auth/dao/Cached.java | 28 +-- .../main/java/org/onap/aaf/auth/dao/CachedDAO.java | 50 ++--- .../java/org/onap/aaf/auth/dao/CassAccess.java | 26 +-- .../java/org/onap/aaf/auth/dao/CassDAOImpl.java | 34 ++-- .../src/main/java/org/onap/aaf/auth/dao/DAO.java | 4 +- .../java/org/onap/aaf/auth/dao/DAOException.java | 6 +- .../main/java/org/onap/aaf/auth/dao/DAO_RO.java | 10 +- .../main/java/org/onap/aaf/auth/dao/Loader.java | 28 +-- .../main/java/org/onap/aaf/auth/dao/Streamer.java | 4 +- .../main/java/org/onap/aaf/auth/dao/Touchable.java | 4 +- .../onap/aaf/auth/dao/cached/CachedCertDAO.java | 12 +- .../onap/aaf/auth/dao/cached/CachedCredDAO.java | 24 +-- .../org/onap/aaf/auth/dao/cached/CachedNSDAO.java | 4 +- .../onap/aaf/auth/dao/cached/CachedPermDAO.java | 20 +- .../onap/aaf/auth/dao/cached/CachedRoleDAO.java | 12 +- .../aaf/auth/dao/cached/CachedUserRoleDAO.java | 8 +- .../org/onap/aaf/auth/dao/cached/FileGetter.java | 202 ++++++++++----------- .../org/onap/aaf/auth/dao/cass/ApprovalDAO.java | 36 ++-- .../java/org/onap/aaf/auth/dao/cass/ArtiDAO.java | 28 +-- .../org/onap/aaf/auth/dao/cass/CacheInfoDAO.java | 50 ++--- .../org/onap/aaf/auth/dao/cass/CacheableData.java | 8 +- .../java/org/onap/aaf/auth/dao/cass/CertDAO.java | 28 +-- .../java/org/onap/aaf/auth/dao/cass/ConfigDAO.java | 16 +- .../java/org/onap/aaf/auth/dao/cass/CredDAO.java | 42 ++--- .../org/onap/aaf/auth/dao/cass/DelegateDAO.java | 20 +- .../java/org/onap/aaf/auth/dao/cass/FutureDAO.java | 14 +- .../org/onap/aaf/auth/dao/cass/HistoryDAO.java | 46 ++--- .../java/org/onap/aaf/auth/dao/cass/LocateDAO.java | 28 +-- .../java/org/onap/aaf/auth/dao/cass/Namespace.java | 14 +- .../java/org/onap/aaf/auth/dao/cass/NsDAO.java | 68 +++---- .../java/org/onap/aaf/auth/dao/cass/NsSplit.java | 8 +- .../java/org/onap/aaf/auth/dao/cass/NsType.java | 20 +- .../org/onap/aaf/auth/dao/cass/OAuthTokenDAO.java | 20 +- .../java/org/onap/aaf/auth/dao/cass/PermDAO.java | 70 +++---- .../java/org/onap/aaf/auth/dao/cass/RoleDAO.java | 60 +++--- .../java/org/onap/aaf/auth/dao/cass/Status.java | 20 +- .../org/onap/aaf/auth/dao/cass/UserRoleDAO.java | 56 +++--- .../org/onap/aaf/auth/dao/hl/CassExecutor.java | 4 +- .../java/org/onap/aaf/auth/dao/hl/Function.java | 126 ++++++------- .../java/org/onap/aaf/auth/dao/hl/PermLookup.java | 20 +- .../java/org/onap/aaf/auth/dao/hl/Question.java | 164 ++++++++--------- .../org/onap/aaf/auth/direct/DirectAAFLocator.java | 22 +-- .../org/onap/aaf/auth/direct/DirectAAFLur.java | 24 +-- .../onap/aaf/auth/direct/DirectAAFUserPass.java | 10 +- .../onap/aaf/auth/direct/DirectCertIdentity.java | 12 +- .../onap/aaf/auth/direct/DirectLocatorCreator.java | 10 +- .../org/onap/aaf/auth/direct/DirectRegistrar.java | 14 +- 51 files changed, 820 insertions(+), 822 deletions(-) (limited to 'auth/auth-cass/src/main') 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 { 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 { private static final Deque resetDeque = new ConcurrentLinkedDeque(); private static boolean resetTrigger = false; private static long nextAvailableReset = 0; - + public AbsCassDAO(TRANS trans, String name, Cluster cluster, String keyspace, Class dataClass) { this.name = name; this.cluster = cluster; @@ -95,7 +95,7 @@ public abstract class AbsCassDAO { 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 { /** * Create a PSInfo and create Prepared Statement - * + * * @param trans * @param theCQL * @param loader @@ -137,7 +137,7 @@ public abstract class AbsCassDAO { } else { crud = CRUD.read; } - + int idx = 0, count=0; while ((idx=cql.indexOf('?',idx))>=0) { ++idx; @@ -145,14 +145,14 @@ public abstract class AbsCassDAO { } 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 { /** * Execute a Prepared Statement by extracting from DATA object - * + * * @param trans * @param text * @param data @@ -194,7 +194,7 @@ public abstract class AbsCassDAO { /** * Execute a Prepared Statement on Object[] key - * + * * @param trans * @param text * @param objs @@ -211,15 +211,15 @@ public abstract class AbsCassDAO { 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 { /* * "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 { /** * Execute a Prepared Statement on Object[] key - * + * * @param trans * @param text * @param objs @@ -281,12 +281,12 @@ public abstract class AbsCassDAO { */ public Result> 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 misa = new HashMap<>(); // //misa.put(new InetSocketAddress(444),new Exception("no host was tried")); @@ -301,20 +301,20 @@ public abstract class AbsCassDAO { } finally { tt.done(); } - + return extract(loader,rs,null /*let Array be created if necessary*/,dflt); } - + public Result> 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 { } else { DATA d; List 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 { 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 { //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.PSInfo psi : psinfos) { if (psi.ps==null) { @@ -378,7 +378,7 @@ public abstract class AbsCassDAO { } } } - + 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 { // 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 { } } } - + if (reset || session == null) { TimeTaken tt = trans.start(NEW_CASSANDRA_SESSION, Env.SUB); try { @@ -458,7 +458,7 @@ public abstract class AbsCassDAO { } 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.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 { protected void wasModified(TRANS trans, CRUD modified, DATA data, String ... override) { } - + protected interface Accept { 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 { /** * Touch the date field for given Table - * + * * @param trans * @param name * @return @@ -39,9 +39,9 @@ public interface CIDAO { /** * 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 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 extends Cache { // Java does not allow creation of Arrays with Generics in them... protected final CIDAO info; - + private static Timer infoTimer; private Object cache[]; public final int segSize; @@ -73,7 +73,7 @@ public class Cached extends Cache data) { @SuppressWarnings("unchecked") Map map = ((Map)cache[cacheIdx(key)]); @@ -105,21 +105,21 @@ public class Cached extends Cache { public abstract Result> get(); }; - + // TODO utilize Segmented Caches, and fold "get" into "reads" @SuppressWarnings("unchecked") public Result> get(TRANS trans, String key, Getter getter) { List ld = null; Result> rld = null; - + int cacheIdx = cacheIdx(key); Map map = ((Map)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)cached.data; @@ -139,7 +139,7 @@ public class Cached extends Cache ... dao) { - for (CachedDAO d : dao) { + for (CachedDAO d : dao) { for (int i=0;i extends Cache void startRefresh(AuthzEnv env, CIDAO 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 extends Cache cidao; private int minRefresh; private long lastRun; - + public Refresh(AuthzEnv env, CIDAO 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 */ -public class CachedDAO,DATA extends Cacheable> +public class CachedDAO,DATA extends Cacheable> extends Cached implements DAO_RO{ -// private final String dirty_str; - +// private final String dirty_str; + private final D dao; public CachedDAO(D dao, CIDAO 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,DATA extend ((CassDAOImpl)dao).cache = this; } } - - public static, DT extends Cacheable> + + public static, DT extends Cacheable> CachedDAO create(DA dao, CIDAO info, int segsize, long expireIn) { return new CachedDAO(dao,info, segsize, expireIn); } @@ -68,7 +68,7 @@ public class CachedDAO,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,DATA extend this.dao = dao; this.objs = objs; } - + /** * Separated into single call for easy overloading * @return @@ -130,7 +130,7 @@ public class CachedDAO,DATA extend public Result> call() { return dao.read(trans, objs); } - + @Override public final Result> get() { return call(); @@ -144,7 +144,7 @@ public class CachedDAO,DATA extend @Override public Result> 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,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> 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,DATA extend // } // return getter.result; } - + @Override public Result> read(TRANS trans, DATA data) { return read(trans,dao.keyFrom(data)); @@ -202,24 +202,24 @@ public class CachedDAO,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 cls; private List 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 extends AbsCassDAO extends AbsCassDAO cache; @@ -89,7 +89,7 @@ public class CassDAOImpl extends AbsCassDAO extends AbsCassDAO dc,Loader loader) { return setCRUD(trans, table, dc, loader, -1); } - + public final String[] setCRUD(TRANS trans, String table, Class dc,Loader loader, int max) { Field[] fields = dc.getDeclaredFields(); int end = max>=0 && max0) { for (int i=0;i0) { @@ -148,18 +148,18 @@ public class CassDAOImpl extends AbsCassDAO extends AbsCassDAO extends AbsCassDAO 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 extends AbsCassDAO extends AbsCassDAO rs = deletePS.execAsync(trans, D_TEXT, d); if (rs.notOK()) { @@ -316,7 +316,7 @@ public class CassDAOImpl extends AbsCassDAO 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 { 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 { } 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 { } } } - - + + /** * We use bytes here to set a Maximum - * + * * @param is * @param MAX * @return @@ -118,10 +118,10 @@ public abstract class Loader { /** * 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 { } } - + public static Set readStringSet(DataInputStream is, byte[] buff) throws IOException { int l = is.readInt(); if (l<0) { @@ -149,7 +149,7 @@ public abstract class Loader { } return set; } - + public static List readStringList(DataInputStream is, byte[] buff) throws IOException { int l = is.readInt(); if (l<0) { @@ -162,7 +162,7 @@ public abstract class Loader { return list; } - /** + /** * Write a map * @param os * @param map @@ -198,7 +198,7 @@ public abstract class Loader { 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 public CachedCertDAO(CertDAO dao, CIDAO info, long expiresIn) { super(dao, info, CertDAO.CACHE_SEG, expiresIn); } - + /** * Pass through Cert ID Lookup - * + * * @param trans * @param ns * @return */ - + public Result> readID(AuthzTrans trans, final String id) { return dao().readID(trans, id); } - + public Result> 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 { private final ReadID readID; private final ReadID readIDBath; - + public CachedCredDAO(CredDAO dao, CIDAO info, long expiresIn) { super(dao, info, CredDAO.CACHE_SEG, expiresIn); if(FileGetter.isLoaded) { @@ -52,12 +52,12 @@ public class CachedCredDAO extends CachedDAO @Override public Result> read(AuthzTrans trans, final String id) { DAOGetter getter = new DAOGetter(trans,dao()) { - @Override + @Override public Result> call() { return dao().readID(trans, id); } }; - + Result> 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 return lurd; } }; - + readIDBath = new ReadID() { @Override public Result> read(AuthzTrans trans, final String id) { DAOGetter getter = new DAOGetter(trans,dao()) { - @Override + @Override public Result> call() { return dao().readIDBAth(trans, id); } }; - + Result> 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 }; } } - + /** * 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> 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 { return dao.readNS(trans, ns); } }; - + Result> 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 { } /** - * + * * @param trans * @param ns * @param type @@ -78,7 +78,7 @@ public class CachedPermDAO extends CachedDAO { return dao.readByType(trans, ns, type); } }; - + // Note: Can reuse index1 here, because there is no name collision versus response Result> lurd = get(trans, ns+'|'+type, getter); if (lurd.isOK() && lurd.isEmpty()) { @@ -86,10 +86,10 @@ public class CachedPermDAO extends CachedDAO { } return lurd; } - + /** * Add desciption to this permission - * + * * @param trans * @param ns * @param type @@ -98,12 +98,12 @@ public class CachedPermDAO extends CachedDAO { * @param description * @return */ - public Result addDescription(AuthzTrans trans, String ns, String type, + public Result 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 addRole(AuthzTrans trans, PermDAO.Data perm, RoleDAO.Data role) { Result 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 { return dao.readNS(trans, ns); } }; - + Result> 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 { return dao().readName(trans, name); } }; - + Result> 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 { 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> readByRole(AuthzTrans trans, final String role) { DAOGetter getter = new DAOGetter(trans,dao()) { public Result> 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> data; + private SimpleDateFormat sdf; + private FileGetter(Access access) { + if(access!=null) { + String filename = access.getProperty(AAF_FILEGETTER,null); + if((filename!=null)&&(!isLoaded)) { + data = new TreeMap<>(); + sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss+SSSS"); + CSV csv = new CSV(access, filename).setDelimiter('|'); + try { + access.log(Level.INIT, "Loading Filebased Cred from",filename); + csv.visit(row -> { + if(row.size()<1) { + access.log(Level.INIT, "Bad Row"); + } + int type; + try { + type =Integer.parseInt(row.get(1)); + } catch(Exception e) { + access.log(Level.INIT, e, "skipping ", row.get(0)); + return; + } + if(CredDAO.CERT_SHA256_RSA == type) { + return; + } + CredDAO.Data cdd = new CredDAO.Data(); + cdd.id=row.get(0); + cdd.type = type; + try { + cdd.expires = sdf.parse(row.get(2)); + cdd.cred = ByteBuffer.wrap(Hash.fromHex(row.get(3))); + cdd.notes= row.get(4); + cdd.ns = row.get(5); + cdd.other = Integer.parseInt(row.get(6)); + if(row.size()>8) { + cdd.tag = row.get(8); + } else { + cdd.tag = ""; + } + List lcdd = data.get(cdd.id); + if(lcdd == null) { + lcdd = new ArrayList<>(); + data.put(cdd.id, lcdd); + } + lcdd.add(cdd); + } catch (ParseException e) { + access.log(Level.INIT, e); + } + + }); + access.printf(Level.INIT, "Filebased Cred finished..."); + isLoaded = true; + } catch( CadiException | IOException e) { + access.log(Level.ERROR, e); + } + } + } + } + + public static synchronized FileGetter singleton(Access access) { + if(singleton==null) { + singleton = new FileGetter(access); + } + return singleton; + + } + public Getter getter(String id) { + return new FGetter(id); + } + private static List EMPTY = new ArrayList<>(); + public class FGetter implements Getter { + private final List lcdd; + public FGetter(final String id) { + lcdd = data.get(id); + } + @Override + public Result> get() { + return Result.ok(lcdd==null?EMPTY:lcdd); + } + } - private Map> data; - private SimpleDateFormat sdf; - private FileGetter(Access access) { - if(access!=null) { - String filename = access.getProperty(AAF_FILEGETTER,null); - if((filename!=null)&&(!isLoaded)) { - data = new TreeMap<>(); - sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss+SSSS"); - CSV csv = new CSV(access, filename).setDelimiter('|'); - try { - access.log(Level.INIT, "Loading Filebased Cred from",filename); - csv.visit(row -> { - if(row.size()<1) { - access.log(Level.INIT, "Bad Row"); - } - int type; - try { - type =Integer.parseInt(row.get(1)); - } catch(Exception e) { - access.log(Level.INIT, e, "skipping ", row.get(0)); - return; - } - if(CredDAO.CERT_SHA256_RSA == type) { - return; - } - CredDAO.Data cdd = new CredDAO.Data(); - cdd.id=row.get(0); - cdd.type = type; - try { - cdd.expires = sdf.parse(row.get(2)); - cdd.cred = ByteBuffer.wrap(Hash.fromHex(row.get(3))); - cdd.notes= row.get(4); - cdd.ns = row.get(5); - cdd.other = Integer.parseInt(row.get(6)); - if(row.size()>8) { - cdd.tag = row.get(8); - } else { - cdd.tag = ""; - } - List lcdd = data.get(cdd.id); - if(lcdd == null) { - lcdd = new ArrayList<>(); - data.put(cdd.id, lcdd); - } - lcdd.add(cdd); - - } catch (ParseException e) { - access.log(Level.INIT, e); - } - - }); - access.printf(Level.INIT, "Filebased Cred finished..."); - isLoaded = true; - } catch( CadiException | IOException e) { - access.log(Level.ERROR, e); - } - - } - } - } + public static 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 getter(String id) { - return new FGetter(id); - } - private static List EMPTY = new ArrayList<>(); - public class FGetter implements Getter { - private final List lcdd; - public FGetter(final String id) { - lcdd = data.get(id); - } - @Override - public Result> get() { - return Result.ok(lcdd==null?EMPTY:lcdd); - } - } - - public static void main(String[] args) { - PropAccess access = new PropAccess(args); - access.setProperty(AAF_FILEGETTER,"/Users/jg1555/cred.dat"); - FileGetter fg = FileGetter.singleton(access); - - for(String id : new String[] {"m01891@aaf.att.com","bogus"}) { - Getter g = fg.getter(id); - Result> r = g.get(); - if(r.isOKhasData()) { - for(CredDAO.Data cdd : r.value) { - System.out.println(cdd); - } - } - } - } + for(String id : new String[] {"m01891@aaf.att.com","bogus"}) { + Getter g = fg.getter(id); + Result> r = g.get(); + if(r.isOKhasData()) { + for(CredDAO.Data cdd : r.value) { + System.out.println(cdd); + } + } + } + } } 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 { 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 { 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 { public String operation; public Date updated; } - + private static class ApprovalLoader extends Loader { 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 { 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 { 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 { } }, 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 { } }, 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 { if (rs.notOK()) { return Result.err(rs); } - return Result.ok(data); + return Result.ok(data); } @@ -195,7 +195,7 @@ public class ApprovalDAO extends CassDAOImpl { public Result> 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 { } 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 { 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 { public Date expires; public int renewDays; public Set sans; - + // // Getters public Set type(boolean mutable) { if (type == null) { @@ -104,7 +104,7 @@ public class ArtiDAO extends CassDAOImpl { 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 { private static class ArtifactLoader extends Loader implements Streamer{ 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 { 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 { } },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 { } },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 { },readConsistency); } - - + + public Result> 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 impl public static final Map 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 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 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 impl private static class InfoLoader extends Loader { 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 impl obj[idx]=data.touched; } } - + public static synchronized void startUpdate(AuthzEnv env, HMangr hman, SecuritySetter 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 impl private SecuritySetter ss; private final String authority; public boolean go = true; - + public CacheUpdate(AuthzEnv env, HMangr hman, SecuritySetter 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 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 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 impl return total; } } - + private class IntHolder { private int[] raw; HashSet set; - + public IntHolder(int ints[]) { raw = ints; set = null; @@ -234,7 +234,7 @@ public class CacheInfoDAO extends CassDAOImpl impl public void add(int[] ints) { if (set==null) { set = new HashSet<>(); - + for (int i=0;i impl return sb.toString(); } } - + @Override public void run() { do { @@ -279,7 +279,7 @@ public class CacheInfoDAO extends CassDAOImpl impl if (data==null) { continue; } - + int count = 0; CacheClear cc = null; Map gather = null; @@ -319,7 +319,7 @@ public class CacheInfoDAO extends CassDAOImpl 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 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 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 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 impl } finally { tt.done(); } - + String lastName = null; Date[] dates = null; for (Row row : rs.all()) { @@ -451,7 +451,7 @@ public class CacheInfoDAO extends CassDAOImpl 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 { public static final String TABLE = "x509"; public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F - + private HistoryDAO historyDAO; private CIDAO 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 { 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 { 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 { private static class CertLoader extends Loader implements Streamer{ 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 { obj[++idx] = data.x500; obj[++idx] = data.x509; - + } @Override @@ -172,7 +172,7 @@ public class CertDAO extends CassDAOImpl { } } } - + public Result> 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 { psX500 = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE x500 = ?", CertLoader.deflt,readConsistency); - + } - + public Result> 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 { 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 { private static class ConfigLoader extends Loader implements Streamer{ 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 { 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 { protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) { // not an auditable table. } - + public Result> 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 { 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 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 { 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 { 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 { public static class CredLoader extends Loader implements Streamer{ 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 { 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 { 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 { 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 { 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 { 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 { public Result> readNS(AuthzTrans trans, String ns) { return psNS.read(trans, R_TEXT, new Object[]{ns}); } - + public Result> readID(AuthzTrans trans, String id) { return psID.read(trans, R_TEXT, new Object[]{id}); } - + public Result> 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 { 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 { 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 { 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 implements Streamer{ public static final int MAGIC=0xD823ACF2; public static final int VERSION=1; @@ -87,7 +87,7 @@ public class DelegateDAO extends CassDAOImpl { 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 { 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 { 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 { 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 { public String memo; public ByteBuffer reconstruct; } - + public static class HistLoader extends Loader { public HistLoader(int keylimit) { super(keylimit); @@ -118,10 +118,10 @@ public class HistoryDAO extends CassDAOImpl { 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 { // 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 { },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 { ); 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 { // 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 { } return extract(defLoader,rs.value,null,yyyymm.length>0?new YYYYMM(yyyymm):dflt); } - + public Result> 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 { } return extract(defLoader,rs.value,null,yyyymm.length>0?new YYYYMM(yyyymm):dflt); } - + private class YYYYMM implements Accept { private int[] yyyymm; public YYYYMM(int yyyymm[]) { @@ -240,7 +240,7 @@ public class HistoryDAO extends CassDAOImpl { } 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 { public static final String TABLE = "locate"; private AbsCassDAO.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 { 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 { } 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 { private static class LocateLoader extends Loader implements Streamer{ 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 { writeString(os,s); } } - + writeString(os,data.port_key==null?"":data.port_key.toString()); } @@ -207,7 +207,7 @@ public class LocateDAO extends CassDAOImpl { 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 { } } } - + public Result> readByName(AuthzTrans trans, String service) { return psName.read(trans, "Read By Name", new Object[] {service}); } @@ -235,7 +235,7 @@ public class LocateDAO extends CassDAOImpl { 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 owner, List 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 { 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 { 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 { 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 { } 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 implements Streamer { 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 { 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 { 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 { } } - + @Override public Result create(AuthzTrans trans, Data data) { String ns = data.name; @@ -253,8 +253,8 @@ public class NsDAO extends CassDAOImpl { 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 { attribUpdateStmt(stmt, ns, es.getKey(),es.getValue()); } } - + // No point in deleting... insert overwrites... // for (Entry es : remoteAttr.entrySet()) { // str = localAttr.get(es.getKey()); @@ -320,7 +320,7 @@ public class NsDAO extends CassDAOImpl { @Override public Result> read(AuthzTrans trans, Data data) { Result> 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 { return super.delete(trans, data, reread); } - + public Result> readAttribByNS(AuthzTrans trans, String ns) { Map 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 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 { Set 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 iter = rs.iterator();iter.hasNext(); ) { Row r = iter.next(); set.add(r.getString(0)); @@ -431,7 +431,7 @@ public class NsDAO extends CassDAOImpl { 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 { sb.append("';"); return sb; } - + public Result attribRemove(AuthzTrans trans, String ns, String key) { try { @@ -468,7 +468,7 @@ public class NsDAO extends CassDAOImpl { 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 { 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 { */ public Result 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 { public Result> 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 { public static final String TABLE = "oauth_token"; private AbsCassDAO.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 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 { public String refresh; public Date expires; public long exp_sec; - public String content; + public String content; public Set scopes; public String state; public String req_ip; // requesting @@ -93,7 +93,7 @@ public class OAuthTokenDAO extends CassDAOImpl { 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 { private static class OAuthLoader extends Loader implements Streamer{ 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 { 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 { public String type; public String instance; public String action; - public Set roles; + public Set 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 { 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 { 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 { /** * Decode Perm String, including breaking into appropriate Namespace - * + * * @param trans * @param q * @param p @@ -169,7 +169,7 @@ public class PermDAO extends CassDAOImpl { 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 { } return rv; } - + public static Data create(AuthzTrans trans, Question q, String name) { String[] s = name.split("\\|"); Result rdns = q.deriveNsSplit(trans, s[0]); @@ -240,7 +240,7 @@ public class PermDAO extends CassDAOImpl { } return rv; } - + //////////////////////////////////////// // Getters public Set roles(boolean mutable) { @@ -268,7 +268,7 @@ public class PermDAO extends CassDAOImpl { 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 { return encode(); } } - + private static class PermLoader extends Loader implements Streamer { 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 { 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 { /** * 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 { } - + /** - * Additional method: + * Additional method: * Select all Permissions by Name - * + * * @param name * @return * @throws DAOException @@ -450,7 +450,7 @@ public class PermDAO extends CassDAOImpl { public Result> readByType(AuthzTrans trans, String ns, String type) { return psByType.read(trans, R_TEXT, new Object[]{ns, type}); } - + public Result> 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 { /** * Add description to this permission - * + * * @param trans * @param ns * @param type @@ -473,7 +473,7 @@ public class PermDAO extends CassDAOImpl { public Result 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 { 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 { } 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 { 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 { 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 { } 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 { /** * Decode Perm String, including breaking into appropriate Namespace - * + * * @param trans * @param q * @param p @@ -189,7 +189,7 @@ public class RoleDAO extends CassDAOImpl { } return Result.ok(ss); } - + @Override public int[] invalidate(Cached cache) { return new int[] { @@ -205,7 +205,7 @@ public class RoleDAO extends CassDAOImpl { 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 { 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 { 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 { obj[++idx]=data.name + DOT_PLUS_ONE; } },readConsistency); - + } public Result> readNS(AuthzTrans trans, String ns) { @@ -306,7 +306,7 @@ public class RoleDAO extends CassDAOImpl { public Result> 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 { /** * 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 { // 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 { // 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 { 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 { */ public Result 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 { 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 { } } - + } \ 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 */ public class Status extends Result { - + // 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 extends Result { 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 extends Result { 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 extends Result { 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 { 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 { 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 { 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 { 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 rnss = ques.deriveNsSplit(trans, role); @@ -141,12 +141,12 @@ public class UserRoleDAO extends CassDAOImpl { return user + '|' + ns + '|' + rname + '|' + Chrono.dateStamp(expires); } } - + private static class URLoader extends Loader implements Streamer { 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 { 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 { 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 { } }; - + 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 { public Result> 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 { 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 { 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 { 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 RE = Result.ok(OP_STATUS.E); public final static Result 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> 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 lrdd = new ArrayList<>(); - + for (String rl : pdd.roles(false)) { Result 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> 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> 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 lrdd = new ArrayList<>(); - + for (String rl : pdd.roles(false)) { Result 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 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 addPermToRole(AuthzTrans trans, RoleDAO.Data role,PermDAO.Data pd, boolean fromApproval) { String user = trans.user(); - + if (!fromApproval) { Result 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 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 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 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 get(AuthzTrans trans, Object ... keys); } - + public Lookup urDBLookup = new Lookup() { @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 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 addIdentity(AuthzTrans trans, StringBuilder sb, + private Result 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> roles = null; private Result> permNames = null; private Result> perms = null; - + private PermLookup() {} - + public static PermLookup get(AuthzTrans trans, Question q, String user) { PermLookup lp=null; Map permMap = trans.get(Question.PERMS, null); @@ -74,7 +74,7 @@ public class PermLookup { } return lp; } - + public Result> getUserRoles() { if (userRoles==null) { userRoles = q.userRoleDAO().readByUser(trans,user); @@ -143,7 +143,7 @@ public class PermLookup { return permNames; } } - + public Result> 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 mspdd = new TreeMap<>(); Result ap = PermDAO.Data.decodeToArray(trans, q, perm); if (ap.isOK()) { - + Result> 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> getPermsByUser(AuthzTrans trans, String user, boolean lookup) { return PermLookup.get(trans, this, user).getPerms(lookup); } - + public Result> getPermsByUserFromRolesFilter(AuthzTrans trans, String user, String forUser) { PermLookup plUser = PermLookup.get(trans, this, user); Result> plPermNames = plUser.getPermNames(); if (plPermNames.notOK()) { return Result.err(plPermNames); } - + Set 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> forUpn = fUser.getPermNames(); if (forUpn.notOK()) { return Result.err(forUpn); } - + for (String pn : forUpn.value) { Result 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> 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 deriveNs(AuthzTrans trans, String child) { Result> 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> 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|::ns| @@ -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 rv = mayUserVirtueOfNS(trans, user, ndd, + Result 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; // .access|:role:| 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> 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 cddl; if (result.value.size() > 1) { - Map mcdd = new TreeMap<>(); - CredDAO.Data cdd; - String tag; - int pseudoTag = 0; + Map 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 userCredCheck(AuthzTrans trans, CredDAO.Data orig, final byte[] raw) { Result 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> 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 { 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 { throw new LocatorException("Invalid Version String: " + version); } } - + try { String aaf_url; if(name.indexOf('.')>=0) { @@ -87,10 +87,10 @@ public class DirectAAFLocator extends AbsAAFLocator { 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 { 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> 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> 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 { private LocateDAO ldao; - private List ldd; + private List 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 { @Override public Result 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 dr = ldao.update(trans, ld); @@ -83,7 +83,7 @@ public class DirectRegistrar implements Registrant { } } } - + if(sb==null) { return Result.ok(200, null); } else { @@ -96,7 +96,7 @@ public class DirectRegistrar implements Registrant { */ @Override public Result 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 dr = ldao.delete(trans, ld, false); @@ -109,7 +109,7 @@ public class DirectRegistrar implements Registrant { } } } - + if(sb==null) { return Result.ok(200, null); } else { -- cgit 1.2.3-korg