1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.wa.starter.pac4j.saml;
20
21 import java.util.Base64;
22 import net.shibboleth.utilities.java.support.resolver.ResolverException;
23 import org.apache.syncope.common.lib.to.SAML2SPEntityTO;
24 import org.apache.syncope.common.rest.api.service.SAML2SPEntityService;
25 import org.apache.syncope.wa.bootstrap.WARestClient;
26 import org.opensaml.saml.metadata.resolver.impl.AbstractReloadingMetadataResolver;
27 import org.pac4j.saml.client.SAML2Client;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class WASAML2MetadataResolver extends AbstractReloadingMetadataResolver {
32
33 protected static final Logger LOG = LoggerFactory.getLogger(WASAML2MetadataResolver.class);
34
35 protected final WARestClient waRestClient;
36
37 protected final SAML2Client saml2Client;
38
39 public WASAML2MetadataResolver(final WARestClient waRestClient, final SAML2Client saml2Client) {
40 this.waRestClient = waRestClient;
41 this.saml2Client = saml2Client;
42 }
43
44 @Override
45 protected String getMetadataIdentifier() {
46 return saml2Client.getName();
47 }
48
49 @Override
50 protected byte[] fetchMetadata() throws ResolverException {
51 try {
52 SAML2SPEntityTO metadataTO = waRestClient.getService(SAML2SPEntityService.class).get(saml2Client.getName());
53 return Base64.getDecoder().decode(metadataTO.getMetadata());
54 } catch (Exception e) {
55 String message = "Unable to fetch SP metadata for " + saml2Client.getName();
56 LOG.error(message, e);
57 throw new ResolverException(message);
58 }
59 }
60 }