import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.security.SecureRandom;
import java.util.Date;
import java.util.List;
public static final int BASIC_AUTH = 1;
public static final int BASIC_AUTH_SHA256 = 2;
public static final int CERT_SHA256_RSA =200;
+ public static final SecureRandom srand = new SecureRandom();
private HistoryDAO historyDAO;
private CIDAO<AuthzTrans> infoDAO;
public String id;
public Integer type;
- public Date expires;
- public Integer other;
- public String ns;
- public String notes;
- public ByteBuffer cred; // this is a blob in cassandra
+ public Date expires;
+ public Integer other;
+ public String ns;
+ public String tag;
+ public String notes;
+ public ByteBuffer cred; // this is a blob in cassandra
@Override
}
}
- private static class CredLoader extends Loader<Data> implements Streamer<Data>{
+ public static class CredLoader extends Loader<Data> implements Streamer<Data>{
public static final int MAGIC=153323443;
- public static final int VERSION=1;
+ public static final int VERSION=2;
public static final int BUFF_SIZE=48; // Note:
public static final CredLoader deflt = new CredLoader(KEYLIMIT);
data.expires = row.getTimestamp(2);
data.other = row.getInt(3);
data.ns = row.getString(4);
- data.notes = row.getString(5);
- data.cred = row.getBytesUnsafe(6);
+ data.tag = row.getString(5);
+ data.notes = row.getString(6);
+ data.cred = row.getBytesUnsafe(7);
return data;
}
@Override
protected void key(Data data, int _idx, Object[] obj) {
- int idx = _idx;
+ int idx = _idx;
obj[idx] = data.id;
obj[++idx] = data.type;
int i;
obj[i=idx] = data.other;
obj[++i] = data.ns;
+ obj[++i] = data.tag;
obj[++i] = data.notes;
obj[++i] = data.cred;
}
os.writeLong(data.expires==null?-1:data.expires.getTime());
os.writeInt(data.other==null?0:data.other);
writeString(os, data.ns);
+ writeString(os, data.tag);
writeString(os, data.notes);
- if(data.cred==null) {
+ if (data.cred==null) {
os.writeInt(-1);
} else {
int l = data.cred.limit()-data.cred.position();
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) {
+ if (i>=0) {
byte[] bytes = new byte[i]; // a bit dangerous, but lessened because of all the previous sized data reads
int read = is.read(bytes);
- if(read>0) {
+ if (read>0) {
data.cred = ByteBuffer.wrap(bytes);
}
}
private void init(AuthzTrans trans) throws APIException, IOException {
// Set up sub-DAOs
- if(historyDAO==null) {
+ if (historyDAO==null) {
historyDAO = new HistoryDAO(trans,this);
}
- if(infoDAO==null) {
+ if (infoDAO==null) {
infoDAO = new CacheInfoDAO(trans,this);
}
" WHERE id = ?", CredLoader.deflt,readConsistency);
}
- public Result<List<Data>> readNS(AuthzTrans trans, String ns) {
+ /* (non-Javadoc)
+ * @see org.onap.aaf.auth.dao.CassDAOImpl#create(org.onap.aaf.misc.env.TransStore, java.lang.Object)
+ */
+ @Override
+ public Result<Data> create(AuthzTrans trans, Data data) {
+ if(data.tag == null) {
+ long l = srand.nextLong();
+ data.tag = Long.toHexString(l);
+ }
+ return super.create(trans, data);
+ }
+
+ public Result<List<Data>> readNS(AuthzTrans trans, String ns) {
return psNS.read(trans, R_TEXT, new Object[]{ns});
}
? String.format("%s by %s", override[0], hd.user)
: (modified.name() + "d credential for " + data.id);
// Detail?
- if(modified==CRUD.delete) {
+ if (modified==CRUD.delete) {
try {
hd.reconstruct = data.bytify();
} catch (IOException e) {
}
}
- if(historyDAO.create(trans, hd).status!=Status.OK) {
+ if (historyDAO.create(trans, hd).status!=Status.OK) {
trans.error().log("Cannot log to History");
}
- if(infoDAO.touch(trans, TABLE,data.invalidate(cache)).status!=Status.OK) {
+ if (infoDAO.touch(trans, TABLE,data.invalidate(cache)).status!=Status.OK) {
trans.error().log("Cannot touch Cred");
}
}