2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.dao.cached;
24 import java.util.List;
26 import org.onap.aaf.auth.dao.CIDAO;
27 import org.onap.aaf.auth.dao.CachedDAO;
28 import org.onap.aaf.auth.dao.cass.PermDAO;
29 import org.onap.aaf.auth.dao.cass.RoleDAO;
30 import org.onap.aaf.auth.dao.cass.Status;
31 import org.onap.aaf.auth.dao.cass.PermDAO.Data;
32 import org.onap.aaf.auth.env.AuthzTrans;
33 import org.onap.aaf.auth.layer.Result;
35 public class CachedPermDAO extends CachedDAO<AuthzTrans,PermDAO, PermDAO.Data> {
37 public CachedPermDAO(PermDAO dao, CIDAO<AuthzTrans> info, long expiresIn) {
38 super(dao, info, PermDAO.CACHE_SEG, expiresIn);
41 public Result<List<Data>> readNS(AuthzTrans trans, final String ns) {
42 DAOGetter getter = new DAOGetter(trans,dao()) {
44 public Result<List<Data>> call() {
45 return dao.readNS(trans, ns);
49 Result<List<Data>> lurd = get(trans, ns, getter);
50 if (lurd.isOKhasData()) {
55 return Result.err(Status.ERR_PermissionNotFound,"No Permission found - " + lurd.details);
58 public Result<List<Data>> readChildren(AuthzTrans trans, final String ns, final String type) {
59 return dao().readChildren(trans,ns,type);
69 public Result<List<Data>> readByType(AuthzTrans trans, final String ns, final String type) {
70 DAOGetter getter = new DAOGetter(trans,dao()) {
72 public Result<List<Data>> call() {
73 return dao.readByType(trans, ns, type);
77 // Note: Can reuse index1 here, because there is no name collision versus response
78 Result<List<Data>> lurd = get(trans, ns+'|'+type, getter);
79 if (lurd.isOK() && lurd.isEmpty()) {
80 return Result.err(Status.ERR_PermissionNotFound,"No Permission found");
86 * Add desciption to this permission
96 public Result<Void> addDescription(AuthzTrans trans, String ns, String type,
97 String instance, String action, String description) {
99 return dao().addDescription(trans, ns, type, instance, action, description);
102 public Result<Void> addRole(AuthzTrans trans, PermDAO.Data perm, RoleDAO.Data role) {
103 Result<Void> rv = dao().addRole(trans,perm,role.encode());
104 if (trans.debug().isLoggable())
105 trans.debug().log("Adding",role.encode(),"to", perm, "with CachedPermDAO.addRole");
106 invalidate(trans,perm);
110 public Result<Void> delRole(AuthzTrans trans, Data perm, RoleDAO.Data role) {
111 Result<Void> rv = dao().delRole(trans,perm,role.encode());
112 if (trans.debug().isLoggable())
113 trans.debug().log("Removing",role.encode(),"from", perm, "with CachedPermDAO.delRole");
114 invalidate(trans,perm);