Search in sources :

Example 6 with NoRequiredPropertyException

use of org.apache.wiki.api.exceptions.NoRequiredPropertyException in project jspwiki by apache.

the class UserDatabaseLoginModuleTest method setUp.

/**
 */
@Before
public void setUp() throws Exception {
    Properties props = TestEngine.getTestProperties();
    props.put(XMLUserDatabase.PROP_USERDATABASE, "target/test-classes/userdatabase.xml");
    m_engine = new TestEngine(props);
    m_db = new XMLUserDatabase();
    m_subject = new Subject();
    try {
        m_db.initialize(m_engine, props);
    } catch (NoRequiredPropertyException e) {
        System.err.println(e.getMessage());
        Assert.assertTrue(false);
    }
}
Also used : TestEngine(org.apache.wiki.TestEngine) XMLUserDatabase(org.apache.wiki.auth.user.XMLUserDatabase) Properties(java.util.Properties) NoRequiredPropertyException(org.apache.wiki.api.exceptions.NoRequiredPropertyException) Subject(javax.security.auth.Subject) Before(org.junit.Before)

Example 7 with NoRequiredPropertyException

use of org.apache.wiki.api.exceptions.NoRequiredPropertyException in project jspwiki by apache.

the class WebContainerLoginModuleTest method setUp.

@Before
public void setUp() throws Exception {
    Properties props = TestEngine.getTestProperties();
    props.put(XMLUserDatabase.PROP_USERDATABASE, "target/test-classes/userdatabase.xml");
    m_engine = new TestEngine(props);
    m_db = new XMLUserDatabase();
    m_subject = new Subject();
    try {
        m_db.initialize(m_engine, props);
    } catch (NoRequiredPropertyException e) {
        System.err.println(e.getMessage());
        Assert.assertTrue(false);
    }
}
Also used : TestEngine(org.apache.wiki.TestEngine) XMLUserDatabase(org.apache.wiki.auth.user.XMLUserDatabase) Properties(java.util.Properties) NoRequiredPropertyException(org.apache.wiki.api.exceptions.NoRequiredPropertyException) Subject(javax.security.auth.Subject) Before(org.junit.Before)

Example 8 with NoRequiredPropertyException

use of org.apache.wiki.api.exceptions.NoRequiredPropertyException in project jspwiki by apache.

the class AuthorizationManager method locateImplementation.

private Object locateImplementation(String clazz) throws WikiException {
    if (clazz != null) {
        try {
            Class<?> authClass = ClassUtil.findClass("org.apache.wiki.auth.authorize", clazz);
            Object impl = authClass.newInstance();
            return impl;
        } catch (ClassNotFoundException e) {
            log.fatal("Authorizer " + clazz + " cannot be found", e);
            throw new WikiException("Authorizer " + clazz + " cannot be found", e);
        } catch (InstantiationException e) {
            log.fatal("Authorizer " + clazz + " cannot be created", e);
            throw new WikiException("Authorizer " + clazz + " cannot be created", e);
        } catch (IllegalAccessException e) {
            log.fatal("You are not allowed to access this authorizer class", e);
            throw new WikiException("You are not allowed to access this authorizer class", e);
        }
    }
    throw new NoRequiredPropertyException("Unable to find a " + PROP_AUTHORIZER + " entry in the properties.", PROP_AUTHORIZER);
}
Also used : WikiException(org.apache.wiki.api.exceptions.WikiException) NoRequiredPropertyException(org.apache.wiki.api.exceptions.NoRequiredPropertyException)

Example 9 with NoRequiredPropertyException

use of org.apache.wiki.api.exceptions.NoRequiredPropertyException in project jspwiki by apache.

the class GroupManager method getGroupDatabase.

/**
 * Returns the current external {@link GroupDatabase} in use. This method
 * is guaranteed to return a properly-initialized GroupDatabase, unless
 * it could not be initialized. In that case, this method throws
 * a {@link org.apache.wiki.api.exceptions.WikiException}. The GroupDatabase
 * is lazily initialized.
 * @throws org.apache.wiki.auth.WikiSecurityException if the GroupDatabase could
 * not be initialized
 * @return the current GroupDatabase
 * @since 2.3
 */
public GroupDatabase getGroupDatabase() throws WikiSecurityException {
    if (m_groupDatabase != null) {
        return m_groupDatabase;
    }
    String dbClassName = "<unknown>";
    String dbInstantiationError = null;
    Throwable cause = null;
    try {
        Properties props = m_engine.getWikiProperties();
        dbClassName = props.getProperty(PROP_GROUPDATABASE);
        if (dbClassName == null) {
            dbClassName = XMLGroupDatabase.class.getName();
        }
        log.info("Attempting to load group database class " + dbClassName);
        Class<?> dbClass = ClassUtil.findClass("org.apache.wiki.auth.authorize", dbClassName);
        m_groupDatabase = (GroupDatabase) dbClass.newInstance();
        m_groupDatabase.initialize(m_engine, m_engine.getWikiProperties());
        log.info("Group database initialized.");
    } catch (ClassNotFoundException e) {
        log.error("GroupDatabase class " + dbClassName + " cannot be found.", e);
        dbInstantiationError = "Failed to locate GroupDatabase class " + dbClassName;
        cause = e;
    } catch (InstantiationException e) {
        log.error("GroupDatabase class " + dbClassName + " cannot be created.", e);
        dbInstantiationError = "Failed to create GroupDatabase class " + dbClassName;
        cause = e;
    } catch (IllegalAccessException e) {
        log.error("You are not allowed to access group database class " + dbClassName + ".", e);
        dbInstantiationError = "Access GroupDatabase class " + dbClassName + " denied";
        cause = e;
    } catch (NoRequiredPropertyException e) {
        log.error("Missing property: " + e.getMessage() + ".");
        dbInstantiationError = "Missing property: " + e.getMessage();
        cause = e;
    }
    if (dbInstantiationError != null) {
        throw new WikiSecurityException(dbInstantiationError + " Cause: " + (cause != null ? cause.getMessage() : ""), cause);
    }
    return m_groupDatabase;
}
Also used : WikiSecurityException(org.apache.wiki.auth.WikiSecurityException) Properties(java.util.Properties) NoRequiredPropertyException(org.apache.wiki.api.exceptions.NoRequiredPropertyException)

Aggregations

NoRequiredPropertyException (org.apache.wiki.api.exceptions.NoRequiredPropertyException)9 Properties (java.util.Properties)6 Subject (javax.security.auth.Subject)4 TestEngine (org.apache.wiki.TestEngine)4 XMLUserDatabase (org.apache.wiki.auth.user.XMLUserDatabase)4 Before (org.junit.Before)4 WikiSecurityException (org.apache.wiki.auth.WikiSecurityException)3 Context (javax.naming.Context)2 InitialContext (javax.naming.InitialContext)2 NamingException (javax.naming.NamingException)2 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 WikiException (org.apache.wiki.api.exceptions.WikiException)1 NoSuchPrincipalException (org.apache.wiki.auth.NoSuchPrincipalException)1 Test (org.junit.Test)1