1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 module hunt.shiro.subject.PrincipalMap; 20 21 import hunt.shiro.subject.PrincipalCollection; 22 import hunt.collection.Map; 23 24 /** 25 * EXPERIMENTAL - DO NOT USE YET 26 * <p/> 27 * A {@code PrincipalMap} is map of all of a subject's principals - its identifying attributes like username, userId, 28 * etc. 29 * <p/> 30 * The {@link Map} methods allow you to interact with a unified representation of 31 * all of the Subject's principals, even if they came from different realms. You can think of the {@code Map} methods 32 * as the general purpose API for a Subject's principals. That is, you can access a principal generally: 33 * <pre> 34 * Object principal = subject.getPrincipals().get(principalName); 35 * </pre> 36 * For example, to get the Subject's username (if the 37 * username principal indeed exists and was populated by a Realm), you can do the following: 38 * <pre> 39 * string username = (string)subject.getPrincipals().get("username"); 40 * </pre> 41 * <h3>Multi-Realm Environments</h3> 42 * If your application uses multiple realms, the {@code Map} methods reflect 43 * the the aggregate principals from <em>all</em> realms that authenticated the owning {@code Subject}. 44 * <p/> 45 * But in these multi-realm environments, it is often convenient or necessary to acquire only the principals contributed 46 * by a specific realm (often in a realm implementation itself). This {@code PrincipalMap} interface satisfies 47 * those needs by providing additional realm-specific accessor/mutator methods. 48 * 49 * @author Les Hazlewood 50 */ 51 interface PrincipalMap : PrincipalCollection, Map!(string, Object) { 52 53 Map!(string,Object) getRealmPrincipals(string realmName); 54 55 Map!(string,Object) setRealmPrincipals(string realmName, Map!(string, Object) principals); 56 57 Object setRealmPrincipal(string realmName, string principalName, Object principal); 58 59 Object getRealmPrincipal(string realmName, string realmPrincipal); 60 61 Object removeRealmPrincipal(string realmName, string principalName); 62 63 }