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