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%2FOAuthTokenDAO.java;h=a84490d0b169593e94db42ccccc00ad1ec6b64a6;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=e1375b8af5125b923a083e3a577754187d3ecefa;hpb=71037c39a37d3549dcfe31926832a657744fbe05;p=aaf%2Fauthz.git 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 e1375b8a..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,77 +44,77 @@ 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; - + 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); + super(trans, OAuthTokenDAO.class.getSimpleName(),aDao, Data.class, TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE)); + init(trans); } public static final int KEYLIMIT = 1; - public static class Data implements Bytification { - public String id; - public String client_id; - public String user; - public boolean active; - public int type; - public String refresh; - public Date expires; - public long exp_sec; - public String content; - public Set scopes; - public String state; - public String req_ip; // requesting - - public Set scopes(boolean mutable) { - if (scopes == null) { - scopes = new HashSet(); - } else if (mutable && !(scopes instanceof HashSet)) { - scopes = new HashSet(scopes); - } - return scopes; - } - - @Override - public ByteBuffer bytify() throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - 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)); - } - - public String toString() { - return user.toString() + ' ' + id.toString() + ' ' + Chrono.dateTime(expires) + (active?"":"in") + "active"; - } + public static class Data implements Bytification { + public String id; + public String client_id; + public String user; + public boolean active; + public int type; + public String refresh; + public Date expires; + public long exp_sec; + public String content; + public Set scopes; + public String state; + public String req_ip; // requesting + + public Set scopes(boolean mutable) { + if (scopes == null) { + scopes = new HashSet<>(); + } else if (mutable && !(scopes instanceof HashSet)) { + scopes = new HashSet<>(scopes); + } + return scopes; + } + + @Override + public ByteBuffer bytify() throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + 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)); + } + + public String toString() { + return user.toString() + ' ' + id.toString() + ' ' + Chrono.dateTime(expires) + (active?"":"in") + "active"; + } } 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 OAuthLoader deflt = new OAuthLoader(KEYLIMIT); - public OAuthLoader(int keylimit) { - super(keylimit); - } - - @Override + 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 OAuthLoader deflt = new OAuthLoader(KEYLIMIT); + public OAuthLoader(int keylimit) { + super(keylimit); + } + + @Override public Data load(Data data, Row row) { data.id = row.getString(0); data.client_id = row.getString(1); @@ -152,43 +152,43 @@ public class OAuthTokenDAO extends CassDAOImpl { obj[++i] = data.req_ip; } - @Override - public void marshal(Data data, DataOutputStream os) throws IOException { - writeHeader(os,MAGIC,VERSION); - writeString(os, data.id); - writeString(os, data.client_id); - writeString(os, data.user); - os.writeBoolean(data.active); - os.writeInt(data.type); - writeString(os, data.refresh); - os.writeLong(data.expires==null?-1:data.expires.getTime()); - os.writeLong(data.exp_sec); - writeString(os, data.content); - writeStringSet(os,data.scopes); - writeString(os, data.state); - writeString(os, data.req_ip); - } - - - @Override - 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]; // used only if fits - data.id = readString(is,buff); - data.client_id = readString(is,buff); - data.user = readString(is,buff); - data.active = is.readBoolean(); - data.type = is.readInt(); - data.refresh = readString(is,buff); - long l = is.readLong(); - data.expires = l<0?null:new Date(l); - data.exp_sec = is.readLong(); - data.content = readString(is,buff); // note, large strings still ok with small buffer - data.scopes = readStringSet(is,buff); - data.state = readString(is,buff); - data.req_ip = readString(is,buff); - } + @Override + public void marshal(Data data, DataOutputStream os) throws IOException { + writeHeader(os,MAGIC,VERSION); + writeString(os, data.id); + writeString(os, data.client_id); + writeString(os, data.user); + os.writeBoolean(data.active); + os.writeInt(data.type); + writeString(os, data.refresh); + os.writeLong(data.expires==null?-1:data.expires.getTime()); + os.writeLong(data.exp_sec); + writeString(os, data.content); + writeStringSet(os,data.scopes); + writeString(os, data.state); + writeString(os, data.req_ip); + } + + + @Override + 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]; // used only if fits + data.id = readString(is,buff); + data.client_id = readString(is,buff); + data.user = readString(is,buff); + data.active = is.readBoolean(); + data.type = is.readInt(); + data.refresh = readString(is,buff); + long l = is.readLong(); + data.expires = l<0?null:new Date(l); + data.exp_sec = is.readLong(); + data.content = readString(is,buff); // note, large strings still ok with small buffer + data.scopes = readStringSet(is,buff); + data.state = readString(is,buff); + data.req_ip = readString(is,buff); + } } private void init(AuthzTrans trans) { @@ -196,7 +196,7 @@ public class OAuthTokenDAO extends CassDAOImpl { psByUser = new PSInfo(trans, "SELECT " + helpers[0] + " from " + TABLE + " WHERE user=?",OAuthLoader.deflt,readConsistency); } - /** + /** * Log Modification statements to History * * @param modified which CRUD action was done @@ -207,7 +207,7 @@ public class OAuthTokenDAO extends CassDAOImpl { protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) { } - public Result> readByUser(AuthzTrans trans, String user) { - return psByUser.read(trans, "Read By User", new Object[]{user}); - } + public Result> readByUser(AuthzTrans trans, String user) { + return psByUser.read(trans, "Read By User", new Object[]{user}); + } }