2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 IBM.
7 * ===========================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END====================================================
23 package org.onap.aaf.auth.dao.cached;
25 import java.util.List;
27 import org.onap.aaf.auth.dao.CIDAO;
28 import org.onap.aaf.auth.dao.CachedDAO;
29 import org.onap.aaf.auth.dao.cass.CredDAO;
30 import org.onap.aaf.auth.dao.cass.CredDAO.Data;
31 import org.onap.aaf.auth.dao.cass.Status;
32 import org.onap.aaf.auth.env.AuthzTrans;
33 import org.onap.aaf.auth.layer.Result;
35 public class CachedCredDAO extends CachedDAO<AuthzTrans, CredDAO, CredDAO.Data> {
36 private final ReadID readID;
37 private final ReadID readIDBath;
39 public CachedCredDAO(CredDAO dao, CIDAO<AuthzTrans> info, long expiresIn) {
40 super(dao, info, CredDAO.CACHE_SEG, expiresIn);
41 if(FileGetter.isLoaded()) {
42 readID = new ReadID() {
44 public Result<List<Data>> read(AuthzTrans trans, final String id) {
45 return FileGetter.singleton(null).getter(id).get();
48 // Both are the same... File read in only does BAth
51 readID = new ReadID() {
53 public Result<List<Data>> read(AuthzTrans trans, final String id) {
54 DAOGetter getter = new DAOGetter(trans,dao()) {
56 public Result<List<CredDAO.Data>> call() {
57 return dao().readID(trans, id);
61 Result<List<CredDAO.Data>> lurd = get(trans, id, getter);
62 if (lurd.isOK() && lurd.isEmpty()) {
63 return Result.err(Status.ERR_UserNotFound,"No User Cred found");
69 readIDBath = new ReadID() {
71 public Result<List<Data>> read(AuthzTrans trans, final String id) {
72 DAOGetter getter = new DAOGetter(trans,dao()) {
74 public Result<List<CredDAO.Data>> call() {
75 return dao().readIDBAth(trans, id);
79 Result<List<CredDAO.Data>> lurd = get(trans, id, getter);
80 if (lurd.isOK() && lurd.isEmpty()) {
81 return Result.err(Status.ERR_UserNotFound,"No User Cred found");
90 * Pass through Cred Lookup
92 * Unlike Role and Perm, we don't need or want to cache these elements... Only used for NS Delete.
98 public Result<List<CredDAO.Data>> readNS(AuthzTrans trans, final String ns) {
100 return dao().readNS(trans, ns);
103 public Result<List<CredDAO.Data>> readID(AuthzTrans trans, final String id) {
104 return readID.read(trans, id);
107 public Result<List<Data>> readIDBAth(AuthzTrans trans, String id) {
108 return readIDBath.read(trans,id);
112 private interface ReadID {
113 public Result<List<CredDAO.Data>> read(final AuthzTrans trans, final String id);