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