X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-cass%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fdao%2Fcass%2FCredDAO.java;h=137969e61b1abfb9bae3f9f2c7d3051140eba0f7;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=5acc836e7d18210b1602242510c7e15d4584f93f;hpb=bdce7667a6e272e2fa32e298d957a0d9090c5bc9;p=aaf%2Fauthz.git 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}); }