1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package com.att.cadi.lur;
\r
25 import java.security.Principal;
\r
26 import java.util.List;
\r
28 import com.att.cadi.CachingLur;
\r
29 import com.att.cadi.CadiException;
\r
30 import com.att.cadi.CredVal;
\r
31 import com.att.cadi.Lur;
\r
32 import com.att.cadi.Permission;
\r
37 * Short for "Epic LUR". Be able to run through a series of LURs to obtain the validation needed.
\r
39 * The pun is better for the other pattern... "TAF" (aka EpiTaf), but it's still the larger picture of
\r
40 * LURs that will be accomplished.
\r
42 * FYI, the reason we separate LURs, rather than combine, is that Various User Repository Resources have
\r
43 * different Caching requirements. For instance, the Local User Repo (with stand alone names), never expire, but might be
\r
44 * refreshed with a change in Configuration File, while the Remote Service based LURs will need to expire at prescribed intervals
\r
48 public final class EpiLur implements Lur {
\r
49 private final Lur[] lurs;
\r
52 * EpiLur constructor
\r
54 * Construct the EpiLur from variable TAF parameters
\r
56 * @throws CadiException
\r
58 public EpiLur(Lur ... lurs) throws CadiException{
\r
60 if(lurs.length==0) throw new CadiException("Need at least one Lur implementation in constructor");
\r
63 public boolean fish(Principal bait, Permission pond) {
\r
69 for(int i=0;!rv && i<lurs.length;++i) {
\r
70 rv = (lur = lurs[i]).fish(bait, pond);
\r
71 if(!rv && lur.handlesExclusively(pond)) break;
\r
76 public void fishAll(Principal bait, List<Permission> permissions) {
\r
77 for(Lur lur : lurs) {
\r
78 lur.fishAll(bait, permissions);
\r
82 public void destroy() {
\r
83 for(Lur lur : lurs) {
\r
89 * Return the first Lur (if any) which also implements UserPass
\r
92 public CredVal getUserPassImpl() {
\r
93 for(Lur lur : lurs) {
\r
94 if(lur instanceof CredVal) {
\r
95 return (CredVal)lur;
\r
101 // Never needed... Only EpiLur uses...
\r
102 public boolean handlesExclusively(Permission pond) {
\r
107 * Get Lur for index. Returns null if out of range
\r
111 public Lur get(int idx) {
\r
112 if(idx>=0 && idx<lurs.length) {
\r
118 public boolean supports(String userName) {
\r
119 for(Lur l : lurs) {
\r
120 if(l.supports(userName))return true;
\r
125 public void remove(String id) {
\r
126 for(Lur l : lurs) {
\r
127 if(l instanceof CachingLur) {
\r
128 ((CachingLur<?>)l).remove(id);
\r
133 public Lur subLur(Class<? extends Lur> cls ) {
\r
134 for(Lur l : lurs) {
\r
135 if(l.getClass().isAssignableFrom(cls)) {
\r
143 public Permission createPerm(String p) {
\r
144 return new LocalPermission(p);
\r
148 * @see com.att.cadi.Lur#clear(java.security.Principal, java.lang.StringBuilder)
\r
151 public void clear(Principal p, StringBuilder report) {
\r
152 for(Lur lur : lurs) {
\r
153 lur.clear(p, report);
\r
157 public String toString() {
\r
158 StringBuilder sb = new StringBuilder();
\r
159 for(Lur lur : lurs) {
\r
160 sb.append(lur.getClass().getSimpleName());
\r
161 sb.append(": Report\n");
\r
162 sb.append(lur.toString());
\r
165 return sb.toString();
\r