Revision: 30135
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 8, 2010 12:46 by LarryStreeter
Initial Code
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 {
public static void main(String[] args){
Connection connection = null;
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
String what = "authentication, operPriv, userPriv";
ResultSet from = ResultSetFactory.getResultSet("type, name", null, null);
ResultSet where = null;
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
ResultSet rs = userAdmin.select(what, from, where);
// move to the first row and get the authentication values and operator
// and user privileges
rs.first();
ResultSet authentication = rs.getResultSet("authentication");
String operPriv = rs.getString("operPriv");
String userPriv = rs.getString("userPriv");
// Create a new user in the selected database with the create method.
ResultSet rsUser = ResultSetFactory.getResultSet(
"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")){
System.out.println(rs.getString("message"));
System.out.println(rs.getString("exception"));
}
}
catch (SrapException e) {
e.printStackTrace();
}
finally {
if (connection != null) {
connection.dispose();
}
}
}
Initial URL
Initial Description
Initial Title
Add new Rochade User
Initial Tags
Initial Language
Java