![JAR search and dependency download from the Maven repository](/logo.png)
org.kawanfw.sql.util.reflection.ReflectionCaller Maven / Gradle / Ivy
/*
* This file is part of AceQL.
* AceQL: Remote JDBC access over HTTP.
* Copyright (C) 2015, KawanSoft SAS
* (http://www.kawansoft.com). All rights reserved.
*
* AceQL is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* AceQL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*
* Any modifications to this file must keep this entire header
* intact.
*/
package org.kawanfw.sql.util.reflection;
import java.sql.SQLException;
import org.kawanfw.sql.api.server.SqlConfigurator;
/**
* @author Nicolas de Pomereu
*
* A class that allows to call CommonsConfigurator & SqlConfigurator
* methods per reflection using Invoker.
*/
public class ReflectionCaller {
/**
* Protected constructor
*/
protected ReflectionCaller() {
}
// KEEP A REFLECTION MODEL
// /**
// * Return the result of computeAuthToken(String username) method of
// CommonsConfigurator
// *
// * @param CommonsConfigurator the CommonsConfigurator instance
// * @return the list of banned IPs else null
// *
// * @throws SQLException if any Exception occurs, it is wrapped into an
// SQLException
// */
// public static char [] getEncryptionPassword(CommonsConfigurator
// commonsConfigurator) throws SQLException
// {
// String methodName = new Object() {
// }.getClass().getEnclosingMethod().getName();
//
// if (!
// Invoker.existsMethod(org.kawanfw.commons.api.server.CommonsConfigurator.class.getName(),
// methodName)) {
// return null;
// }
//
// Object result = null;
//
// try {
// result = Invoker.getMethodResult(commonsConfigurator, methodName);
// } catch (Exception e) {
// throw new SQLException(e);
// }
//
// if (result == null) {
// return null;
// }
// else {
// return (char[]) result;
// }
// }
// FUTUR USAGE
// * Define if a login delay must be applied after a number of
// unsuccessful login attempts.
//
// /**
// * Defines the number of successive unsuccessful login attempts before
// triggering a delay.
// * A value of 0 means no delay will be applied.
// *
// * Setting a value > 0 requires the existence of the following table in
// the current database:
// *
// * create table kawanfw_login_delay
// * (
// * username varchar(64) not null,
// * login_attempts integer not null,
// * PRIMARY KEY(username)
// * );
// *
// *
// * @return the number of successive unsuccessful login attempts before
// triggering a delay
// *
// */
// public int getMaxLoginAttemptsBeforeDelay();
//
//
// /**
// * Defines the number of seconds to delay after the the maximum number of
// successive unsuccessful login attempts
// * defined by {@link #getMaxLoginAttemptsBeforeDelay()} has bee reached.
// *
// * @return the number of seconds to delay before activating the next login
// attempt
// *
// * @throws SQLException
// * if a SQLException occurs: this may be the case if the
// kawanfw_login_delay
table
// * has not been defined in current the database
// */
// public int getDelayBeforeNextLogin() throws SQLException;
// /**
// * @return 0 (delay will never be applied)
// */
// @Override
// public int getMaxLoginAttemptsBeforeDelay() {
// return 0;
// }
//
// /**
// * @return 3 seconds delay before next login. Delay Will be activated only
// if {@link #getMaxLoginAttemptsBeforeDelay()} > 0
// */
// @Override
// public int getDelayBeforeNextLogin() throws SQLException {
// return 3;
// }
/**
* Return the result of getDelayBeforeNextLogin method of SqlConfigurator
*
* @param sqlConfigurator
* the SqlConfigurator instance
* @return the maximum of attempts before login delay
*
* @throws SQLException
* if any Exception occurs, it is wrapped into an SQLException
*/
public static int getMaxLoginAttemptsBeforeDelay(
SqlConfigurator sqlConfigurator) throws SQLException {
String methodName = new Object() {
}.getClass().getEnclosingMethod().getName();
if (!Invoker.existsMethod(
org.kawanfw.sql.api.server.SqlConfigurator.class.getName(),
methodName)) {
return 0;
}
Object result = null;
try {
result = Invoker.getMethodResult(sqlConfigurator, methodName);
} catch (Exception e) {
throw new SQLException(e);
}
if (result == null) {
return 0;
} else {
return (Integer) result;
}
}
/**
* Return the result of getDelayBeforeNextLogin method of SqlConfigurator
*
* @param sqlConfigurator
* the SqlConfigurator instance
* @return the delay in seconds before the next authorized login
*
* @throws SQLException
* if any Exception occurs, it is wrapped into an SQLException
*/
public static int getDelayBeforeNextLogin(SqlConfigurator sqlConfigurator)
throws SQLException {
String methodName = new Object() {
}.getClass().getEnclosingMethod().getName();
if (!Invoker.existsMethod(
org.kawanfw.sql.api.server.SqlConfigurator.class.getName(),
methodName)) {
return 0;
}
Object result = null;
try {
result = Invoker.getMethodResult(sqlConfigurator, methodName);
} catch (Exception e) {
throw new SQLException(e);
}
if (result == null) {
return 0;
} else {
return (Integer) result;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy