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()) {
43 public Result<List<Data>> call() {
44 return dao.readNS(trans, ns);
48 Result<List<Data>> lurd = get(trans, ns, getter);
49 if (lurd.isOKhasData()) {
54 // if (getter.result==null) {
56 return Result.err(Status.ERR_PermissionNotFound,"No Permission found - " + lurd.details);
58 // return Result.ok(lurd);
61 // return getter.result;
64 public Result<List<Data>> readChildren(AuthzTrans trans, final String ns, final String type) {
65 return dao().readChildren(trans,ns,type);
75 public Result<List<Data>> readByType(AuthzTrans trans, final String ns, final String type) {
76 DAOGetter getter = new DAOGetter(trans,dao()) {
77 public Result<List<Data>> call() {
78 return dao.readByType(trans, ns, type);
82 // Note: Can reuse index1 here, because there is no name collision versus response
83 Result<List<Data>> lurd = get(trans, ns+'|'+type, getter);
84 if (lurd.isOK() && lurd.isEmpty()) {
85 return Result.err(Status.ERR_PermissionNotFound,"No Permission found");
91 * Add desciption to this permission
101 public Result<Void> addDescription(AuthzTrans trans, String ns, String type,
102 String instance, String action, String description) {
104 return dao().addDescription(trans, ns, type, instance, action, description);
107 public Result<Void> addRole(AuthzTrans trans, PermDAO.Data perm, RoleDAO.Data role) {
108 Result<Void> rv = dao().addRole(trans,perm,role.encode());
109 if (trans.debug().isLoggable())
110 trans.debug().log("Adding",role.encode(),"to", perm, "with CachedPermDAO.addRole");
111 invalidate(trans,perm);
115 public Result<Void> delRole(AuthzTrans trans, Data perm, RoleDAO.Data role) {
116 Result<Void> rv = dao().delRole(trans,perm,role.encode());
117 if (trans.debug().isLoggable())
118 trans.debug().log("Removing",role.encode(),"from", perm, "with CachedPermDAO.delRole");
119 invalidate(trans,perm);