Search in sources :

Example 1 with ConfigurationException

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);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationException(org.apache.jackrabbit.core.config.ConfigurationException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) ConfigurationErrorHandler(org.apache.jackrabbit.core.config.ConfigurationErrorHandler) SAXException(org.xml.sax.SAXException)

Example 2 with ConfigurationException

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());
        }
    }
}
Also used : BeanConfig(org.apache.jackrabbit.core.config.BeanConfig) LoginContext(javax.security.auth.login.LoginContext) Configuration(javax.security.auth.login.Configuration) ConfigurationException(org.apache.jackrabbit.core.config.ConfigurationException) LoginModuleConfig(org.apache.jackrabbit.core.config.LoginModuleConfig) LoginException(javax.security.auth.login.LoginException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) Properties(java.util.Properties)

Example 3 with ConfigurationException

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;
    }
}
Also used : FailedLoginException(javax.security.auth.login.FailedLoginException) ConfigurationException(org.apache.jackrabbit.core.config.ConfigurationException) HashMap(java.util.HashMap) LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) Properties(java.util.Properties) LoginException(javax.security.auth.login.LoginException) ConfigurationException(org.apache.jackrabbit.core.config.ConfigurationException) FailedLoginException(javax.security.auth.login.FailedLoginException)

Aggregations

ConfigurationException (org.apache.jackrabbit.core.config.ConfigurationException)3 Properties (java.util.Properties)2 LoginException (javax.security.auth.login.LoginException)2 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 HashMap (java.util.HashMap)1 Configuration (javax.security.auth.login.Configuration)1 FailedLoginException (javax.security.auth.login.FailedLoginException)1 LoginContext (javax.security.auth.login.LoginContext)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 BeanConfig (org.apache.jackrabbit.core.config.BeanConfig)1 ConfigurationErrorHandler (org.apache.jackrabbit.core.config.ConfigurationErrorHandler)1 LoginModuleConfig (org.apache.jackrabbit.core.config.LoginModuleConfig)1 Document (org.w3c.dom.Document)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1