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%2FRoleDAO.java;fp=auth%2Fauth-cass%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fdao%2Fcass%2FRoleDAO.java;h=ae8d525df28c8a4c13962c5a39c596400646c788;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=e5c97559aaf0ff34a34e22401eab4b3a4e495cd8;hpb=bdce7667a6e272e2fa32e298d957a0d9090c5bc9;p=aaf%2Fauthz.git diff --git a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/RoleDAO.java b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/RoleDAO.java index e5c97559..ae8d525d 100644 --- a/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/RoleDAO.java +++ b/auth/auth-cass/src/main/java/org/onap/aaf/auth/dao/cass/RoleDAO.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. @@ -50,7 +50,7 @@ public class RoleDAO extends CassDAOImpl { public static final String TABLE = "role"; public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F - + private final HistoryDAO historyDAO; private final CacheInfoDAO infoDAO; @@ -96,34 +96,34 @@ public class RoleDAO extends CassDAOImpl { } return perms; } - + public static Data create(NsDAO.Data ns, String name) { - NsSplit nss = new NsSplit(ns,name); + NsSplit nss = new NsSplit(ns,name); RoleDAO.Data rv = new Data(); rv.ns = nss.ns; rv.name=nss.name; return rv; } - + public String fullName() { StringBuilder sb = new StringBuilder(); if(ns==null) { sb.append('.'); } else { sb.append(ns); - sb.append(ns.indexOf('@')<0?'.':':'); + sb.append(ns.indexOf('@')<0?'.':':'); } sb.append(name); return sb.toString(); } - + public String encode() { return ns + '|' + name; } - + /** * Decode Perm String, including breaking into appropriate Namespace - * + * * @param trans * @param q * @param r @@ -171,7 +171,7 @@ public class RoleDAO extends CassDAOImpl { /** * Decode Perm String, including breaking into appropriate Namespace - * + * * @param trans * @param q * @param p @@ -189,7 +189,7 @@ public class RoleDAO extends CassDAOImpl { } return Result.ok(ss); } - + @Override public int[] invalidate(Cached cache) { return new int[] { @@ -205,7 +205,7 @@ public class RoleDAO extends CassDAOImpl { RoleLoader.deflt.marshal(this,new DataOutputStream(baos)); return ByteBuffer.wrap(baos.toByteArray()); } - + @Override public void reconstitute(ByteBuffer bb) throws IOException { RoleLoader.deflt.unmarshal(this, toDIS(bb)); @@ -223,11 +223,11 @@ public class RoleDAO extends CassDAOImpl { public static final int BUFF_SIZE=96; public static final RoleLoader deflt = new RoleLoader(KEYLIMIT); - + public RoleLoader(int keylimit) { super(keylimit); } - + @Override public Data load(Data data, Row row) { // Int more efficient @@ -275,15 +275,15 @@ public class RoleDAO extends CassDAOImpl { private void init(AuthzTrans trans) { String[] helpers = setCRUD(trans, TABLE, Data.class, RoleLoader.deflt); - + psNS = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE ns = ?", new RoleLoader(1),readConsistency); psName = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + " WHERE name = ?", new RoleLoader(1),readConsistency); - psChildren = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + - " WHERE ns=? AND name > ? AND name < ?", + psChildren = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE + + " WHERE ns=? AND name > ? AND name < ?", new RoleLoader(3) { @Override protected void key(Data data, int _idx, Object[] obj) { @@ -293,7 +293,7 @@ public class RoleDAO extends CassDAOImpl { obj[++idx]=data.name + DOT_PLUS_ONE; } },readConsistency); - + } public Result> readNS(AuthzTrans trans, String ns) { @@ -306,7 +306,7 @@ public class RoleDAO extends CassDAOImpl { public Result> readChildren(AuthzTrans trans, String ns, String role) { if (role.length()==0 || "*".equals(role)) { - return psChildren.read(trans, R_TEXT, new Object[]{ns, FIRST_CHAR, LAST_CHAR}); + return psChildren.read(trans, R_TEXT, new Object[]{ns, FIRST_CHAR, LAST_CHAR}); } else { return psChildren.read(trans, R_TEXT, new Object[]{ns, role+DOT, role+DOT_PLUS_ONE}); } @@ -314,7 +314,7 @@ public class RoleDAO extends CassDAOImpl { /** * Add a single Permission to the Role's Permission Collection - * + * * @param trans * @param role * @param perm @@ -326,7 +326,7 @@ public class RoleDAO extends CassDAOImpl { // Note: Prepared Statements for Collection updates aren't supported String pencode = perm.encode(); try { - getSession(trans).execute(UPDATE_SP + TABLE + " SET perms = perms + {'" + + getSession(trans).execute(UPDATE_SP + TABLE + " SET perms = perms + {'" + pencode + "'} WHERE " + "ns = '" + role.ns + "' AND name = '" + role.name + "';"); } catch (DriverException | APIException | IOException e) { @@ -351,10 +351,10 @@ public class RoleDAO extends CassDAOImpl { // Note: Prepared Statements for Collection updates aren't supported String pencode = perm.encode(); - + //ResultSet rv = try { - getSession(trans).execute(UPDATE_SP + TABLE + " SET perms = perms - {'" + + getSession(trans).execute(UPDATE_SP + TABLE + " SET perms = perms - {'" + pencode + "'} WHERE " + "ns = '" + role.ns + "' AND name = '" + role.name + "';"); } catch (DriverException | APIException | IOException e) { @@ -366,10 +366,10 @@ public class RoleDAO extends CassDAOImpl { wasModified(trans, CRUD.update, role, "Removed permission " + pencode + " from role " + role.fullName() ); return Result.ok(); } - + /** * Add description to role - * + * * @param trans * @param ns * @param name @@ -378,7 +378,7 @@ public class RoleDAO extends CassDAOImpl { */ public Result addDescription(AuthzTrans trans, String ns, String name, String description) { try { - getSession(trans).execute(UPDATE_SP + TABLE + " SET description = '" + getSession(trans).execute(UPDATE_SP + TABLE + " SET description = '" + description + "' WHERE ns = '" + ns + "' AND name = '" + name + "';"); } catch (DriverException | APIException | IOException e) { reportPerhapsReset(trans,e); @@ -391,8 +391,8 @@ public class RoleDAO extends CassDAOImpl { wasModified(trans, CRUD.update, data, "Added description " + description + " to role " + data.fullName(), null ); return Result.ok(); } - - + + /** * Log Modification statements to History * @param modified which CRUD action was done @@ -426,5 +426,5 @@ public class RoleDAO extends CassDAOImpl { } } - + } \ No newline at end of file