Search in sources :

Example 6 with ForumException

use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.

the class InstallAction method importTablesData.

private boolean importTablesData(Connection conn) {
    try {
        boolean status = true;
        boolean autoCommit = conn.getAutoCommit();
        conn.setAutoCommit(false);
        String dbType = this.getFromSession("database");
        List statements = ParseDBDumpFile.parse(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR) + "/database/" + dbType + "/" + dbType + "_data_dump.sql");
        for (Iterator iter = statements.iterator(); iter.hasNext(); ) {
            String query = (String) iter.next();
            if (query == null || "".equals(query.trim())) {
                continue;
            }
            query = query.trim();
            Statement s = conn.createStatement();
            try {
                if (query.startsWith("UPDATE") || query.startsWith("INSERT") || query.startsWith("SET")) {
                    s.executeUpdate(query);
                } else if (query.startsWith("SELECT")) {
                    s.executeQuery(query);
                } else {
                    throw new SQLException("Invalid query: " + query);
                }
            } catch (SQLException ex) {
                status = false;
                conn.rollback();
                logger.error("Error importing data for " + query + ": " + ex, ex);
                this.context.put("exceptionMessage", ex.getMessage() + "\n" + query);
                break;
            } finally {
                s.close();
            }
        }
        conn.setAutoCommit(autoCommit);
        return status;
    } catch (Exception e) {
        throw new ForumException(e);
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Iterator(java.util.Iterator) List(java.util.List) DatabaseException(net.jforum.exceptions.DatabaseException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ForumException(net.jforum.exceptions.ForumException)

Example 7 with ForumException

use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.

the class InstallAction method createTables.

private boolean createTables(Connection conn) {
    logger.info("Going to create tables...");
    String dbType = this.getFromSession("database");
    if ("postgresql".equals(dbType) || "oracle".equals(dbType)) {
        // This should be in a separate transaction block; otherwise, an empty database will fail.
        this.dropOracleOrPostgreSQLTables(dbType, conn);
    }
    try {
        boolean status = true;
        boolean autoCommit = conn.getAutoCommit();
        conn.setAutoCommit(false);
        List statements = ParseDBStructFile.parse(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR) + "/database/" + dbType + "/" + dbType + "_db_struct.sql");
        for (Iterator iter = statements.iterator(); iter.hasNext(); ) {
            String query = (String) iter.next();
            if (query == null || "".equals(query.trim())) {
                continue;
            }
            Statement s = null;
            try {
                s = conn.createStatement();
                s.executeUpdate(query);
            } catch (SQLException ex) {
                status = false;
                logger.error("Error executing query: " + query + ": " + ex, ex);
                this.context.put("exceptionMessage", ex.getMessage() + "\n" + query);
                break;
            } finally {
                DbUtils.close(s);
            }
        }
        conn.setAutoCommit(autoCommit);
        return status;
    } catch (Exception e) {
        throw new ForumException(e);
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Iterator(java.util.Iterator) List(java.util.List) DatabaseException(net.jforum.exceptions.DatabaseException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ForumException(net.jforum.exceptions.ForumException)

Example 8 with ForumException

use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.

the class ConfigAction method list.

public void list() {
    Properties p = new Properties();
    Iterator iter = SystemGlobals.fetchConfigKeyIterator();
    while (iter.hasNext()) {
        String key = (String) iter.next();
        String value = SystemGlobals.getValue(key);
        p.put(key, value);
    }
    Properties locales = new Properties();
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR) + "/languages/locales.properties");
        locales.load(fis);
    } catch (IOException e) {
        throw new ForumException(e);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (Exception e) {
            }
        }
    }
    List localesList = new ArrayList();
    for (Enumeration e = locales.keys(); e.hasMoreElements(); ) {
        localesList.add(e.nextElement());
    }
    this.context.put("config", p);
    this.context.put("locales", localesList);
    this.setTemplateName(TemplateKeys.CONFIG_LIST);
}
Also used : ForumException(net.jforum.exceptions.ForumException) Enumeration(java.util.Enumeration) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ForumException(net.jforum.exceptions.ForumException)

