From: <gh...@rh...> - 2009-04-28 16:01:47
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } --></style> <title>[rhq-project.org rhq] [3863] RHQ-2040 Configuring a postgres user works</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>3863</dd> <dt>Author</dt> <dd>ghinkle</dd> <dt>Date</dt> <dd>2009-04-28 11:01:30 -0500 (Tue, 28 Apr 2009)</dd> </dl> <h3>Log Message</h3> <pre>RHQ-2040 Configuring a postgres user works</pre> <h3>Modified Paths</h3> <ul> <li><a href="#rhqtrunkmodulespluginspostgressrcmainjavaorgrhqpluginspostgresPostgresUserComponentjava">rhq/trunk/modules/plugins/postgres/src/main/java/org/rhq/plugins/postgres/PostgresUserComponent.java</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="rhqtrunkmodulespluginspostgressrcmainjavaorgrhqpluginspostgresPostgresUserComponentjava"></a> <div class="modfile"><h4>Modified: rhq/trunk/modules/plugins/postgres/src/main/java/org/rhq/plugins/postgres/PostgresUserComponent.java (3862 => 3863)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/plugins/postgres/src/main/java/org/rhq/plugins/postgres/PostgresUserComponent.java 2009-04-27 20:48:00 UTC (rev 3862) +++ rhq/trunk/modules/plugins/postgres/src/main/java/org/rhq/plugins/postgres/PostgresUserComponent.java 2009-04-28 16:01:30 UTC (rev 3863) </span><span class="lines">@@ -97,14 +97,18 @@ </span><span class="cx"> rs = statement.executeQuery(); rs.next(); Configuration config = new Configuration(); </span><span class="add">+ config.put(new PropertySimple("user", rs.getString("rolname"))); </span><span class="cx"> config.put(new PropertySimple("canLogin", rs.getBoolean("rolcanlogin"))); config.put(new PropertySimple("inheritRights", rs.getBoolean("rolinherit"))); config.put(new PropertySimple("superuser", rs.getBoolean("rolsuper"))); config.put(new PropertySimple("canCreateDatabaseObjects", rs.getBoolean("rolcreatedb"))); </span><span class="rem">- config.put(new PropertySimple("canCreateRoles", rs.getBoolean("rolcreaterol"))); </span><span class="add">+ config.put(new PropertySimple("canCreateRoles", rs.getBoolean("rolcreaterole"))); </span><span class="cx"> config.put(new PropertySimple("canModifyCatalogDirectly", rs.getBoolean("rolcatupdate"))); </span><span class="rem">- config.put(new PropertySimple("connectionLimit", rs.getBoolean("rolconnlimit"))); </span><span class="add">+ config.put(new PropertySimple("connectionLimit", rs.getInt("rolconnlimit"))); </span><span class="cx"> return config; </span><span class="add">+ } catch (Exception e) { + e.printStackTrace(); + throw e; </span><span class="cx"> } finally { JDBCUtil.safeClose(statement, rs); } </span><span class="lines">@@ -114,7 +118,7 @@ </span><span class="cx"> Configuration config = report.getConfiguration(); Statement statement = null; </span><span class="rem">- String sql = getUserSQL(config, UpdateType.UPDATE); </span><span class="add">+ String sql = getUserSQL(config, UpdateType.ALTER); </span><span class="cx"> try { statement = getConnection().createStatement(); int updates = statement.executeUpdate(sql); </span><span class="lines">@@ -131,7 +135,7 @@ </span><span class="cx"> } public enum UpdateType { </span><span class="rem">- CREATE, UPDATE, DROP </span><span class="add">+ CREATE, ALTER, DROP </span><span class="cx"> } public static String getUserSQL(Configuration config, UpdateType type) { </span><span class="lines">@@ -141,15 +145,22 @@ </span><span class="cx"> connectionLimit = connLimit.getIntegerValue(); } </span><span class="rem">- return type.name() </span><span class="add">+ String sql = type.name() </span><span class="cx"> + " USER " + config.getSimpleValue("user", null) </span><span class="rem">- + " " - + ((type != UpdateType.DROP) ? ("WITH PASSWORD '" + config.getSimpleValue("password", "") + "' " - + (config.getSimple("canCreateDatabaseObjects").getBooleanValue() ? "CREATEDB " : "NOCREATEDB ") - + (config.getSimple("canCreateRoles").getBooleanValue() ? "CREATEUSER " : "NOCREATEUSER ") + ((connectionLimit > -1) ? ("CONNECTION LIMIT " + connectionLimit) - : " ")) - : ""); </span><span class="add">+ + " "; + + if (type != UpdateType.DROP) { + if (config.getSimpleValue("password",null) != null && config.getSimpleValue("password",null).length() != 0) { + sql += " WITH PASSWORD '" + config.getSimpleValue("password",null) + "' "; + } + + sql += (config.getSimple("canCreateDatabaseObjects").getBooleanValue() ? "CREATEDB " : "NOCREATEDB "); + sql += (config.getSimple("canCreateRoles").getBooleanValue() ? "CREATEUSER " : "NOCREATEUSER "); + sql += (connectionLimit > -1) ? ("CONNECTION LIMIT " + connectionLimit): ""; + } + + return sql; </span><span class="cx"> } public void deleteResource() throws Exception { </span> </pre> </div> </div> </body> </html> |