View Javadoc

1   /*
2    * Licensed to the University Corporation for Advanced Internet Development, 
3    * Inc. (UCAID) under one or more contributor license agreements.  See the 
4    * NOTICE file distributed with this work for additional information regarding
5    * copyright ownership. The UCAID licenses this file to You under the Apache 
6    * License, Version 2.0 (the "License"); you may not use this file except in 
7    * compliance with the License.  You may obtain a copy of the License at
8    *
9    *    http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package edu.internet2.middleware.shibboleth.common.relyingparty;
19  
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import org.opensaml.xml.security.credential.Credential;
24  import org.opensaml.xml.util.DatatypeHelper;
25  
26  /**
27   * A set of configuration options for a relying party.
28   */
29  public class RelyingPartyConfiguration {
30  
31      /** Entity ID of the relying party. */
32      private String relyingPartyId;
33  
34      /** Entity ID of the responder when communicating with the relying party. */
35      private String providerId;
36  
37      /** Authentication method to use if none is specified within a request. */
38      private String defaultAuthenticationMethod;
39  
40      /** Default signing credential. */
41      private Credential signingCredential;
42  
43      /** Precedence ordering of NameID formats for this relying party. */
44      private String[] nameIdFormatPrecedence;
45  
46      /** Various profile configurations. */
47      private HashMap<String, ProfileConfiguration> profiles;
48  
49      /**
50       * Constructor.
51       * 
52       * @param provider entity ID of the responder when communicating with the relying party
53       */
54      public RelyingPartyConfiguration(String provider) {
55          setProviderId(provider);
56          profiles = new HashMap<String, ProfileConfiguration>();
57      }
58  
59      /**
60       * Constructor.
61       * 
62       * @param relyingParty ID of the relying party this configuration is for
63       * @param provider entity ID of the responder when communicating with the relying party
64       */
65      public RelyingPartyConfiguration(String relyingParty, String provider) {
66          setRelyingPartyId(relyingParty);
67          setProviderId(provider);
68          profiles = new HashMap<String, ProfileConfiguration>();
69      }
70  
71      /**
72       * Gets the precedence of NameID formats for this relying party.
73       * 
74       * @return precedence of NameID formats for this relying party
75       */
76      public String[] getNameIdFormatPrecedence() {
77          return nameIdFormatPrecedence;
78      }
79  
80      /**
81       * Sets the precedence of NameID formats for this relying party.
82       * 
83       * @param precedence precedence of NameID formats for this relying party
84       */
85      public void setNameIdFormatPrecedence(String[] precedence) {
86          nameIdFormatPrecedence = precedence;
87      }
88  
89      /**
90       * Gets the entity ID of the relying party this configuration is for.
91       * 
92       * @return the entity ID of the relying party this configuration is for
93       */
94      public String getRelyingPartyId() {
95          return relyingPartyId;
96      }
97  
98      /**
99       * Sets the entity ID of the relying party this configuration is for.
100      * 
101      * @param id entity ID of the relying party this configuration is for
102      */
103     protected void setRelyingPartyId(String id) {
104         relyingPartyId = DatatypeHelper.safeTrimOrNullString(id);
105     }
106 
107     /**
108      * Gets the entity ID of the responder when communicating with the relying party.
109      * 
110      * @return entity ID of the responder when communicating with the relying party
111      */
112     public String getProviderId() {
113         return providerId;
114     }
115 
116     /**
117      * Sets the entity ID of the responder when communicating with the relying party.
118      * 
119      * @param id entity ID of the responder when communicating with the relying party
120      */
121     protected void setProviderId(String id) {
122         providerId = DatatypeHelper.safeTrimOrNullString(id);
123     }
124 
125     /**
126      * Gets the authentication method to use if one is not specified within a request.
127      * 
128      * @return authentication method to use if one is not specified within a request
129      */
130     public String getDefaultAuthenticationMethod() {
131         return defaultAuthenticationMethod;
132     }
133 
134     /**
135      * Sets the authentication method to use if one is not specified within a request.
136      * 
137      * @param method authentication method to use if one is not specified within a request
138      */
139     public void setDefaultAuthenticationMethod(String method) {
140         defaultAuthenticationMethod = method;
141     }
142 
143     /**
144      * Gets the default signing credential for the relying party. This is provided as a convenience method so that this
145      * credential need not be defined on every signing supporting profile configuration. If a profile configuration has
146      * a defined signing credential it must be used in place of the credential retrieved here.
147      * 
148      * @return default signing credential for the relying party
149      */
150     public Credential getDefaultSigningCredential() {
151         return signingCredential;
152     }
153 
154     /**
155      * Sets the default signing credential for the relying party.
156      * 
157      * @param credential default signing credential for the relying party
158      */
159     public void setDefaultSigningCredential(Credential credential) {
160         signingCredential = credential;
161     }
162 
163     /**
164      * Gets whether assertions should be encrypted.
165      * 
166      * @return configuration for specific communication profiles used by the system indexed by profile ID
167      */
168     public Map<String, ProfileConfiguration> getProfileConfigurations() {
169         return profiles;
170     }
171 
172     /**
173      * Convenience method for retrieving a given profile configuration from the {@link Map} returned by
174      * {@link #getProfileConfigurations()}.
175      * 
176      * @param profileId unique Id of the profile
177      * 
178      * @return the profile configuration or null
179      */
180     public ProfileConfiguration getProfileConfiguration(String profileId) {
181         if (profiles != null) {
182             return profiles.get(profileId);
183         }
184 
185         return null;
186     }
187 }