View Javadoc

1   /*
2    * Copyright [2005] [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  /**
18   * 
19   */
20  
21  package org.opensaml.saml2.metadata.impl;
22  
23  import java.util.ArrayList;
24  import java.util.Collections;
25  import java.util.List;
26  
27  import javax.xml.namespace.QName;
28  
29  import org.opensaml.saml2.metadata.AssertionConsumerService;
30  import org.opensaml.saml2.metadata.AttributeConsumingService;
31  import org.opensaml.saml2.metadata.Endpoint;
32  import org.opensaml.saml2.metadata.SPSSODescriptor;
33  import org.opensaml.xml.XMLObject;
34  import org.opensaml.xml.schema.XSBooleanValue;
35  import org.opensaml.xml.util.XMLObjectChildrenList;
36  
37  /**
38   * Concrete implementation of {@link org.opensaml.saml2.metadata.SPSSODescriptor}.
39   */
40  public class SPSSODescriptorImpl extends SSODescriptorImpl implements SPSSODescriptor {
41  
42      /** value for isAuthnRequestSigned attribute. */
43      private XSBooleanValue authnRequestSigned;
44  
45      /** value for the want assertion signed attribute. */
46      private XSBooleanValue assertionSigned;
47  
48      /** AssertionConsumerService children. */
49      private final XMLObjectChildrenList<AssertionConsumerService> assertionConsumerServices;
50  
51      /** AttributeConsumingService children. */
52      private final XMLObjectChildrenList<AttributeConsumingService> attributeConsumingServices;
53  
54      /**
55       * Constructor.
56       * 
57       * @param namespaceURI the namespace the element is in
58       * @param elementLocalName the local name of the XML element this Object represents
59       * @param namespacePrefix the prefix for the given namespace
60       */
61      protected SPSSODescriptorImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
62          super(namespaceURI, elementLocalName, namespacePrefix);
63          assertionConsumerServices = new XMLObjectChildrenList<AssertionConsumerService>(this);
64          attributeConsumingServices = new XMLObjectChildrenList<AttributeConsumingService>(this);
65      }
66      
67      /** {@inheritDoc} */
68      public Boolean isAuthnRequestsSigned() {
69          if (authnRequestSigned == null) {
70              return Boolean.FALSE;
71          }
72          return authnRequestSigned.getValue();
73      }
74  
75      /** {@inheritDoc} */
76      public XSBooleanValue isAuthnRequestsSignedXSBoolean() {
77          return authnRequestSigned;
78      }
79      
80      /** {@inheritDoc} */
81      public void setAuthnRequestsSigned(Boolean newIsSigned) {
82          if(newIsSigned != null){
83              authnRequestSigned = prepareForAssignment(authnRequestSigned, new XSBooleanValue(newIsSigned, false));
84          }else{
85              authnRequestSigned = prepareForAssignment(authnRequestSigned, null);
86          }
87      }
88  
89      /** {@inheritDoc} */
90      public void setAuthnRequestsSigned(XSBooleanValue isSigned) {
91          authnRequestSigned = prepareForAssignment(authnRequestSigned, isSigned);
92      }
93      
94      /** {@inheritDoc} */
95      public Boolean getWantAssertionsSigned() {
96          if (assertionSigned == null) {
97              return Boolean.FALSE;
98          }
99          return assertionSigned.getValue();
100     }
101 
102     /** {@inheritDoc} */
103     public XSBooleanValue getWantAssertionsSignedXSBoolean() {
104         return assertionSigned;
105     }
106     
107     /** {@inheritDoc} */
108     public void setWantAssertionsSigned(Boolean wantAssestionSigned) {
109         if(wantAssestionSigned != null){
110             assertionSigned = prepareForAssignment(assertionSigned, new XSBooleanValue(wantAssestionSigned, false));
111         }else{
112             assertionSigned = prepareForAssignment(assertionSigned, null);
113         }
114     }
115 
116     /** {@inheritDoc} */
117     public void setWantAssertionsSigned(XSBooleanValue wantAssestionSigned) {
118         this.assertionSigned = prepareForAssignment(this.assertionSigned, wantAssestionSigned);
119     }
120 
121     /** {@inheritDoc} */
122     public List<AssertionConsumerService> getAssertionConsumerServices() {
123         return assertionConsumerServices;
124     }
125     
126     /** {@inheritDoc} */
127     public AssertionConsumerService getDefaultAssertionConsumerService() {
128         for (AssertionConsumerService service : assertionConsumerServices) {
129             if (service.isDefault()) {
130                 return service;
131             }
132         }
133 
134         if (assertionConsumerServices.size() > 0) {
135             return assertionConsumerServices.get(0);
136         } else {
137             System.err.println("FOOBAR");
138         }
139 
140         return null;
141     }
142 
143     /** {@inheritDoc} */
144     public List<AttributeConsumingService> getAttributeConsumingServices() {
145         return attributeConsumingServices;
146     }
147     
148     /** {@inheritDoc} */
149     public AttributeConsumingService getDefaultAttributeConsumingService(){
150         for(AttributeConsumingService service : attributeConsumingServices){
151             if(service.isDefault()){
152                 return service;
153             }
154         }
155         
156         return null;
157     }
158     
159     /** {@inheritDoc} */
160     public List<Endpoint> getEndpoints() {
161         List<Endpoint> endpoints = new ArrayList<Endpoint>();
162         endpoints.addAll(super.getEndpoints());
163         endpoints.addAll(assertionConsumerServices);
164         return Collections.unmodifiableList(endpoints);
165     }
166     
167     /** {@inheritDoc} */
168     public List<Endpoint> getEndpoints(QName type) {
169         if(type.equals(AssertionConsumerService.DEFAULT_ELEMENT_NAME)){
170             return Collections.unmodifiableList(new ArrayList<Endpoint>(assertionConsumerServices));
171         }else{
172             return super.getEndpoints(type);
173         }
174     }
175 
176     /** {@inheritDoc} */
177     public List<XMLObject> getOrderedChildren() {
178         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
179 
180         children.addAll(super.getOrderedChildren());
181         children.addAll(assertionConsumerServices);
182         children.addAll(attributeConsumingServices);
183 
184         return Collections.unmodifiableList(children);
185     }
186 }