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.saml;
18  
19  import java.util.List;
20  
21  import org.opensaml.ws.security.SecurityPolicy;
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.provider.AbstractSAMLProfileConfiguration;
26  import edu.internet2.middleware.shibboleth.common.relyingparty.provider.CryptoOperationRequirementLevel;
27  
28  /**
29   * Base Spring factory bean for creating SAML profile configurations.
30   */
31  public abstract class AbstractSAMLProfileConfigurationFactoryBean extends AbstractFactoryBean {
32  
33      /** Audiences of issued assertions. */
34      private List<String> audiences;
35  
36      /** Amount of time before an issued assertion expires. */
37      private long assertionLifetime;
38  
39      /** 2-byte artifact type used for outbound messages. */
40      private byte[] outboundArtifactType;
41  
42      /** Whether assertions should be signed. */
43      private CryptoOperationRequirementLevel signAssertions;
44  
45      /** Whether to sign protocol requests. */
46      private CryptoOperationRequirementLevel signRequests;
47  
48      /** Whether to sign protocol responses. */
49      private CryptoOperationRequirementLevel signResponses;
50  
51      /** Credential used to sign assertions. */
52      private Credential signingCredential;
53      
54      /** Security policy for this profile. */
55      private SecurityPolicy profileSecurityPolicy;
56      
57      /**
58       * Gets the amount of time, in milliseconds, before an issued assertion expires. A negative value indicates the
59       * assertion never expires.
60       * 
61       * @return amount of time before an issued assertion expires
62       */
63      public long getAssertionLifetime() {
64          return assertionLifetime;
65      }
66      
67      /**
68       * Gets the audiences of issued assertions.
69       * 
70       * @return audiences of issued assertions
71       */
72      public List<String> getAudiences() {
73          return audiences;
74      }
75  
76      /**
77       * Gets the 2-byte artifact type used for outbound messages.
78       * 
79       * @return 2-byte artifact type used for outbound messages
80       */
81      public  byte[] getOutboundArtifactType() {
82          return outboundArtifactType;
83      }
84  
85      /**
86       * Gets the security policy for this profile.
87       * 
88       * @return security policy for this profile
89       */
90      public SecurityPolicy getProfileSecurityPolicy() {
91          return profileSecurityPolicy;
92      }
93  
94      /**
95       * Gets whether assertions should be signed.
96       * 
97       * @return whether assertions should be signed
98       */
99      public CryptoOperationRequirementLevel getSignAssertions() {
100         return signAssertions;
101     }
102 
103     /**
104      * Gets the credential used to sign assertions.
105      * 
106      * @return credential used to sign assertions
107      */
108     public Credential getSigningCredential() {
109         return signingCredential;
110     }
111 
112     /**
113      * Gets whether to sign protocol requests.
114      * 
115      * @return whether to sign protocol requests
116      */
117     public CryptoOperationRequirementLevel getSignRequests() {
118         return signRequests;
119     }
120 
121     /**
122      * Gets whether to sign protocol responses.
123      * 
124      * @return whether to sign protocol responses
125      */
126     public CryptoOperationRequirementLevel getSignResposnes() {
127         return signResponses;
128     }
129 
130     /**
131      * Sets the amount of time before an issued assertion expires.
132      * 
133      * @param lifetime amount of time before an issued assertion expires
134      */
135     public void setAssertionLifetime(long lifetime) {
136         assertionLifetime = lifetime;
137     }
138 
139     /**
140      * Sets the audiences of issued assertions.
141      * 
142      * @param newAudiences audiences of issued assertions
143      */
144     public void setAudiences(List<String> newAudiences) {
145         audiences = newAudiences;
146     }
147 
148     /**
149      * Sets the 2-byte artifact type used for outbound messages.
150      * 
151      * @param type 2-byte artifact type used for outbound messages
152      */
153     public void setOutboundArtifactType(byte[] type) {
154         outboundArtifactType = type;
155     }
156 
157     /**
158      * Sets the security policy for this profile.
159      * 
160      * @param policy security policy for this profile
161      */
162     public void setProfileSecurityPolicy(SecurityPolicy policy) {
163         profileSecurityPolicy = policy;
164     }
165 
166     /**
167      * Sets whether assertions should be signed.
168      * 
169      * @param sign whether assertions should be signed
170      */
171     public void setSignAssertions(CryptoOperationRequirementLevel sign) {
172         signAssertions = sign;
173     }
174 
175     /**
176      * Sets the credential used to sign assertions.
177      * 
178      * @param credential credential used to sign assertions
179      */
180     public void setSigningCredential(Credential credential) {
181         signingCredential = credential;
182     }
183 
184     /**
185      * Sets whether to sign protocol requests.
186      * 
187      * @param sign whether to sign protocol requests
188      */
189     public void setSignRequests(CryptoOperationRequirementLevel sign) {
190         signRequests = sign;
191     }
192 
193     /**
194      * Sets whether to sign protocol responses.
195      * 
196      * @param sign whether to sign protocol responses
197      */
198     public void setSignResponses(CryptoOperationRequirementLevel sign) {
199         signResponses = sign;
200     }
201     
202     /**
203      * Populates the given profile configuration with standard information.
204      * 
205      * @param configuration configuration to populate
206      */
207     protected void populateBean(AbstractSAMLProfileConfiguration configuration) {
208         configuration.setAssertionAudiences(getAudiences());
209         configuration.setAssertionLifetime(getAssertionLifetime());
210         configuration.setSecurityPolicy(getProfileSecurityPolicy());
211         configuration.setOutboundArtifactType(getOutboundArtifactType());
212         configuration.setSignRequests(getSignRequests());
213         configuration.setSignResponses(getSignResposnes());
214         configuration.setSignAssertions(getSignAssertions());
215         configuration.setSigningCredential(getSigningCredential());
216     }
217 }