use of com.helger.commons.exception.InitializationException in project phoss-directory by phax.
the class ClientCertificateValidator method _initCerts.
private static void _initCerts() {
LOGGER.info("Initializing all trusted root certificates");
final ICommonsList<PDConfiguredTrustStore> aAllTrustStores = PDServerConfiguration.getAllTrustStores();
LOGGER.info("Scanning " + aAllTrustStores.size() + " trust stores");
// Get data from config file
for (final PDConfiguredTrustStore aTS : aAllTrustStores) {
X509Certificate aCert;
try {
final KeyStore aKS = KeyStoreHelper.loadKeyStoreDirect(aTS.getType(), aTS.getPath(), aTS.getPassword());
aCert = (X509Certificate) aKS.getCertificate(aTS.getAlias());
} catch (final Exception ex) {
final String sMsg = "Failed to read trust store from '" + aTS.getPath() + "'";
LOGGER.error(sMsg);
throw new InitializationException(sMsg, ex);
}
// Check if both root certificates could be loaded
if (aCert == null) {
final String sMsg = "Failed to resolve alias '" + aTS.getAlias() + "' in trust store '" + aTS.getPath() + "'!";
LOGGER.error(sMsg);
throw new InitializationException(sMsg);
}
ALLOWED_ROOT_CERTS.add(aCert);
LOGGER.info("Root certificate loaded successfully from trust store '" + aTS.getPath() + "' with alias '" + aTS.getAlias() + "'; root certificate serial=" + aCert.getSerialNumber().toString(16) + "; root certficate issuer=" + aCert.getIssuerX500Principal().getName());
}
if (ALLOWED_ROOT_CERTS.isEmpty()) {
final String sMsg = "Server configuration contains no trusted root certificate configuration.";
if (_isCheckDisabled())
LOGGER.warn(sMsg + " Continuing anyway.");
else {
LOGGER.error(sMsg);
throw new InitializationException(sMsg);
}
}
}
use of com.helger.commons.exception.InitializationException in project ph-masterdata by phax.
the class IBANManager method _readIBANDataFromXML.
/**
* Read all IBAN country data from a file.
*/
private static void _readIBANDataFromXML() {
final IMicroDocument aDoc = MicroReader.readMicroXML(new ClassPathResource("codelists/iban-country-data.xml"));
if (aDoc == null)
throw new InitializationException("Failed to read IBAN country data [1]");
if (aDoc.getDocumentElement() == null)
throw new InitializationException("Failed to read IBAN country data [2]");
final DateTimeFormatter aDTPattern = DateTimeFormatter.ISO_DATE;
for (final IMicroElement eCountry : aDoc.getDocumentElement().getAllChildElements(ELEMENT_COUNTRY)) {
// get descriptive string
final String sDesc = eCountry.getTextContent();
final String sCountryCode = sDesc.substring(0, 2);
if (CountryCache.getInstance().getCountry(sCountryCode) == null)
if (LOGGER.isWarnEnabled())
LOGGER.warn("IBAN country data: no such country code '" + sCountryCode + "' - be careful");
LocalDate aValidFrom = null;
if (eCountry.hasAttribute(ATTR_VALIDFROM)) {
// Constant format, conforming to XML date
aValidFrom = PDTFromString.getLocalDateFromString(eCountry.getAttributeValue(ATTR_VALIDFROM), aDTPattern);
}
LocalDate aValidTo = null;
if (eCountry.hasAttribute(ATTR_VALIDUNTIL)) {
// Constant format, conforming to XML date
aValidTo = PDTFromString.getLocalDateFromString(eCountry.getAttributeValue(ATTR_VALIDUNTIL), aDTPattern);
}
final String sLayout = eCountry.getAttributeValue(ATTR_LAYOUT);
final String sCheckDigits = eCountry.getAttributeValue(ATTR_CHECKDIGITS);
// get expected length
final String sLen = eCountry.getAttributeValue(ATTR_LEN);
final int nExpectedLength = StringParser.parseInt(sLen, CGlobal.ILLEGAL_UINT);
if (nExpectedLength == CGlobal.ILLEGAL_UINT)
throw new InitializationException("Failed to convert length '" + sLen + "' to int!");
if (s_aIBANData.containsKey(sCountryCode))
throw new IllegalArgumentException("Country " + sCountryCode + " is already contained!");
s_aIBANData.put(sCountryCode, IBANCountryData.createFromString(sCountryCode, nExpectedLength, sLayout, sCheckDigits, aValidFrom, aValidTo, sDesc));
}
}
use of com.helger.commons.exception.InitializationException in project phoss-smp by phax.
the class SMPMetaManager method onAfterInstantiation.
@Override
protected void onAfterInstantiation(@Nonnull final IScope aScope) {
if (s_aManagerProvider == null)
throw new InitializationException("No ManagerProvider is set. Please call setManagerProvider before you call getInstance!");
try {
// Before all
s_aManagerProvider.beforeInitManagers();
final ESMPIdentifierType eIdentifierType = SMPServerConfiguration.getIdentifierType();
m_aIdentifierFactory = eIdentifierType.getIdentifierFactory();
// RegistrationHookFactory
try {
SMPTrustManager.getInstance();
} catch (final Exception ex) {
// fall through. No special trust store - no problem :)
}
try {
SMPKeyManager.getInstance();
} catch (final Exception ex) {
// fall through. Certificate stays invalid, no SML access possible.
}
m_eBackendConnectionState = s_aManagerProvider.getBackendConnectionEstablishedDefaultState();
if (m_eBackendConnectionState == null)
throw new IllegalStateException("Failed to get default backend connection state!");
// TODO This might become configurable in the future
m_aSMPURLProvider = SMPServerConfiguration.getRESTType().isPeppol() ? PeppolURLProvider.INSTANCE : BDXLURLProvider.INSTANCE;
if (m_aSMPURLProvider == null)
throw new IllegalStateException("Failed to create SMP URL Provider!");
m_aSMLInfoMgr = s_aManagerProvider.createSMLInfoMgr();
if (m_aSMLInfoMgr == null)
throw new IllegalStateException("Failed to create SML Info manager!");
m_aSettingsMgr = s_aManagerProvider.createSettingsMgr();
if (m_aSettingsMgr == null)
throw new IllegalStateException("Failed to create Settings manager!");
m_aTransportProfileMgr = s_aManagerProvider.createTransportProfileMgr();
if (m_aTransportProfileMgr == null)
throw new IllegalStateException("Failed to create TransportProfile manager!");
// Service group manager must be before redirect and service information!
m_aServiceGroupMgr = s_aManagerProvider.createServiceGroupMgr();
if (m_aServiceGroupMgr == null)
throw new IllegalStateException("Failed to create ServiceGroup manager!");
m_aRedirectMgr = s_aManagerProvider.createRedirectMgr(m_aIdentifierFactory, m_aServiceGroupMgr);
if (m_aRedirectMgr == null)
throw new IllegalStateException("Failed to create Redirect manager!");
m_aServiceInformationMgr = s_aManagerProvider.createServiceInformationMgr(m_aIdentifierFactory, m_aServiceGroupMgr);
if (m_aServiceInformationMgr == null)
throw new IllegalStateException("Failed to create ServiceInformation manager!");
m_aParticipantMigrationMgr = s_aManagerProvider.createParticipantMigrationMgr();
if (m_aParticipantMigrationMgr == null)
throw new IllegalStateException("Failed to create ParticipantMigration manager!");
// May be null!
m_aBusinessCardMgr = s_aManagerProvider.createBusinessCardMgr(m_aIdentifierFactory, m_aServiceGroupMgr);
_initCallbacks();
_performMigrations();
// After all
s_aManagerProvider.afterInitManagers();
LOGGER.info(ClassHelper.getClassLocalName(this) + " was initialized");
} catch (final Exception ex) {
throw new InitializationException("Failed to init " + ClassHelper.getClassLocalName(this), ex);
}
}
use of com.helger.commons.exception.InitializationException in project phoss-smp by phax.
the class SMPMetaManager method initBackendFromConfiguration.
/**
* This is the initialization routine that must be called upon application
* startup. It performs the SPI initialization of all registered manager
* provider ({@link ISMPManagerProvider}) and selects the one specified in the
* SMP server configuration file.
*
* @throws InitializationException
* If an unsupported backend is provided in the configuration.
* @see SMPServerConfiguration#getBackend()
* @see SMPBackendRegistry
* @see ISMPManagerProvider
* @see #setManagerProvider(ISMPManagerProvider)
*/
public static void initBackendFromConfiguration() {
// Determine backend
final SMPBackendRegistry aBackendRegistry = SMPBackendRegistry.getInstance();
final String sBackendID = SMPServerConfiguration.getBackend();
LOGGER.info("Initializing SMP manager for backend '" + sBackendID + "'");
final ISMPManagerProvider aManagerProvider = aBackendRegistry.getManagerProvider(sBackendID);
if (aManagerProvider == null)
throw new InitializationException("Invalid backend '" + sBackendID + "' provided. Supported ones are: " + aBackendRegistry.getAllBackendIDs());
// Remember the manager provider
setManagerProvider(aManagerProvider);
// Now we can call getInstance to ensure everything is initialized correctly
getInstance();
}
use of com.helger.commons.exception.InitializationException in project peppol-practical by phax.
the class PPMetaManager method onAfterInstantiation.
@Override
protected void onAfterInstantiation(@Nonnull final IScope aScope) {
try {
m_aCRMGroupMgr = new CRMGroupManager(CRMGROUP_XML);
m_aCRMSubscriberMgr = new CRMSubscriberManager(CRMSUBSCRIBER_XML);
// Before TestEndpoint manager!
m_aSMLConfigurationMgr = new SMLConfigurationManager(SML_INFO_XML);
m_aTestEndpointMgr = new TestEndpointManager(TEST_ENDPOINT_XML);
LOGGER.info("MetaManager was initialized");
} catch (final DAOException ex) {
throw new InitializationException("Failed to init MetaManager", ex);
}
}
Aggregations