I've just extended DataSourceRealm for an internal project, and found
that my extensions could have been done easier if the access level of
preparedRoles and preparedCredentials were less restrictive.
This would allow developers to replace the actual SQL with something
more suited for their purpose without having to resort to a copy/paste
implementation of (parts of) DataSourceRealm.
I've also seen people struggle with configuration of the realms, so
another proposed change is to validate that the input parameters are at
least defined and log any errors.
--
Andreas
diff -Naur apache-tomcat-5.5.17-src.orig/container/catalina/src/share/org/apache/catalina/realm/DataSourceRealm.java apache-tomcat-5.5.17-src/container/catalina/src/share/org/apache/catalina/realm/DataSourceRealm.java
--- apache-tomcat-5.5.17-src.orig/container/catalina/src/share/org/apache/catalina/realm/DataSourceRealm.java 2006-04-14 20:11:43.000000000 +0200
+++ apache-tomcat-5.5.17-src/container/catalina/src/share/org/apache/catalina/realm/DataSourceRealm.java 2006-08-15 15:51:04.000000000 +0200
@@ -57,13 +57,13 @@
/**
* The generated string for the roles PreparedStatement
*/
- private String preparedRoles = null;
+ protected String preparedRoles = null;
/**
* The generated string for the credentials PreparedStatement
*/
- private String preparedCredentials = null;
+ protected String preparedCredentials = null;
/**
diff -Naur apache-tomcat-5.5.17-src.orig/container/catalina/src/share/org/apache/catalina/realm/DataSourceRealm.java apache-tomcat-5.5.17-src/container/catalina/src/share/org/apache/catalina/realm/DataSourceRealm.java
--- apache-tomcat-5.5.17-src.orig/container/catalina/src/share/org/apache/catalina/realm/DataSourceRealm.java 2006-04-14 20:11:43.000000000 +0200
+++ apache-tomcat-5.5.17-src/container/catalina/src/share/org/apache/catalina/realm/DataSourceRealm.java 2006-08-15 16:07:36.000000000 +0200
@@ -623,6 +623,12 @@
// Perform normal superclass initialization
super.start();
+ assertNotNull("roleNameCol", roleNameCol);
+ assertNotNull("userCredCol", userCredCol);
+ assertNotNull("userNameCol", userNameCol);
+ assertNotNull("userRoleTable", userRoleTable);
+ assertNotNull("userTable", userTable);
+
// Create the roles PreparedStatement string
StringBuffer temp = new StringBuffer("SELECT ");
temp.append(roleNameCol);
diff -Naur apache-tomcat-5.5.17-src.orig/container/catalina/src/share/org/apache/catalina/realm/LocalStrings.properties apache-tomcat-5.5.17-src/container/catalina/src/share/org/apache/catalina/realm/LocalStrings.properties
--- apache-tomcat-5.5.17-src.orig/container/catalina/src/share/org/apache/catalina/realm/LocalStrings.properties 2006-04-14 20:11:43.000000000 +0200
+++ apache-tomcat-5.5.17-src/container/catalina/src/share/org/apache/catalina/realm/LocalStrings.properties 2006-08-15 15:56:37.000000000 +0200
@@ -58,6 +58,7 @@
realmBase.notStarted=This Realm has not yet been started
realmBase.authenticateFailure=Username {0} NOT successfully authenticated
realmBase.authenticateSuccess=Username {0} successfully authenticated
+realmBase.missingArgument={0} must be configured
userDatabaseRealm.authenticateError=Login configuration error authenticating username {0}
userDatabaseRealm.lookup=Exception looking up UserDatabase under key {0}
userDatabaseRealm.noDatabase=No UserDatabase component found under key {0}
diff -Naur apache-tomcat-5.5.17-src.orig/container/catalina/src/share/org/apache/catalina/realm/RealmBase.java apache-tomcat-5.5.17-src/container/catalina/src/share/org/apache/catalina/realm/RealmBase.java
--- apache-tomcat-5.5.17-src.orig/container/catalina/src/share/org/apache/catalina/realm/RealmBase.java 2006-04-14 20:11:44.000000000 +0200
+++ apache-tomcat-5.5.17-src/container/catalina/src/share/org/apache/catalina/realm/RealmBase.java 2006-08-15 16:11:39.000000000 +0200
@@ -688,6 +688,15 @@
}
/**
+ * Check whether a parameter is null and log an error if it is
+ */
+ protected void assertNotNull(String paramName, Object o) throws LifecycleException {
+ if (o == null) {
+ throw new LifecycleException(sm.getString("realmBase.missingArgument", paramName));
+ }
+ }
+
+ /**
* Convert an ArrayList to a SecurityContraint [].
*/
private SecurityConstraint [] resultsToArray(ArrayList results) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]