View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.client.console.rest;
20  
21  import java.io.IOException;
22  import java.io.InputStream;
23  import javax.ws.rs.core.MediaType;
24  import javax.ws.rs.core.Response;
25  import org.apache.cxf.jaxrs.client.WebClient;
26  import org.apache.syncope.client.console.SyncopeConsoleSession;
27  import org.apache.syncope.client.ui.commons.SAML2SP4UIConstants;
28  import org.apache.syncope.common.rest.api.service.SAML2SP4UIService;
29  import org.apache.wicket.util.io.IOUtils;
30  import org.apache.wicket.util.resource.AbstractResourceStream;
31  import org.apache.wicket.util.resource.IResourceStream;
32  import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
33  
34  public class SAML2SPRestClient extends BaseRestClient {
35  
36      private static final long serialVersionUID = -5084300184764037527L;
37  
38      public IResourceStream getMetadata(final String spEntityID) {
39          SAML2SP4UIService service = SyncopeConsoleSession.get().getAnonymousService(SAML2SP4UIService.class);
40          WebClient.client(service).accept(MediaType.APPLICATION_XML_TYPE).type(MediaType.APPLICATION_XML_TYPE);
41          Response metadataResponse = service.getMetadata(spEntityID, SAML2SP4UIConstants.URL_CONTEXT);
42          WebClient.client(service).reset();
43  
44          InputStream inputStream = (InputStream) metadataResponse.getEntity();
45  
46          return new AbstractResourceStream() {
47  
48              private static final long serialVersionUID = -2268011115723452312L;
49  
50              @Override
51              public InputStream getInputStream() throws ResourceStreamNotFoundException {
52                  return inputStream;
53              }
54  
55              @Override
56              public void close() throws IOException {
57                  IOUtils.closeQuietly(inputStream);
58              }
59          };
60      }
61  }