/ Published in: Java
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import de.rochade.srap.Connection; import de.rochade.srap.ResultSet; import de.rochade.srap.ResultSetFactory; import de.rochade.srap.Rochade; import de.rochade.srap.SrapException; import de.rochade.srap.Startup; import de.rochade.srap.UserAdmin; public class AddUser { try { // Connect to the Rochade Server Rochade rochade = Startup.getInstance(null, null, null, null, null, null); connection = rochade.getConnection("localhost", 8888, "ROADM", "", null); // Request the User Administration object for the selected database UserAdmin userAdmin = connection.getUserAdmin("AP-DATA"); // Get the authentication settings from an existing template // using the select method. // Setup the select statement parameters from.add(); from.updateString("type", "template"); // Identify the type as template from.updateString("name", "ROCHUSER"); // The name of the template to get // Request the template using a select call // move to the first row and get the authentication values and operator // and user privileges rs.first(); // Create a new user in the selected database with the create method. "type, userID, shortDesc, authentication, operPriv, userPriv", null, null); rsUser.add(); rsUser.updateString("type", "user"); // Identify the type as user rsUser.updateString("userID", "JOEUSER"); // User ID rsUser.updateString("shortDesc", "Joe is a Rochade user, not a plumber"); // User description // Add an additional column to the authentication parameters // for the users initial password. authentication.appendColumn("pwd", "String"); authentication.first(); authentication.updateString("pwd", "password"); // set the authentication settings and the user and operator // privileges for the new user. rsUser.updateResultSet("authentication", authentication); rsUser.updateString("operPriv", operPriv); rsUser.updateString("userPriv", userPriv); // Create the user using the create method. rs = userAdmin.create(rsUser); // Check the results for success. rs.first(); if (!rs.getBoolean("success")){ } } catch (SrapException e) { e.printStackTrace(); } finally { if (connection != null) { connection.dispose(); } } }