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.CredDAO;
29 import org.onap.aaf.auth.dao.cass.CredDAO.Data;
30 import org.onap.aaf.auth.dao.cass.Status;
31 import org.onap.aaf.auth.env.AuthzTrans;
32 import org.onap.aaf.auth.layer.Result;
34 public class CachedCredDAO extends CachedDAO<AuthzTrans, CredDAO, CredDAO.Data> {
35 private final ReadID readID;
36 private final ReadID readIDBath;
38 public CachedCredDAO(CredDAO dao, CIDAO<AuthzTrans> info, long expiresIn) {
39 super(dao, info, CredDAO.CACHE_SEG, expiresIn);
40 if(FileGetter.isLoaded) {
41 readID = new ReadID() {
43 public Result<List<Data>> read(AuthzTrans trans, final String id) {
44 return FileGetter.singleton(null).getter(id).get();
47 // Both are the same... File read in only does BAth
50 readID = new ReadID() {
52 public Result<List<Data>> read(AuthzTrans trans, final String id) {
53 DAOGetter getter = new DAOGetter(trans,dao()) {
54 public Result<List<CredDAO.Data>> call() {
55 return dao().readID(trans, id);
59 Result<List<CredDAO.Data>> lurd = get(trans, id, getter);
60 if (lurd.isOK() && lurd.isEmpty()) {
61 return Result.err(Status.ERR_UserNotFound,"No User Cred found");
67 readIDBath = new ReadID() {
69 public Result<List<Data>> read(AuthzTrans trans, final String id) {
70 DAOGetter getter = new DAOGetter(trans,dao()) {
71 public Result<List<CredDAO.Data>> call() {
72 return dao().readIDBAth(trans, id);
76 Result<List<CredDAO.Data>> lurd = get(trans, id, getter);
77 if (lurd.isOK() && lurd.isEmpty()) {
78 return Result.err(Status.ERR_UserNotFound,"No User Cred found");
87 * Pass through Cred Lookup
89 * Unlike Role and Perm, we don't need or want to cache these elements... Only used for NS Delete.
95 public Result<List<CredDAO.Data>> readNS(AuthzTrans trans, final String ns) {
97 return dao().readNS(trans, ns);
100 public Result<List<CredDAO.Data>> readID(AuthzTrans trans, final String id) {
101 return readID.read(trans, id);
104 public Result<List<Data>> readIDBAth(AuthzTrans trans, String id) {
105 return readIDBath.read(trans,id);
108 private interface ReadID {
109 public Result<List<CredDAO.Data>> read(final AuthzTrans trans, final String id);