Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added client valid check

  • Loading branch information...
commit c00d00022414a374ba69b702c67e9b13c8a2365e 1 parent abd91de
Vincent Kriek vincentkriek authored
6 Product/Controller/src/org/openremote/controller/service/ClientService.java
View
@@ -106,6 +106,12 @@
*/
boolean isClientIDValid(int clientID);
/**
+ * Check if the client is valid based on a dname
+ * @param dname the dynamic name
+ * @return true if the client is valid
+ */
+ boolean isClientValid(String dname);
+ /**
* Close the result set.
*/
void free();
26 Product/Controller/src/org/openremote/controller/service/impl/ClientServiceImpl.java
View
@@ -59,6 +59,7 @@
private static final String KEYSTORE_PASSWORD = "password";
private static final String CA_PATH = "ca_path";
+ private static String checkClientQuery = "SELECT client_id FROM client WHERE client_dn = ? ";
private static String selectClientQuery = "SELECT * FROM client WHERE client_id = ? ";
private static String selectAllClientsQuery = "SELECT * FROM client ORDER BY client_creation_timestamp ASC";
private static String insertClientQuery = "INSERT INTO client (client_serial, client_pincode, client_device_name, client_email, client_alias, client_active, client_creation_timestamp, client_modification_timestamp, client_role, client_dn) VALUES ";
@@ -570,4 +571,29 @@ public void setDatabase(DatabaseService database) {
public void setDatabaseConfiguration(ConfigurationService databaseConfiguration) {
this.databaseConfiguration = databaseConfiguration;
}
+
+ /**
+ * Check if the client is valid based on a dname
+ * @param dname the dynamic name
+ * @return true if the client is valid
+ */
+ public boolean isClientValid(String dname) {
+ boolean returnValue = false;
+ PreparedStatement preparedStatement = null;
+
+ if (database != null)
+ {
+ try {
+ preparedStatement = database.createPrepareStatement(checkClientQuery + limitByOne);
+ preparedStatement.setString(1, dname);
+ database.doSQL(preparedStatement);
+ returnValue = database.getNumRows() == 1;
+ } catch (SQLException e) {
+ logger.error("SQL Exception: " + e.getMessage());
+ }
+ } else {
+ logger.error("Database is not yet set (null)");
+ }
+ return returnValue;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.