remm 2005/08/04 06:06:56 Modified: catalina/src/share/org/apache/catalina/users MemoryUserDatabase.java mbeans-descriptors.xml MemoryUserDatabaseFactory.java LocalStrings.properties webapps/docs changelog.xml Log: - 36020: MemoryUserDatabase in read only situations. - Submitted by Rainer Jung. Revision Changes Path 1.8 +59 -1 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/users/MemoryUserDatabase.java Index: MemoryUserDatabase.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/users/MemoryUserDatabase.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- MemoryUserDatabase.java 26 Jun 2004 17:41:33 -0000 1.7 +++ MemoryUserDatabase.java 4 Aug 2005 13:06:56 -0000 1.8 @@ -31,6 +31,8 @@ import org.apache.catalina.User; import org.apache.catalina.UserDatabase; import org.apache.catalina.util.StringManager; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.tomcat.util.digester.Digester; import org.apache.tomcat.util.digester.ObjectCreationFactory; import org.xml.sax.Attributes; @@ -49,6 +51,8 @@ public class MemoryUserDatabase implements UserDatabase { + private static Log log = LogFactory.getLog(MemoryUserDatabase.class); + // ----------------------------------------------------------- Constructors @@ -113,6 +117,11 @@ /** + * A flag, indicating if the user database is read only. + */ + protected boolean readonly = false; + + /** * The set of [EMAIL PROTECTED] Role}s defined in this database, keyed by * role name. */ @@ -183,6 +192,28 @@ /** + * Returning the readonly status of the user database + */ + public boolean getReadonly() { + + return (this.readonly); + + } + + + /** + * Setting the readonly status of the user database + * + * @param pathname The new pathname + */ + public void setReadonly(boolean readonly) { + + this.readonly = readonly; + + } + + + /** * Return the set of [EMAIL PROTECTED] Role}s defined in this user database. */ public Iterator getRoles() { @@ -442,6 +473,24 @@ /** + * Check for permissions to save this user database + * to persistent storage location + * + */ + public boolean isPersistable() { + + File file = new File(pathname); + if (!file.isAbsolute()) { + file = new File(System.getProperty("catalina.base"), + pathname); + } + File dir = file.getParentFile(); + return dir.exists() && dir.isDirectory() && dir.canWrite(); + + } + + + /** * Save any updated information to the persistent storage location for * this user database. * @@ -449,6 +498,15 @@ */ public void save() throws Exception { + if ( getReadonly() ) { + return; + } + + if ( ! isPersistable() ) { + log.warn(sm.getString("memoryUserDatabase.notPersistable")); + return; + } + // Write out contents to a temporary file File fileNew = new File(pathnameNew); if (!fileNew.isAbsolute()) { 1.2 +11 -0 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/users/mbeans-descriptors.xml Index: mbeans-descriptors.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/users/mbeans-descriptors.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- mbeans-descriptors.xml 25 Apr 2003 21:14:36 -0000 1.1 +++ mbeans-descriptors.xml 4 Aug 2005 13:06:56 -0000 1.2 @@ -252,6 +252,17 @@ type="java.lang.String"/> </operation> + <attribute name="readonly" + description="No persistant save of the user database" + type="boolean" + writeable="false"/> + + <operation name="isPersistable" + description="Check if user database is writable" + impact="INFO" + returnType="boolean"> + </operation> + <operation name="save" description="Save current users and groups to persistent storage" impact="ACTION" 1.4 +6 -1 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/users/MemoryUserDatabaseFactory.java Index: MemoryUserDatabaseFactory.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/users/MemoryUserDatabaseFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MemoryUserDatabaseFactory.java 27 Feb 2004 14:58:50 -0000 1.3 +++ MemoryUserDatabaseFactory.java 4 Aug 2005 13:06:56 -0000 1.4 @@ -93,6 +93,11 @@ database.setPathname(ra.getContent().toString()); } + ra = ref.get("readonly"); + if (ra != null) { + database.setReadonly(Boolean.valueOf(ra.getContent().toString()).booleanValue()); + } + // Return the configured database instance database.open(); database.save(); 1.2 +1 -0 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/users/LocalStrings.properties Index: LocalStrings.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/users/LocalStrings.properties,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- LocalStrings.properties 18 Jul 2002 16:47:47 -0000 1.1 +++ LocalStrings.properties 4 Aug 2005 13:06:56 -0000 1.2 @@ -2,3 +2,4 @@ memoryUserDatabase.renameOld=Cannot rename original file to {0} memoryUserDatabase.renameNew=Cannot rename new file to {0} memoryUserDatabase.writeException=IOException writing to {0} +memoryUserDatabase.notPersistable=User database is not persistable - no write permissions on directory 1.353 +4 -0 jakarta-tomcat-catalina/webapps/docs/changelog.xml Index: changelog.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/docs/changelog.xml,v retrieving revision 1.352 retrieving revision 1.353 diff -u -r1.352 -r1.353 --- changelog.xml 4 Aug 2005 11:54:20 -0000 1.352 +++ changelog.xml 4 Aug 2005 13:06:56 -0000 1.353 @@ -75,6 +75,10 @@ <fix> Add version check for Tomcat native so that incompatible API changes are detected early (remm) </fix> + <fix> + <bug>36020</bug>: Allow MemoryUserDatabase to work better on write protected mediums, + submitted by Rainer Jung (remm) + </fix> </changelog> </subsection>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]