+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START====================================================\r
- * * org.onap.aaf\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.onap.aaf.cadi.lur;\r
-\r
-import java.security.Principal;\r
-import java.util.List;\r
-\r
-import org.onap.aaf.cadi.CachingLur;\r
-import org.onap.aaf.cadi.CadiException;\r
-import org.onap.aaf.cadi.CredVal;\r
-import org.onap.aaf.cadi.Lur;\r
-import org.onap.aaf.cadi.Permission;\r
-\r
-/**\r
- * EpiLUR\r
- * \r
- * Short for "Epic LUR". Be able to run through a series of LURs to obtain the validation needed.\r
- * \r
- * The pun is better for the other pattern... "TAF" (aka EpiTaf), but it's still the larger picture of \r
- * LURs that will be accomplished.\r
- * \r
- * FYI, the reason we separate LURs, rather than combine, is that Various User Repository Resources have\r
- * different Caching requirements. For instance, the Local User Repo (with stand alone names), never expire, but might be\r
- * refreshed with a change in Configuration File, while the Remote Service based LURs will need to expire at prescribed intervals \r
- * \r
- *\r
- */\r
-public final class EpiLur implements Lur {\r
- private final Lur[] lurs;\r
- \r
- /**\r
- * EpiLur constructor\r
- * \r
- * Construct the EpiLur from variable TAF parameters\r
- * @param lurs\r
- * @throws CadiException\r
- */\r
- public EpiLur(Lur ... lurs) throws CadiException{\r
- this.lurs = lurs;\r
- if(lurs.length==0) throw new CadiException("Need at least one Lur implementation in constructor");\r
- }\r
-\r
- public boolean fish(Principal bait, Permission pond) {\r
- if(pond==null) {\r
- return false;\r
- }\r
- boolean rv = false;\r
- Lur lur;\r
- for(int i=0;!rv && i<lurs.length;++i) {\r
- rv = (lur = lurs[i]).fish(bait, pond);\r
- if(!rv && lur.handlesExclusively(pond)) break;\r
- }\r
- return rv;\r
- }\r
-\r
- public void fishAll(Principal bait, List<Permission> permissions) {\r
- for(Lur lur : lurs) {\r
- lur.fishAll(bait, permissions);\r
- }\r
- }\r
-\r
- public void destroy() {\r
- for(Lur lur : lurs) {\r
- lur.destroy();\r
- }\r
- }\r
-\r
- /**\r
- * Return the first Lur (if any) which also implements UserPass \r
- * @return\r
- */\r
- public CredVal getUserPassImpl() {\r
- for(Lur lur : lurs) {\r
- if(lur instanceof CredVal) {\r
- return (CredVal)lur;\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- // Never needed... Only EpiLur uses...\r
- public boolean handlesExclusively(Permission pond) {\r
- return false;\r
- }\r
- \r
- /**\r
- * Get Lur for index. Returns null if out of range\r
- * @param idx\r
- * @return\r
- */\r
- public Lur get(int idx) {\r
- if(idx>=0 && idx<lurs.length) {\r
- return lurs[idx];\r
- }\r
- return null;\r
- }\r
-\r
- public boolean supports(String userName) {\r
- for(Lur l : lurs) {\r
- if(l.supports(userName))return true;\r
- }\r
- return false;\r
- }\r
-\r
- public void remove(String id) {\r
- for(Lur l : lurs) {\r
- if(l instanceof CachingLur) {\r
- ((CachingLur<?>)l).remove(id);\r
- }\r
- }\r
- }\r
- \r
- public Lur subLur(Class<? extends Lur> cls ) {\r
- for(Lur l : lurs) {\r
- if(l.getClass().isAssignableFrom(cls)) {\r
- return l;\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- @Override\r
- public Permission createPerm(String p) {\r
- return new LocalPermission(p);\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see com.att.cadi.Lur#clear(java.security.Principal, java.lang.StringBuilder)\r
- */\r
- @Override\r
- public void clear(Principal p, StringBuilder report) {\r
- for(Lur lur : lurs) {\r
- lur.clear(p, report);\r
- }\r
- }\r
- \r
- public String toString() {\r
- StringBuilder sb = new StringBuilder();\r
- for(Lur lur : lurs) {\r
- sb.append(lur.getClass().getSimpleName());\r
- sb.append(": Report\n");\r
- sb.append(lur.toString());\r
- sb.append('\n');\r
- }\r
- return sb.toString();\r
- }\r
-}\r