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.ArtifactResolutionService;
30  import org.opensaml.saml2.metadata.Endpoint;
31  import org.opensaml.saml2.metadata.ManageNameIDService;
32  import org.opensaml.saml2.metadata.NameIDFormat;
33  import org.opensaml.saml2.metadata.SSODescriptor;
34  import org.opensaml.saml2.metadata.SingleLogoutService;
35  import org.opensaml.xml.XMLObject;
36  import org.opensaml.xml.util.XMLObjectChildrenList;
37  
38  /**
39   * Concrete implementation of {@link org.opensaml.saml2.metadata.SSODescriptor}.
40   */
41  public abstract class SSODescriptorImpl extends RoleDescriptorImpl implements SSODescriptor {
42  
43      /** Supported artifact resolutions services. */
44      private final XMLObjectChildrenList<ArtifactResolutionService> artifactResolutionServices;
45  
46      /** Logout services for this SSO entity. */
47      private final XMLObjectChildrenList<SingleLogoutService> singleLogoutServices;
48  
49      /** Manage NameID services for this entity. */
50      private final XMLObjectChildrenList<ManageNameIDService> manageNameIDServices;
51  
52      /** NameID formats supported by this entity. */
53      private final XMLObjectChildrenList<NameIDFormat> nameIDFormats;
54      
55      /**
56       * Constructor.
57       * 
58       * @param namespaceURI the namespace the element is in
59       * @param elementLocalName the local name of the XML element this Object represents
60       * @param namespacePrefix the prefix for the given namespace
61       */
62      protected SSODescriptorImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
63          super(namespaceURI, elementLocalName, namespacePrefix);
64          artifactResolutionServices = new XMLObjectChildrenList<ArtifactResolutionService>(this);
65          singleLogoutServices = new XMLObjectChildrenList<SingleLogoutService>(this);
66          manageNameIDServices = new XMLObjectChildrenList<ManageNameIDService>(this);
67          nameIDFormats = new XMLObjectChildrenList<NameIDFormat>(this);
68      }
69  
70      /** {@inheritDoc} */
71      public List<ArtifactResolutionService> getArtifactResolutionServices() {
72          return artifactResolutionServices;
73      }
74      
75      /** {@inheritDoc} */
76      public ArtifactResolutionService getDefaultArtificateResolutionService(){
77          for(ArtifactResolutionService service : artifactResolutionServices){
78              if(service.isDefault()){
79                  return service;
80              }
81          }
82          
83          return null;
84      }
85  
86      /** {@inheritDoc} */
87      public List<SingleLogoutService> getSingleLogoutServices() {
88          return singleLogoutServices;
89      }
90  
91      /** {@inheritDoc} */
92      public List<ManageNameIDService> getManageNameIDServices() {
93          return manageNameIDServices;
94      }
95  
96      /** {@inheritDoc} */
97      public List<NameIDFormat> getNameIDFormats() {
98          return nameIDFormats;
99      }
100     
101     /** {@inheritDoc} */
102     public List<Endpoint> getEndpoints() {
103         List<Endpoint> endpoints = new ArrayList<Endpoint>();
104         endpoints.addAll(artifactResolutionServices);
105         endpoints.addAll(singleLogoutServices);
106         endpoints.addAll(manageNameIDServices);
107         return Collections.unmodifiableList(endpoints);
108     }
109     
110     /** {@inheritDoc} */
111     public List<Endpoint> getEndpoints(QName type) {
112         if(type.equals(ArtifactResolutionService.DEFAULT_ELEMENT_NAME)){
113             return Collections.unmodifiableList(new ArrayList<Endpoint>(artifactResolutionServices));
114         }else if(type.equals(SingleLogoutService.DEFAULT_ELEMENT_NAME)){
115             return Collections.unmodifiableList(new ArrayList<Endpoint>(singleLogoutServices));
116         }else if(type.equals(ManageNameIDService.DEFAULT_ELEMENT_NAME)){
117             return Collections.unmodifiableList(new ArrayList<Endpoint>(manageNameIDServices));
118         }
119         
120         return null;
121     }
122     
123     /** {@inheritDoc} */
124     public List<XMLObject> getOrderedChildren() {
125         ArrayList<XMLObject> children = new ArrayList<XMLObject>();
126         
127         children.addAll(super.getOrderedChildren());
128         children.addAll(artifactResolutionServices);
129         children.addAll(singleLogoutServices);
130         children.addAll(manageNameIDServices);
131         children.addAll(nameIDFormats);
132         
133         return Collections.unmodifiableList(children);
134     }
135 }