use of org.apache.syncope.core.spring.ResourceWithFallbackLoader in project syncope by apache.
the class SAML2SPLoader method load.
@Override
public void load() {
EntitlementsHolder.getInstance().init(SAML2SPEntitlement.values());
Pair<Properties, String> init = PropertyUtils.read(getClass(), SAML2SP_LOGIC_PROPERTIES, "conf.directory");
Properties props = init.getLeft();
String confDirectory = init.getRight();
assertNotNull(confDirectory, "<conf.directory>");
String name = props.getProperty("keystore.name");
assertNotNull(name, "<keystore.name>");
String type = props.getProperty("keystore.type");
assertNotNull(type, "<keystore.type>");
String storePass = props.getProperty("keystore.storepass");
assertNotNull(storePass, "<keystore.storepass>");
keyPass = props.getProperty("keystore.keypass");
assertNotNull(keyPass, "<keystore.keypass>");
String certAlias = props.getProperty("sp.cert.alias");
assertNotNull(certAlias, "<sp.cert.alias>");
signatureAlgorithm = props.getProperty("signature.algorithm");
LOG.debug("Attempting to load the provided keystore...");
try {
ResourceWithFallbackLoader loader = new ResourceWithFallbackLoader();
loader.setResourceLoader(ApplicationContextProvider.getApplicationContext());
loader.setPrimary(StringUtils.appendIfMissing("file:" + confDirectory, "/") + name);
loader.setFallback("classpath:" + name);
keystore = KeyStore.getInstance(type);
try (InputStream inputStream = loader.getResource().getInputStream()) {
keystore.load(inputStream, storePass.toCharArray());
LOG.debug("Keystore loaded");
}
Map<String, String> passwordMap = new HashMap<>();
passwordMap.put(certAlias, keyPass);
KeyStoreCredentialResolver resolver = new KeyStoreCredentialResolver(keystore, passwordMap);
this.credential = resolver.resolveSingle(new CriteriaSet(new EntityIdCriterion(certAlias)));
LOG.debug("SAML 2.0 Service Provider certificate loaded");
saml2rw.init();
inited = true;
} catch (Exception e) {
LOG.error("Could not initialize the SAML 2.0 Service Provider certificate", e);
inited = false;
}
domainsHolder.getDomains().keySet().forEach(domain -> {
AuthContextUtils.execWithAuthContext(domain, () -> {
idpDAO.findAll().forEach(idp -> {
try {
cache.put(idp);
} catch (Exception e) {
LOG.error("Could not cache the SAML 2.0 IdP with key ", idp.getEntityID(), e);
}
});
return null;
});
});
}
use of org.apache.syncope.core.spring.ResourceWithFallbackLoader in project syncope by apache.
the class XMLContentLoader method load.
@Override
public void load() {
domainsHolder.getDomains().forEach((domain, datasource) -> {
// create EntityManager so OpenJPA will build the SQL schema
EntityManagerFactoryUtils.findEntityManagerFactory(ApplicationContextProvider.getBeanFactory(), domain).createEntityManager();
JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
boolean existingData;
try {
existingData = jdbcTemplate.queryForObject("SELECT COUNT(0) FROM " + JPAConf.TABLE, Integer.class) > 0;
} catch (DataAccessException e) {
LOG.error("[{}] Could not access to table " + JPAConf.TABLE, domain, e);
existingData = true;
}
if (existingData) {
LOG.info("[{}] Data found in the database, leaving untouched", domain);
} else {
LOG.info("[{}] Empty database found, loading default content", domain);
try {
createViews(domain, datasource);
} catch (IOException e) {
LOG.error("[{}] While creating views", domain, e);
}
try {
createIndexes(domain, datasource);
} catch (IOException e) {
LOG.error("[{}] While creating indexes", domain, e);
}
try {
ResourceWithFallbackLoader contentXML = ApplicationContextProvider.getBeanFactory().getBean(domain + "ContentXML", ResourceWithFallbackLoader.class);
loadDefaultContent(domain, contentXML, datasource);
} catch (Exception e) {
LOG.error("[{}] While loading default content", domain, e);
}
}
});
}
Aggregations