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.config.relyingparty;
18  
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.opensaml.xml.security.credential.Credential;
23  import org.springframework.beans.factory.config.AbstractFactoryBean;
24  
25  import edu.internet2.middleware.shibboleth.common.relyingparty.ProfileConfiguration;
26  import edu.internet2.middleware.shibboleth.common.relyingparty.RelyingPartyConfiguration;
27  
28  /**
29   * Relying party configuration factory bean.
30   */
31  public class RelyingPartyFactoryBean extends AbstractFactoryBean {
32      
33      /** ID of the relying party. */
34      private String relyingPartyId;
35  
36      /** ID of the provider to use for this relying party. */
37      private String providerId;
38      
39      /** Authentication method to use if none is specified within a request. */
40      private String defaultAuthenticationMethod;
41  
42      /** The default signing credential for this relying party. */
43      private Credential defaultSigningCredential;
44  
45      /** Precedence ordering of NameID formats for this relying party. */
46      private List<String> nameIdFormatPrecedence;
47      
48      /** Registered profile configurations. */
49      private List<ProfileConfiguration> profileConfigurations;
50  
51      /** {@inheritDoc} */
52      public Class getObjectType() {
53          return RelyingPartyConfiguration.class;
54      }
55      
56      /**
57       * Gets the ID of the relying party.
58       * 
59       * @return ID of the provider to use for this relying party
60       */
61      public String getRelyingPartyId() {
62          return relyingPartyId;
63      }
64  
65      /**
66       * Sets the ID of the relying party.
67       * 
68       * @param id ID of the relying party
69       */
70      public void setRelyingPartyId(String id) {
71          relyingPartyId = id;
72      }
73  
74      /**
75       * Gets the ID of the provider to use for this relying party.
76       * 
77       * @return ID of the provider to use for this relying party
78       */
79      public String getProviderId() {
80          return providerId;
81      }
82  
83      /**
84       * Sets the ID of the provider to use for this relying party.
85       * 
86       * @param id ID of the provider to use for this relying party
87       */
88      public void setProviderId(String id) {
89          providerId = id;
90      }
91      
92      /**
93       * Gets the authentication method to use if one is not specified within a request.
94       * 
95       * @return authentication method to use if one is not specified within a request
96       */
97      public String getDefaultAuthenticationMethod() {
98          return defaultAuthenticationMethod;
99      }
100 
101     /**
102      * Sets the authentication method to use if one is not specified within a request.
103      * 
104      * @param method authentication method to use if one is not specified within a request
105      */
106     public void setDefaultAuthenticationMethod(String method) {
107         defaultAuthenticationMethod = method;
108     }
109 
110     /**
111      * Gets the default signing credential for this relying party.
112      * 
113      * @return default signing credential for this relying party
114      */
115     public Credential getDefaultSigningCredential() {
116         return defaultSigningCredential;
117     }
118 
119     /**
120      * Sets the default signing credential for this relying party.
121      * 
122      * @param credential default signing credential for this relying party
123      */
124     public void setDefaultSigningCredential(Credential credential) {
125         defaultSigningCredential = credential;
126     }
127     
128     /**
129      * Gets the precedence of NameID formats for this relying party.
130      * 
131      * @return precedence of NameID formats for this relying party
132      */
133     public List<String> getNameIdFormatPrecedence() {
134         return nameIdFormatPrecedence;
135     }
136 
137     /**
138      * Sets the precedence of NameID formats for this relying party.
139      * 
140      * @param precedence precedence of NameID formats for this relying party
141      */
142     public void setNameIdFormatPrecedence(List<String> precedence) {
143         nameIdFormatPrecedence = precedence;
144     }
145 
146     /**
147      * Gets the registered profile configurations.
148      * 
149      * @return registered profile configurations
150      */
151     public List<ProfileConfiguration> getProfileConfigurations() {
152         return profileConfigurations;
153     }
154 
155     /**
156      * Sets the registered profile configurations.
157      * 
158      * @param configurations registered profile configurations
159      */
160     public void setProfileConfigurations(List<ProfileConfiguration> configurations) {
161         profileConfigurations = configurations;
162     }
163 
164     /** {@inheritDoc} */
165     protected Object createInstance() throws Exception {
166         RelyingPartyConfiguration configuration = new RelyingPartyConfiguration(relyingPartyId, providerId);
167         configuration.setDefaultAuthenticationMethod(defaultAuthenticationMethod);
168         configuration.setDefaultSigningCredential(defaultSigningCredential);
169         if(nameIdFormatPrecedence != null && !nameIdFormatPrecedence.isEmpty()){
170             configuration.setNameIdFormatPrecedence(nameIdFormatPrecedence.toArray(new String[nameIdFormatPrecedence.size()]));
171         }
172 
173         if (profileConfigurations != null) {
174             Map<String, ProfileConfiguration> registeredProfileConfigs = configuration.getProfileConfigurations();
175             for (ProfileConfiguration profileConfig : profileConfigurations) {
176                 registeredProfileConfigs.put(profileConfig.getProfileId(), profileConfig);
177             }
178         }
179 
180         return configuration;
181     }
182 }