1 /* 2 * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.] 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.opensaml.xml.security.keyinfo; 18 19 import java.security.Key; 20 import java.util.Collection; 21 import java.util.Collections; 22 import java.util.Map; 23 import java.util.Set; 24 25 import org.opensaml.xml.security.credential.Credential; 26 import org.opensaml.xml.signature.KeyInfo; 27 import org.opensaml.xml.util.LazyMap; 28 import org.opensaml.xml.util.LazySet; 29 30 31 /** 32 * Resolution context class that is used to supply state information to, and to share information 33 * amongst, {@link KeyInfoProvider}s. 34 * 35 * <p> 36 * The extensible properties map available from {@link #getProperties()} may for example used to communicate 37 * state between two or more providers, or between a provider and custom logic in a particular implementation 38 * of {@link KeyInfoCredentialResolver}. It is recommended that providers and/or resolvers define 39 * and use property names in such a way as to avoid collisions with those used by other providers and resolvers, 40 * and to also clearly define the data type stored for each propery name. 41 * </p> 42 * 43 */ 44 public class KeyInfoResolutionContext { 45 46 /** The KeyInfo being processed. */ 47 private KeyInfo keyInfo; 48 49 /** Key names which are known to be associated with the KeyInfo being processed. 50 * These may have for example been extracted from KeyName elements present, 51 * or may have been inferred from the context in which the KeyInfo exists or 52 * is being used. */ 53 private Set<String> keyNames; 54 55 /** Get the key currently known to be represented by the KeyInfo. */ 56 private Key key; 57 58 /** This list provides KeyInfo resolvers and providers in a particular processing 59 * environment access to credentials that may have already been previously resolved. */ 60 private Collection<Credential> resolvedCredentials; 61 62 /** Extensible map of properties used to share state amongst providers and/or resolver logic. */ 63 private final Map<String, Object> properties; 64 65 /** 66 * Constructor. 67 * 68 * @param credentials a reference to the collection in which credentials previously 69 * resolved in a processing flow are being stored 70 */ 71 public KeyInfoResolutionContext(Collection<Credential> credentials) { 72 resolvedCredentials = Collections.unmodifiableCollection(credentials); 73 properties = new LazyMap<String, Object>(); 74 keyNames = new LazySet<String>(); 75 } 76 77 /** 78 * Gets the KeyInfo being processed. 79 * 80 * @return Returns the keyInfo. 81 */ 82 public KeyInfo getKeyInfo() { 83 return keyInfo; 84 } 85 86 /** 87 * Sets the KeyInfo being processed. 88 * 89 * @param newKeyInfo The keyInfo to set. 90 */ 91 public void setKeyInfo(KeyInfo newKeyInfo) { 92 keyInfo = newKeyInfo; 93 } 94 95 /** 96 * The key names which are currently known. 97 * 98 * These key names should be those which are known to be associated with the 99 * key represented by the KeyInfo being processed. These may have for example 100 * been directly extracted from KeyName elements present, or may have been 101 * inferred from the context in which the KeyInfo exists or is being used. 102 * 103 * @return the set of key names 104 * 105 * */ 106 public Set<String> getKeyNames() { 107 return keyNames; 108 } 109 110 /** 111 * Get the key currently known to be represented by the KeyInfo. 112 * 113 * @return the key currently known to be represented by the KeyInfo 114 * or null if not currently known 115 */ 116 public Key getKey() { 117 return key; 118 } 119 120 /** 121 * Set the key currently known to be represented by the KeyInfo. 122 * 123 * @param newKey the new Key 124 */ 125 public void setKey(Key newKey) { 126 key = newKey; 127 } 128 129 /** 130 * Get the set of credentials previously resolved. 131 * 132 * @return Returns the keyValueCredential. 133 */ 134 public Collection<Credential> getResolvedCredentials() { 135 return resolvedCredentials; 136 } 137 138 /** 139 * Get the extensible properties map. 140 * 141 * @return Returns the properties. 142 */ 143 public Map<String, Object> getProperties() { 144 return properties; 145 } 146 }