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%2FPermDAO.java;h=a59682c4a6c563e1bdb7ab913d6f25e69357d770;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=0033f8a1eebdbe54fdd1f827b35b5e464114e2e9;hpb=2c3cb70208785cf0272eae075206074318ca74cc;p=aaf%2Fauthz.git 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 0033f8a1..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; @@ -93,40 +93,40 @@ public class PermDAO extends CassDAOImpl { } public String fullType() { - StringBuilder sb = new StringBuilder(); - if(ns==null) { - sb.append('.'); - } else { - sb.append(ns); - sb.append(ns.indexOf('@')<0?'.':':'); - } - sb.append(type); - return sb.toString(); + StringBuilder sb = new StringBuilder(); + if(ns==null) { + sb.append('.'); + } else { + sb.append(ns); + sb.append(ns.indexOf('@')<0?'.':':'); + } + sb.append(type); + return sb.toString(); } - + public String fullPerm() { - StringBuilder sb = new StringBuilder(); - if(ns==null) { - sb.append("null."); - } else { - sb.append(ns); - sb.append(ns.indexOf('@')<0?'.':':'); - } - sb.append(type); - sb.append('|'); - sb.append(instance); - sb.append('|'); - sb.append(action); - return sb.toString(); + StringBuilder sb = new StringBuilder(); + if(ns==null) { + sb.append("null."); + } else { + sb.append(ns); + sb.append(ns.indexOf('@')<0?'.':':'); + } + sb.append(type); + sb.append('|'); + sb.append(instance); + sb.append('|'); + sb.append(action); + return sb.toString(); } 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,33 +206,33 @@ 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]); Data rv = new PermDAO.Data(); if (rdns.isOKhasData()) { switch(s.length) { - case 4: - rv.ns=s[0]; - rv.type=s[1]; - rv.instance=s[2]; - rv.action=s[3]; - break; + case 4: + rv.ns=s[0]; + rv.type=s[1]; + rv.instance=s[2]; + rv.action=s[3]; + break; case 3: - rv.ns=s[0]; + rv.ns=s[0]; rv.type=s[1]; rv.instance=s[2]; rv.action=s[3]; break; case 2: - rv.ns=s[0]; + rv.ns=s[0]; rv.type=s[1]; rv.instance=s[2]; rv.action=STAR; break; default: - rv.ns=s[0]; + rv.ns=s[0]; rv.type=s[1]; rv.instance = STAR; rv.action = STAR; @@ -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"); }