return ld;
}
protected int count(String str, char c) {
- int count=str==null||str.isEmpty()?0:1;
- for(int i=str.indexOf(c);i>=0;i=str.indexOf(c,i+1)) {
- ++count;
+ if(str==null || str.isEmpty()) {
+ return 0;
+ } else {
+ int count=1;
+ for(int i=str.indexOf(c);i>=0;i=str.indexOf(c,i+1)) {
+ ++count;
+ }
+ return count;
}
- return count;
}
public final void close(AuthzTrans trans) {
try {
Thread.sleep(wait);
} catch (InterruptedException e) {
+ return exec(trans,org,sb);
}
}
return exec(trans,org,sb);
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";
+ private static final Object LOCK = new Object();
private static class ResetRequest {
//package on purpose
Cluster tempCluster = null;
Session tempSession = null;
try {
- synchronized(NEW_CASSANDRA_SESSION_CREATED) {
+ synchronized(LOCK) {
boolean reset = false;
for(ResetRequest r : resetDeque) {
if(r.session == session) {
*/
public Result<DATA> create(TRANS trans, DATA data) {
if(createPS==null) {
- Result.err(Result.ERR_NotImplemented,"Create is disabled for %s",getClass().getSimpleName());
+ return Result.err(Result.ERR_NotImplemented,"Create is disabled for %s",getClass().getSimpleName());
}
if(async) /*ResultSetFuture */ {
Result<ResultSetFuture> rs = createPS.execAsync(trans, C_TEXT, data);
*/
public Result<List<DATA>> read(TRANS trans, DATA data) {
if(readPS==null) {
- Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName());
+ return Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName());
}
return readPS.read(trans, R_TEXT, data);
}
public Result<List<DATA>> read(TRANS trans, Object ... key) {
if(readPS==null) {
- Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName());
+ return Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName());
}
return readPS.read(trans, R_TEXT, key);
}
public Result<DATA> readPrimKey(TRANS trans, Object ... key) {
if(readPS==null) {
- Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName());
+ return Result.err(Result.ERR_NotImplemented,"Read is disabled for %s",getClass().getSimpleName());
}
Result<List<DATA>> rld = readPS.read(trans, R_TEXT, key);
if(rld.isOK()) {
public Result<Void> update(TRANS trans, DATA data, boolean async) {
if(updatePS==null) {
- Result.err(Result.ERR_NotImplemented,"Update is disabled for %s",getClass().getSimpleName());
+ return Result.err(Result.ERR_NotImplemented,"Update is disabled for %s",getClass().getSimpleName());
}
if(async)/* ResultSet rs =*/ {
Result<ResultSetFuture> rs = updatePS.execAsync(trans, U_TEXT, data);
// This method Sig for Cached...
public Result<Void> delete(TRANS trans, DATA data, boolean reread) {
if(deletePS==null) {
- Result.err(Result.ERR_NotImplemented,"Delete is disabled for %s",getClass().getSimpleName());
+ return Result.err(Result.ERR_NotImplemented,"Delete is disabled for %s",getClass().getSimpleName());
}
// Since Deleting will be stored off, for possible re-constitution, need the whole thing
if(reread) {
data.x509 = readString(is,buff);
data.ca = readString(is,buff);
int i = is.readInt();
- if(i<0) {
- data.serial=null;
- } else {
+ data.serial=null;
+ if(i>=0) {
byte[] bytes = new byte[i]; // a bit dangerous, but lessened because of all the previous sized data reads
- is.read(bytes);
- data.serial = new BigInteger(bytes);
+ if(is.read(bytes)>0) {
+ data.serial = new BigInteger(bytes);
+ }
}
}
}
data.notes = readString(is,buff);
int i = is.readInt();
- if(i<0) {
- data.cred=null;
- } else {
+ data.cred=null;
+ if(i>=0) {
byte[] bytes = new byte[i]; // a bit dangerous, but lessened because of all the previous sized data reads
is.read(bytes);
data.cred = ByteBuffer.wrap(bytes);
if (r.isOKhasData()) {
return Result.ok(r.value.get(0));
} else {
- int dot = child == null ? -1 : child.lastIndexOf('.');
+ int dot;
+ if(child==null) {
+ return Result.err(Status.ERR_NsNotFound, "No Namespace");
+ } else {
+ dot = child.lastIndexOf('.');
+ }
if (dot < 0) {
- return Result.err(Status.ERR_NsNotFound,
- "No Namespace for [%s]", child);
+ return Result.err(Status.ERR_NsNotFound, "No Namespace for [%s]", child);
} else {
return deriveNs(trans, child.substring(0, dot));
}
bytes = new byte[(int)crt.length()];
FileInputStream fis = new FileInputStream(crt);
try {
- fis.read(bytes);
- addTrustedCA(new String(bytes));
+ int read = fis.read(bytes);
+ if(read>0) {
+ addTrustedCA(new String(bytes));
+ }
} finally {
fis.close();
}
private final static String MS_PROFILE="1";
private final static int MAX_RETRY=3;
- public static final long INVALIDATE_TIME = 1000*60*10; // 10 mins
+ public static final long INVALIDATE_TIME = 1000*60*10L; // 10 mins
// package on purpose
private Map<String,X509ChainWithIssuer> mxcwi_s;
|| trans.user().equals(sponsor)) {
return artiDAO.delete(trans, add, false);
}
- return null;
+ return Result.err(Result.ERR_Denied, "%1 is not allowed to delete this item",trans.user());
}
public Result<Void> deleteArtifact(AuthzTrans trans, List<ArtiDAO.Data> list) {
try {
ret = c.exec(++idx, largs);
if (delay+globalDelay > 0) {
- Thread.sleep(delay+globalDelay);
+ Thread.sleep((long)(delay+globalDelay));
}
} catch (Exception e) {
if (expect.contains(-1)) {
default:
throw new CadiException("Bad Argument");
};
-
- if(fp.get(AAFcli.timeout())) {
- pw().println(message);
+ if(fp==null) {
+ return 500;
} else {
- error(fp);
- return fp.code();
+ if(fp.get(AAFcli.timeout())) {
+ pw().println(message);
+ } else {
+ error(fp);
+ }
+
+ return fp.code();
}
-
- return fp==null?500:fp.code();
}
});
}
// case 4:
// return clean.exec(cleanIDX, args);
}
+ if(fp==null) {
+ return null; // get by Sonar check.
+ }
if(fp.get(AAFcli.timeout())) {
pw().print(verb);
pw().print(cr.getId());
Collections.sort(sorted, new Comparator<aaf.v2_0.Users.User>() {
@Override
public int compare(aaf.v2_0.Users.User u1, aaf.v2_0.Users.User u2) {
- if(u2==null || u2 == null) {
+ if(u1==null || u2 == null) {
return -1;
}
return u1.getId().compareTo(u2.getId());
public void open(AuthzTrans trans, long timeout) throws IOException {
TimeTaken tt = trans.start("Open Data File", Env.SUB);
- boolean opened = false, first = true;
+ boolean first = true;
try {
if(!dataf.exists()) {
throw new FileNotFoundException("Data File Missing:" + dataf.getCanonicalPath());
throw e;
}
ti.open();
- opened = true;
} finally {
tt.done();
}
- if(!opened) {
- throw new IOException("DataFile pair for " + name + " was not able to be opened in " + timeout + "ms");
- }
}
private synchronized void ensureIdxGood(AuthzTrans trans) throws IOException {
TimeTaken tt2 = trans.start("Open Files", Env.SUB);
try {
raf = new RandomAccessFile(file,"rw");
- raf.setLength(0L);
- fos = raf.getChannel();
+ try {
+ raf.setLength(0L);
+ fos = raf.getChannel();
+ } finally {
+ raf.close();
+ }
} finally {
tt2.done();
}
}
public final Validator permType(String type, String ns) {
- if(nob(type,NAME_CHARS)) {
- msg("Perm Type [" + (ns==null?"":ns+(type.length()==0?"":'.'))+type + "] is invalid.");
+ if(type==null) {
+ msg("Perm Type is null");
+ } else if(ns==null) {
+ msg("Perm NS is null");
+ } else if(nob(type,NAME_CHARS)) {
+ msg("Perm Type [" + (ns+(type.length()==0?"":'.'))+type + "] is invalid.");
}
return this;
}
}
public final Validator ns(String ns) {
- if(nob(ns,NAME_CHARS)){
+ if(ns==null) {
+ msg("NS is null");
+ return this;
+ } else if(nob(ns,NAME_CHARS)) {
msg("NS [" + ns + "] is invalid.");
}
for(String s : nsKeywords) {
}
public final static String GET_ENDPOINTS = "getEndpoints";
+ private final static Object LOCK = new Object();
/* (non-Javadoc)
* @see org.onap.aaf.auth.locate.facade.GwFacade#getEndpoints(org.onap.aaf.auth.env.test.AuthzTrans, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String, java.lang.String)
*/
try {
String output=null;
long temp=System.currentTimeMillis();
- synchronized(GET_ENDPOINTS) {
+ synchronized(LOCK) {
if(cacheClear<temp) {
epsCache.clear();
cacheClear = temp+1000*60*2; // 2 mins standard cache clear
return Result.err(reps);
} else {
output = epDF.newData(trans).load(reps.value).asString();
- synchronized(GET_ENDPOINTS) {
+ synchronized(LOCK) {
epsCache.put(key, output);
}
}
Result<Void> rp = service.putMgmtEndPoints(trans, rreq);
switch(rp.status) {
case OK:
- synchronized(GET_ENDPOINTS) {
+ synchronized(LOCK) {
cacheClear = 0L;
}
setContentType(resp,mepDF.getOutType());
Result<Void> rp = service.removeMgmtEndPoints(trans, rreq);
switch(rp.status) {
case OK:
- synchronized(GET_ENDPOINTS) {
+ synchronized(LOCK) {
cacheClear = 0L;
}
setContentType(resp,mepDF.getOutType());
import org.onap.aaf.auth.oauth.facade.DirectIntrospect;
import org.onap.aaf.auth.rserv.TransFilter;
import org.onap.aaf.cadi.CachedPrincipal;
+import org.onap.aaf.cadi.CachedPrincipal.Resp;
import org.onap.aaf.cadi.CadiException;
+import org.onap.aaf.cadi.CredVal.Type;
import org.onap.aaf.cadi.Hash;
import org.onap.aaf.cadi.LocatorException;
import org.onap.aaf.cadi.PropAccess;
-import org.onap.aaf.cadi.CachedPrincipal.Resp;
-import org.onap.aaf.cadi.CredVal.Type;
import org.onap.aaf.cadi.Taf.LifeForm;
import org.onap.aaf.cadi.config.Config;
import org.onap.aaf.cadi.oauth.OAuth2HttpTafResp;
import org.onap.aaf.cadi.oauth.TokenClient;
import org.onap.aaf.cadi.oauth.TokenClientFactory;
import org.onap.aaf.cadi.oauth.TokenMgr;
-import org.onap.aaf.cadi.oauth.TokenPerm;
import org.onap.aaf.cadi.oauth.TokenMgr.TokenPermLoader;
+import org.onap.aaf.cadi.oauth.TokenPerm;
import org.onap.aaf.cadi.principal.OAuth2FormPrincipal;
import org.onap.aaf.cadi.taf.HttpTaf;
import org.onap.aaf.cadi.taf.TafResp;
}
}
- if(client_id==null && client_secret==null) {
+ if(client_id==null || client_secret==null) {
return new OAuth2HttpTafResp(access, null, "client_id and client_secret required", RESP.TRY_ANOTHER_TAF, resp, false);
}
}
}
}
+ if(udr==null) {
+ return Result.err(Result.ERR_NotFound,"No User Data found");
+ }
if (udr.isOK()) {
return Result.ok();
}
if((uri = dl.get(li)) == null) {
System.out.println("Locator Item empty");
} else {
+ socket = new Socket();
try {
- socket = new Socket();
- socket.connect(new InetSocketAddress(uri.getHost(), uri.getPort()),3000);
- System.out.printf("Can Connect a Socket to %s %d\n",uri.getHost(),uri.getPort());
+ try {
+ socket.connect(new InetSocketAddress(uri.getHost(), uri.getPort()),3000);
+ System.out.printf("Can Connect a Socket to %s %d\n",uri.getHost(),uri.getPort());
+ } catch (IOException e) {
+ System.out.printf("Cannot Connect a Socket to %s %d: %s\n",uri.getHost(),uri.getPort(),e.getMessage());
+ }
+ } finally {
try {
socket.close();
} catch (IOException e1) {
System.out.printf("Could not close Socket Connection: %s\n",e1.getMessage());
}
- } catch (IOException e) {
- System.out.printf("Cannot Connect a Socket to %s %d: %s\n",uri.getHost(),uri.getPort(),e.getMessage());
}
}
}
f.setWritable(true);
}
}
+
// Append if not first
PrintWriter pw = new PrintWriter(new FileWriter(f,!first));
-
- // Write a Header
- if(first) {
- for(int i=0;i<60;++i) {
- pw.print('#');
- }
- pw.println();
- pw.println("# Properties Generated by AT&T Certificate Manager");
- pw.print("# by ");
- pw.println(System.getProperty("user.name"));
- pw.print("# on ");
- pw.println(Chrono.dateStamp());
- pw.println("# @copyright 2016, AT&T");
- for(int i=0;i<60;++i) {
- pw.print('#');
- }
- pw.println();
- for(String prop : encodeds) {
- if( prop.startsWith("cm_")
- || prop.startsWith(Config.HOSTNAME)
- || prop.startsWith(Config.AAF_ENV)) {
- pw.println(prop);
+ try {
+ // Write a Header
+ if(first) {
+ for(int i=0;i<60;++i) {
+ pw.print('#');
+ }
+ pw.println();
+ pw.println("# Properties Generated by AT&T Certificate Manager");
+ pw.print("# by ");
+ pw.println(System.getProperty("user.name"));
+ pw.print("# on ");
+ pw.println(Chrono.dateStamp());
+ pw.println("# @copyright 2016, AT&T");
+ for(int i=0;i<60;++i) {
+ pw.print('#');
+ }
+ pw.println();
+ for(String prop : encodeds) {
+ if( prop.startsWith("cm_")
+ || prop.startsWith(Config.HOSTNAME)
+ || prop.startsWith(Config.AAF_ENV)) {
+ pw.println(prop);
+ }
}
}
- }
- try {
for(String prop : encodeds) {
if(prop.startsWith("cadi")) {
pw.println(prop);
public static Collection<? extends Certificate> toX509Certificate(Trans trans, File file) throws CertificateException, FileNotFoundException {
FileInputStream fis = new FileInputStream(file);
try {
- return toX509Certificate(fis);
- } finally {
try {
- fis.close();
- } catch (IOException e) {
- throw new CertificateException(e);
+ return toX509Certificate(fis);
+ } finally {
+ fis.close();
}
+ } catch (IOException e) {
+ throw new CertificateException(e);
}
}
byte[] user = null;
byte[] pass = null;
int end = bytes.length;
- for (int i = bytes.length - 1; i >= 0; i--)
- {
- if (bytes[i] != 0)
+ for (int i = bytes.length - 1; i >= 0; i--) {
+ if (bytes[i] != 0) {
continue;
- if (pass == null)
+ }
+ if (pass == null) {
pass = Arrays.copyOfRange(bytes, i + 1, end);
- else if (user == null)
+ } else if (user == null) {
user = Arrays.copyOfRange(bytes, i + 1, end);
+ }
end = i;
}
public class Symm {
private static final byte[] DOUBLE_EQ = new byte[] {'=','='};
public static final String ENC = "enc:";
+ private static final Object LOCK = new Object();
private static final SecureRandom random = new SecureRandom();
public final char[] codeset;
}
public <T> T exec(SyncExec<T> exec) throws Exception {
- synchronized(ENC) {
+ synchronized(LOCK) {
if(keyBytes == null) {
keyBytes = new byte[AES.AES_KEY_SIZE/8];
int offset = (Math.abs(codeset[0])+47)%(codeset.length-keyBytes.length);
}
public void decode(InputStream is, OutputStream os, int skip) throws IOException {
- is.skip(skip);
+ if(is.skip(skip)!=skip) {
+ throw new IOException("Error skipping on IOStream in Symm");
+ }
decode(is,os);
}