View Javadoc

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      /** Precedence ordering of NameID formats for this relying party. */
43      private String[] nameIdFormatPrecedence;
44  
45      /** Various profile configurations. */
46      private HashMap<String, ProfileConfiguration> profiles;
47  
48      /**
49       * Constructor.
50       * 
51       * @param provider entity ID of the responder when communicating with the relying party
52       */
53      public RelyingPartyConfiguration(String provider) {
54          setProviderId(provider);
55          profiles = new HashMap<String, ProfileConfiguration>();
56      }
57  
58      /**
59       * Constructor.
60       * 
61       * @param relyingParty ID of the relying party this configuration is for
62       * @param provider entity ID of the responder when communicating with the relying party
63       */
64      public RelyingPartyConfiguration(String relyingParty, String provider) {
65          setRelyingPartyId(relyingParty);
66          setProviderId(provider);
67          profiles = new HashMap<String, ProfileConfiguration>();
68      }
69  
70      /**
71       * Gets the precedence of NameID formats for this relying party.
72       * 
73       * @return precedence of NameID formats for this relying party
74       */
75      public String[] getNameIdFormatPrecedence() {
76          return nameIdFormatPrecedence;
77      }
78  
79      /**
80       * Sets the precedence of NameID formats for this relying party.
81       * 
82       * @param precedence precedence of NameID formats for this relying party
83       */
84      public void setNameIdFormatPrecedence(String[] precedence) {
85          nameIdFormatPrecedence = precedence;
86      }
87  
88      /**
89       * Gets the entity ID of the relying party this configuration is for.
90       * 
91       * @return the entity ID of the relying party this configuration is for
92       */
93      public String getRelyingPartyId() {
94          return relyingPartyId;
95      }
96  
97      /**
98       * Sets the entity ID of the relying party this configuration is for.
99       * 
100      * @param id entity ID of the relying party this configuration is for
101      */
102     protected void setRelyingPartyId(String id) {
103         relyingPartyId = DatatypeHelper.safeTrimOrNullString(id);
104     }
105 
106     /**
107      * Gets the entity ID of the responder when communicating with the relying party.
108      * 
109      * @return entity ID of the responder when communicating with the relying party
110      */
111     public String getProviderId() {
112         return providerId;
113     }
114 
115     /**
116      * Sets the entity ID of the responder when communicating with the relying party.
117      * 
118      * @param id entity ID of the responder when communicating with the relying party
119      */
120     protected void setProviderId(String id) {
121         providerId = DatatypeHelper.safeTrimOrNullString(id);
122     }
123 
124     /**
125      * Gets the authentication method to use if one is not specified within a request.
126      * 
127      * @return authentication method to use if one is not specified within a request
128      */
129     public String getDefaultAuthenticationMethod() {
130         return defaultAuthenticationMethod;
131     }
132 
133     /**
134      * Sets the authentication method to use if one is not specified within a request.
135      * 
136      * @param method authentication method to use if one is not specified within a request
137      */
138     public void setDefaultAuthenticationMethod(String method) {
139         defaultAuthenticationMethod = method;
140     }
141 
142     /**
143      * Gets the default signing credential for the relying party. This is provided as a convenience method so that this
144      * credential need not be defined on every signing supporting profile configuration. If a profile configuration has
145      * a defined signing credential it must be used in place of the credential retrieved here.
146      * 
147      * @return default signing credential for the relying party
148      */
149     public Credential getDefaultSigningCredential() {
150         return signingCredential;
151     }
152 
153     /**
154      * Sets the default signing credential for the relying party.
155      * 
156      * @param credential default signing credential for the relying party
157      */
158     public void setDefaultSigningCredential(Credential credential) {
159         signingCredential = credential;
160     }
161 
162     /**
163      * Gets whether assertions should be encrypted.
164      * 
165      * @return configuration for specific communication profiles used by the system indexed by profile ID
166      */
167     public Map<String, ProfileConfiguration> getProfileConfigurations() {
168         return profiles;
169     }
170 
171     /**
172      * Convenience method for retrieving a given profile configuration from the {@link Map} returned by
173      * {@link #getProfileConfigurations()}.
174      * 
175      * @param profileId unique Id of the profile
176      * 
177      * @return the profile configuration or null
178      */
179     public ProfileConfiguration getProfileConfiguration(String profileId) {
180         if (profiles != null) {
181             return profiles.get(profileId);
182         }
183 
184         return null;
185     }
186 }