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 edu.internet2.middleware.shibboleth.common.relyingparty; 18 19 import java.util.HashMap; 20 import java.util.Map; 21 22 import org.opensaml.xml.security.credential.Credential; 23 import org.opensaml.xml.util.DatatypeHelper; 24 25 /** 26 * A set of configuration options for a relying party. 27 */ 28 public class RelyingPartyConfiguration { 29 30 /** Entity ID of the relying party. */ 31 private String relyingPartyId; 32 33 /** Entity ID of the responder when communicating with the relying party. */ 34 private String providerId; 35 36 /** Authentication method to use if none is specified within a request. */ 37 private String defaultAuthenticationMethod; 38 39 /** Default signing credential. */ 40 private Credential signingCredential; 41 42 /** Various profile configurations. */ 43 private HashMap<String, ProfileConfiguration> profiles; 44 45 /** 46 * Constructor. 47 * 48 * @param provider entity ID of the responder when communicating with the relying party 49 */ 50 public RelyingPartyConfiguration(String provider) { 51 setProviderId(provider); 52 profiles = new HashMap<String, ProfileConfiguration>(); 53 } 54 55 /** 56 * Constructor. 57 * 58 * @param relyingParty ID of the relying party this configuration is for 59 * @param provider entity ID of the responder when communicating with the relying party 60 */ 61 public RelyingPartyConfiguration(String relyingParty, String provider) { 62 setRelyingPartyId(relyingParty); 63 setProviderId(provider); 64 profiles = new HashMap<String, ProfileConfiguration>(); 65 } 66 67 /** 68 * Gets the entity ID of the relying party this configuration is for. 69 * 70 * @return the entity ID of the relying party this configuration is for 71 */ 72 public String getRelyingPartyId() { 73 return relyingPartyId; 74 } 75 76 /** 77 * Sets the entity ID of the relying party this configuration is for. 78 * 79 * @param id entity ID of the relying party this configuration is for 80 */ 81 protected void setRelyingPartyId(String id) { 82 relyingPartyId = DatatypeHelper.safeTrimOrNullString(id); 83 } 84 85 /** 86 * Gets the entity ID of the responder when communicating with the relying party. 87 * 88 * @return entity ID of the responder when communicating with the relying party 89 */ 90 public String getProviderId() { 91 return providerId; 92 } 93 94 /** 95 * Sets the entity ID of the responder when communicating with the relying party. 96 * 97 * @param id entity ID of the responder when communicating with the relying party 98 */ 99 protected void setProviderId(String id) { 100 providerId = DatatypeHelper.safeTrimOrNullString(id); 101 } 102 103 /** 104 * Gets the authentication method to use if one is not specified within a request. 105 * 106 * @return authentication method to use if one is not specified within a request 107 */ 108 public String getDefaultAuthenticationMethod() { 109 return defaultAuthenticationMethod; 110 } 111 112 /** 113 * Sets the authentication method to use if one is not specified within a request. 114 * 115 * @param method authentication method to use if one is not specified within a request 116 */ 117 public void setDefaultAuthenticationMethod(String method) { 118 defaultAuthenticationMethod = method; 119 } 120 121 /** 122 * Gets the default signing credential for the relying party. This is provided as a convenience method so that this 123 * credential need not be defined on every signing supporting profile configuration. If a profile configuration has 124 * a defined signing credential it must be used in place of the credential retrieved here. 125 * 126 * @return default signing credential for the relying party 127 */ 128 public Credential getDefaultSigningCredential() { 129 return signingCredential; 130 } 131 132 /** 133 * Sets the default signing credential for the relying party. 134 * 135 * @param credential default signing credential for the relying party 136 */ 137 public void setDefaultSigningCredential(Credential credential) { 138 signingCredential = credential; 139 } 140 141 /** 142 * Gets whether assertions should be encrypted. 143 * 144 * @return configuration for specific communication profiles used by the system indexed by profile ID 145 */ 146 public Map<String, ProfileConfiguration> getProfileConfigurations() { 147 return profiles; 148 } 149 150 /** 151 * Convenience method for retrieving a given profile configuration from the {@link Map} returned by 152 * {@link #getProfileConfigurations()}. 153 * 154 * @param profileId unique Id of the profile 155 * 156 * @return the profile configuration or null 157 */ 158 public ProfileConfiguration getProfileConfiguration(String profileId) { 159 if (profiles != null) { 160 return profiles.get(profileId); 161 } 162 163 return null; 164 } 165 }