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);
}
}
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);
}
}
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);
}
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;
}
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();
}
}
Aggregations