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;
31 import org.apache.shiro.subject.PrincipalCollection;
33 public class AAFPrincipalCollection implements PrincipalCollection {
35 private static final long serialVersionUID = 558246013419818831L;
36 private static final Set<String> realmSet;
37 private final Principal principal;
38 private List<Principal> list=null;
39 private Set<Principal> set=null;
42 realmSet = new HashSet<String>();
43 realmSet.add(AAFRealm.AAF_REALM);
46 public AAFPrincipalCollection(Principal p) {
51 public AAFPrincipalCollection(final String principalName) {
52 principal = new Principal() {
53 private final String name = principalName;
55 public String getName() {
62 public Iterator<Principal> iterator() {
67 public List<Principal> asList() {
69 list = new ArrayList<Principal>();
76 public Set<Principal> asSet() {
78 set = new HashSet<Principal>();
84 @SuppressWarnings("unchecked")
86 public <T> Collection<T> byType(Class<T> cls) {
87 Collection<T> coll = new ArrayList<T>();
88 if(cls.isAssignableFrom(Principal.class)) {
89 coll.add((T)principal);
95 public Collection<Principal> fromRealm(String realm) {
96 if(AAFRealm.AAF_REALM.equals(realm)) {
99 return new ArrayList<Principal>();
104 public Principal getPrimaryPrincipal() {
109 public Set<String> getRealmNames() {
114 public boolean isEmpty() {
115 return principal==null;
118 @SuppressWarnings("unchecked")
120 public <T> T oneByType(Class<T> cls) {
121 if(cls.isAssignableFrom(Principal.class)) {