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.config;
20
21 import java.util.Optional;
22 import org.apache.commons.lang3.StringUtils;
23 import org.apache.syncope.wa.bootstrap.WARestClient;
24 import org.apereo.cas.support.saml.idp.metadata.generator.SamlIdPMetadataGenerator;
25 import org.apereo.cas.support.saml.services.idp.metadata.SamlIdPMetadataDocument;
26 import org.apereo.cas.util.AsciiArtUtils;
27 import org.quartz.Job;
28 import org.quartz.JobExecutionContext;
29 import org.quartz.JobExecutionException;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.cloud.context.refresh.ContextRefresher;
34
35 public class WARefreshContextJob implements Job {
36
37 private static final Logger LOG = LoggerFactory.getLogger(WARefreshContextJob.class);
38
39 @Autowired
40 private WARestClient waRestClient;
41
42 @Autowired
43 private ContextRefresher contextRefresher;
44
45 @Autowired
46 private SamlIdPMetadataGenerator metadataGenerator;
47
48 @Override
49 public void execute(final JobExecutionContext jobExecutionContext) throws JobExecutionException {
50 try {
51 LOG.debug("Attempting to refresh WA application context");
52 if (!waRestClient.isReady()) {
53 LOG.debug("Syncope client is not yet ready");
54 throw new IllegalStateException("Syncope core is not yet ready to access requests");
55 }
56 contextRefresher.refresh();
57 LOG.info("Refreshed application context to bootstrap property sources, etc...");
58
59 LOG.info("Generating SAML2 IdP metadata metadata");
60 SamlIdPMetadataDocument document = metadataGenerator.generate(Optional.empty());
61 LOG.info("Generated SAML2 IdP metadata for {}", document.getAppliesTo());
62
63 advertiseReady();
64 } catch (final Exception e) {
65 throw new JobExecutionException("While generating SAML2 IdP metadata", e);
66 }
67 }
68
69 private static void advertiseReady() {
70 AsciiArtUtils.printAsciiArtReady(LOG, StringUtils.EMPTY);
71 LOG.info("Ready to process requests");
72 }
73 }