Example 9 with ForumException

use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.

the class UserAction method parseBasicAuthentication.

private boolean parseBasicAuthentication() {
    if (hasBasicAuthentication(request)) {
        String auth = request.getHeader("Authorization");
        String decoded;
        try {
            decoded = new String(new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(6)));
        } catch (IOException e) {
            throw new ForumException(e);
        }
        int p = decoded.indexOf(':');
        if (p != -1) {
            request.setAttribute("username", decoded.substring(0, p));
            request.setAttribute("password", decoded.substring(p + 1));
            return true;
        }
    }
    return false;
}
Also used : ForumException(net.jforum.exceptions.ForumException) IOException(java.io.IOException)

Example 10 with ForumException

use of net.jforum.exceptions.ForumException in project jforum2 by rafaelsteil.

the class ControllerUtils method refreshSession.

/**
 * Do a refresh in the user's session. This method will update the last visit time for the
 * current user, as well checking for authentication if the session is new or the SSO user has
 * changed
 */
public void refreshSession() {
    UserSession userSession = SessionFacade.getUserSession();
    RequestContext request = JForumExecutionContext.getRequest();
    if (userSession == null) {
        userSession = new UserSession();
        userSession.registerBasicInfo();
        userSession.setSessionId(request.getSessionContext().getId());
        userSession.setIp(request.getRemoteAddr());
        SessionFacade.makeUnlogged();
        if (!JForumExecutionContext.getForumContext().isBot()) {
            // Non-SSO authentications can use auto login
            if (!ConfigKeys.TYPE_SSO.equals(SystemGlobals.getValue(ConfigKeys.AUTHENTICATION_TYPE))) {
                if (SystemGlobals.getBoolValue(ConfigKeys.AUTO_LOGIN_ENABLED)) {
                    this.checkAutoLogin(userSession);
                } else {
                    userSession.makeAnonymous();
                }
            } else {
                this.checkSSO(userSession);
            }
        }
        SessionFacade.add(userSession);
    } else if (ConfigKeys.TYPE_SSO.equals(SystemGlobals.getValue(ConfigKeys.AUTHENTICATION_TYPE))) {
        SSO sso;
        try {
            sso = (SSO) Class.forName(SystemGlobals.getValue(ConfigKeys.SSO_IMPLEMENTATION)).newInstance();
        } catch (Exception e) {
            throw new ForumException(e);
        }
        // If SSO, then check if the session is valid
        if (!sso.isSessionValid(userSession, request)) {
            SessionFacade.remove(userSession.getSessionId());
            refreshSession();
        }
    } else {
        SessionFacade.getUserSession().updateSessionTime();
    }
}
Also used : ForumException(net.jforum.exceptions.ForumException) UserSession(net.jforum.entities.UserSession) RequestContext(net.jforum.context.RequestContext) SSO(net.jforum.sso.SSO) DatabaseException(net.jforum.exceptions.DatabaseException) ForumException(net.jforum.exceptions.ForumException)

Aggregations

ForumException (net.jforum.exceptions.ForumException)37 IOException (java.io.IOException)24 FileInputStream (java.io.FileInputStream)10 File (java.io.File)7 Iterator (java.util.Iterator)6 Properties (java.util.Properties)6 DatabaseException (net.jforum.exceptions.DatabaseException)6 List (java.util.List)5 SQLException (java.sql.SQLException)4 CacheEngineStartupException (net.jforum.exceptions.CacheEngineStartupException)4 SchedulerException (org.quartz.SchedulerException)4 FileOutputStream (java.io.FileOutputStream)3 PreparedStatement (java.sql.PreparedStatement)3 Enumeration (java.util.Enumeration)3 Statement (java.sql.Statement)2 ArrayList (java.util.ArrayList)2 SAXParser (javax.xml.parsers.SAXParser)2 Post (net.jforum.entities.Post)2 User (net.jforum.entities.User)2 SSO (net.jforum.sso.SSO)2