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====================================================
21 package org.onap.aaf.cadi.shiro;
23 import java.security.Principal;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashSet;
27 import java.util.Iterator;
28 import java.util.List;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import org.apache.shiro.subject.PrincipalCollection;
35 public class AAFPrincipalCollection implements PrincipalCollection {
37 private static final long serialVersionUID = 558246013419818831L;
38 private static final Logger logger = LoggerFactory.getLogger(AAFPrincipalCollection.class);
39 private static final Set<String> realmSet;
40 private final Principal principal;
41 private List<Principal> list=null;
42 private Set<Principal> set=null;
45 realmSet = new HashSet<String>();
46 realmSet.add(AAFRealm.AAF_REALM);
49 public AAFPrincipalCollection(Principal p) {
54 public AAFPrincipalCollection(final String principalName) {
55 principal = new Principal() {
56 private final String name = principalName;
58 public String getName() {
65 public Iterator<Principal> iterator() {
70 public List<Principal> asList() {
72 list = new ArrayList<Principal>();
79 public Set<Principal> asSet() {
81 set = new HashSet<Principal>();
87 @SuppressWarnings("unchecked")
89 public <T> Collection<T> byType(Class<T> cls) {
90 Collection<T> coll = new ArrayList<T>();
91 if(cls.isAssignableFrom(Principal.class)) {
92 coll.add((T)principal);
98 public Collection<Principal> fromRealm(String realm) {
99 if(AAFRealm.AAF_REALM.equals(realm)) {
102 return new ArrayList<Principal>();
107 public Principal getPrimaryPrincipal() {
112 public Set<String> getRealmNames() {
117 public boolean isEmpty() {
118 return principal==null;
121 @SuppressWarnings("unchecked")
123 public <T> T oneByType(Class<T> cls) {
124 if(cls.isAssignableFrom(Principal.class)) {