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.security; 18 19 import java.util.List; 20 21 import org.opensaml.saml2.metadata.EncryptionMethod; 22 import org.opensaml.saml2.metadata.KeyDescriptor; 23 import org.opensaml.saml2.metadata.RoleDescriptor; 24 import org.opensaml.xml.security.credential.CredentialContext; 25 26 /** 27 * A credential context for credentials resolved from a {@link org.opensaml.xml.signature.KeyInfo} that was found in 28 * SAML 2 metadata. 29 */ 30 public class SAMLMDCredentialContext implements CredentialContext { 31 32 /** Key descriptor which contained the KeyInfo used. */ 33 private KeyDescriptor keyDescriptor; 34 35 /** Role in which credential was resolved. */ 36 private RoleDescriptor role; 37 38 /** Encryption methods associated with the credential. */ 39 private List<EncryptionMethod> encMethods; 40 41 /** 42 * Constructor. 43 * 44 * @param descriptor the KeyDescriptor context from which a credential was resolved 45 */ 46 public SAMLMDCredentialContext(KeyDescriptor descriptor) { 47 keyDescriptor = descriptor; 48 if (descriptor != null) { 49 // KeyDescriptor / EncryptionMethod 50 encMethods = descriptor.getEncryptionMethods(); 51 // KeyDescriptor -> RoleDescriptor 52 role = (RoleDescriptor) descriptor.getParent(); 53 } 54 } 55 56 /** 57 * Get the key descriptor context. 58 * 59 * @return key descriptor 60 */ 61 public KeyDescriptor getKeyDescriptor() { 62 return keyDescriptor; 63 } 64 65 /** 66 * Return the list of {@link EncryptionMethod}'s associated with credential context. 67 * 68 * @return a list of SAML metadata encryption method associated with this context 69 */ 70 public List<EncryptionMethod> getEncryptionMethod() { 71 return encMethods; 72 } 73 74 /** 75 * Get the role descriptor context. 76 * 77 * @return role descriptor 78 */ 79 public RoleDescriptor getRoleDescriptor() { 80 return role; 81 } 82 83 }