use of org.apache.jackrabbit.core.config.ConfigurationException in project jackrabbit by apache.
the class DefaultLoginModuleTest method parseXML.
private static Element parseXML(InputSource xml, boolean validate) throws ConfigurationException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(validate);
DocumentBuilder builder = factory.newDocumentBuilder();
if (validate) {
builder.setErrorHandler(new ConfigurationErrorHandler());
}
builder.setEntityResolver(ConfigurationEntityResolver.INSTANCE);
Document document = builder.parse(xml);
return document.getDocumentElement();
} catch (ParserConfigurationException e) {
throw new ConfigurationException("Unable to create configuration XML parser", e);
} catch (SAXParseException e) {
throw new ConfigurationException("Configuration file syntax error. (Line: " + e.getLineNumber() + " Column: " + e.getColumnNumber() + ")", e);
} catch (SAXException e) {
throw new ConfigurationException("Configuration file syntax error. ", e);
} catch (IOException e) {
throw new ConfigurationException("Configuration file could not be read.", e);
}
}
use of org.apache.jackrabbit.core.config.ConfigurationException in project sling by apache.
the class DelegatingLoginModule method initialize.
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
Configuration config = null;
try {
config = Configuration.getInstance(JAAS_CONFIG_ALGO_NAME, null, providerName);
} catch (NoSuchProviderException e) {
logger.debug("No provider " + providerName + "found so far", e);
} catch (NoSuchAlgorithmException e) {
logger.debug("No provider " + providerName + "found so far for fetching JAAS " + "config with algorithm name " + JAAS_CONFIG_ALGO_NAME, e);
}
if (config != null) {
final Thread current = Thread.currentThread();
final ClassLoader orig = current.getContextClassLoader();
try {
current.setContextClassLoader(DelegatingLoginModule.class.getClassLoader());
loginContext = new LoginContext(appName, subject, callbackHandler, config);
} catch (LoginException e) {
loginException = e;
} finally {
current.setContextClassLoader(orig);
}
} else {
//No support so far from OSGi so would use default logic used by Jackrabbit
//to construct the LoginModule
Properties p = new Properties();
p.putAll(options);
BeanConfig bc = new BeanConfig(delegateLoginModuleClass, p);
LoginModuleConfig lmc = new LoginModuleConfig(bc);
try {
delegate = lmc.getLoginModule();
delegate.initialize(subject, callbackHandler, sharedState, options);
logger.info("No JAAS Configuration provider found would be directly invoking LoginModule {}", delegateLoginModuleClass);
} catch (ConfigurationException e) {
//Behaviour is same as org.apache.jackrabbit.core.security.authentication.LocalAuthContext.login()
loginException = new LoginException(e.getMessage());
}
}
}
use of org.apache.jackrabbit.core.config.ConfigurationException in project jackrabbit by apache.
the class LocalAuthContext method login.
public void login() throws LoginException {
try {
module = config.getLoginModule();
} catch (ConfigurationException e) {
throw new LoginException(e.getMessage());
}
Map<String, Object> state = new HashMap<String, Object>();
Map<String, String> options = new HashMap<String, String>();
Properties parameters = config.getParameters();
Enumeration<?> names = parameters.propertyNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
options.put(name, parameters.getProperty(name));
}
module.initialize(subject, cbHandler, state, options);
try {
if (!(module.login() && module.commit())) {
throw new FailedLoginException("LoginModule ignored Credentials");
}
} catch (LoginException le) {
module.abort();
throw le;
} catch (Exception e) {
module.abort();
LoginException le = new LoginException("LoginModule could not perform authentication: " + e.getMessage());
le.initCause(e);
log.debug("Login failed to runtime-exception: ", e);
throw le;
}
}
Aggregations