View Javadoc

1   /*
2    * Copyright [2006] [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 org.opensaml;
18  
19  import org.joda.time.chrono.ISOChronology;
20  import org.joda.time.format.DateTimeFormat;
21  import org.joda.time.format.DateTimeFormatter;
22  import org.opensaml.saml1.binding.artifact.SAML1ArtifactBuilderFactory;
23  import org.opensaml.saml2.binding.artifact.SAML2ArtifactBuilderFactory;
24  
25  /**
26   * OpenSAML configuration singleton.
27   * 
28   * The library must be initialized with a set of configurations prior to usage. This is often done by invoking
29   * {@link DefaultBootstrap#bootstrap()} but may done in any manner so long as all the needed object providers and
30   * artifact factory are created and registered with the configuration.
31   */
32  public class Configuration extends org.opensaml.xml.Configuration {
33  
34      /** Date format in SAML object, default is yyyy-MM-dd'T'HH:mm:ss.SSS'Z'. */
35      private static String defaultDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
36  
37      /** Formatter used to write dates. */
38      private static DateTimeFormatter dateFormatter;
39  
40      /** SAML 1 Artifact factory. */
41      private static SAML1ArtifactBuilderFactory saml1ArtifactBuilderFactory;
42  
43      /** SAML 2 Artifact factory. */
44      private static SAML2ArtifactBuilderFactory saml2ArtifactBuilderFactory;
45  
46      /**
47       * Gets the date format used to string'ify SAML's {@link org.joda.time.DateTime} objects.
48       * 
49       * @return date format used to string'ify date objects
50       */
51      public static DateTimeFormatter getSAMLDateFormatter() {
52          if (dateFormatter == null) {
53              DateTimeFormatter formatter = DateTimeFormat.forPattern(defaultDateFormat);
54              dateFormatter = formatter.withChronology(ISOChronology.getInstanceUTC());
55          }
56  
57          return dateFormatter;
58      }
59  
60      /**
61       * Sets the date format used to string'ify SAML's date/time objects.
62       * 
63       * See the
64       * {@link <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>}
65       * documentation for format syntax.
66       * 
67       * @param format date format used to string'ify date objects
68       */
69      public static void setSAMLDateFormat(String format) {
70          DateTimeFormatter formatter = DateTimeFormat.forPattern(format);
71          dateFormatter = formatter.withChronology(ISOChronology.getInstanceUTC());
72      }
73  
74      /**
75       * Gets the artifact factory for the library.
76       * 
77       * @return artifact factory for the library
78       */
79      public static SAML1ArtifactBuilderFactory getSAML1ArtifactBuilderFactory() {
80          return saml1ArtifactBuilderFactory;
81      }
82  
83      /**
84       * Sets the artifact factory for the library.
85       * 
86       * @param factory artifact factory for the library
87       */
88      public static void setSAML1ArtifactBuilderFactory(SAML1ArtifactBuilderFactory factory) {
89          saml1ArtifactBuilderFactory = factory;
90      }
91  
92      /**
93       * Gets the artifact factory for the library.
94       * 
95       * @return artifact factory for the library
96       */
97      public static SAML2ArtifactBuilderFactory getSAML2ArtifactBuilderFactory() {
98          return saml2ArtifactBuilderFactory;
99      }
100 
101     /**
102      * Sets the artifact factory for the library.
103      * 
104      * @param factory artifact factory for the library
105      */
106     public static void setSAML2ArtifactBuilderFactory(SAML2ArtifactBuilderFactory factory) {
107         saml2ArtifactBuilderFactory = factory;
108     }
109 }