You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2018/09/14 07:27:09 UTC
svn commit: r1840892 -
/tomcat/trunk/java/org/apache/catalina/users/MemoryUserDatabase.java
Author: markt
Date: Fri Sep 14 07:27:09 2018
New Revision: 1840892
URL: http://svn.apache.org/viewvc?rev=1840892&view=rev
Log:
Clean-up. No functional change.
Modified:
tomcat/trunk/java/org/apache/catalina/users/MemoryUserDatabase.java
Modified: tomcat/trunk/java/org/apache/catalina/users/MemoryUserDatabase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/users/MemoryUserDatabase.java?rev=1840892&r1=1840891&r2=1840892&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/users/MemoryUserDatabase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/users/MemoryUserDatabase.java Fri Sep 14 07:27:09 2018
@@ -39,20 +39,20 @@ import org.apache.tomcat.util.res.String
import org.xml.sax.Attributes;
/**
- * <p>Concrete implementation of {@link UserDatabase} that loads all
- * defined users, groups, and roles into an in-memory data structure,
- * and uses a specified XML file for its persistent storage.</p>
+ * Concrete implementation of {@link UserDatabase} that loads all defined users,
+ * groups, and roles into an in-memory data structure, and uses a specified XML
+ * file for its persistent storage.
*
* @author Craig R. McClanahan
* @since 4.1
*/
public class MemoryUserDatabase implements UserDatabase {
-
private static final Log log = LogFactory.getLog(MemoryUserDatabase.class);
+ private static final StringManager sm = StringManager.getManager(MemoryUserDatabase.class);
- // ----------------------------------------------------------- Constructors
+ // ----------------------------------------------------------- Constructors
/**
* Create a new instance with default values.
@@ -71,73 +71,54 @@ public class MemoryUserDatabase implemen
this.id = id;
}
-
// ----------------------------------------------------- Instance Variables
-
/**
- * The set of {@link Group}s defined in this database, keyed by
- * group name.
+ * The set of {@link Group}s defined in this database, keyed by group name.
*/
- protected final HashMap<String,Group> groups = new HashMap<>();
-
+ protected final HashMap<String, Group> groups = new HashMap<>();
/**
* The unique global identifier of this user database.
*/
protected final String id;
-
/**
- * The relative (to <code>catalina.base</code>) or absolute pathname to
- * the XML file in which we will save our persistent information.
+ * The relative (to <code>catalina.base</code>) or absolute pathname to the
+ * XML file in which we will save our persistent information.
*/
protected String pathname = "conf/tomcat-users.xml";
-
/**
* The relative or absolute pathname to the file in which our old
* information is stored while renaming is in progress.
*/
protected String pathnameOld = pathname + ".old";
-
/**
- * The relative or absolute pathname of the file in which we write
- * our new information prior to renaming.
+ * The relative or absolute pathname of the file in which we write our new
+ * information prior to renaming.
*/
protected String pathnameNew = pathname + ".new";
-
/**
* A flag, indicating if the user database is read only.
*/
protected boolean readonly = true;
/**
- * The set of {@link Role}s defined in this database, keyed by
- * role name.
+ * The set of {@link Role}s defined in this database, keyed by role name.
*/
- protected final HashMap<String,Role> roles = new HashMap<>();
-
-
- /**
- * The string manager for this package.
- */
- private static final StringManager sm =
- StringManager.getManager(Constants.Package);
-
+ protected final HashMap<String, Role> roles = new HashMap<>();
/**
- * The set of {@link User}s defined in this database, keyed by
- * user name.
+ * The set of {@link User}s defined in this database, keyed by user name.
*/
- protected final HashMap<String,User> users = new HashMap<>();
+ protected final HashMap<String, User> users = new HashMap<>();
// ------------------------------------------------------------- Properties
-
/**
* @return the set of {@link Group}s defined in this user database.
*/
@@ -172,11 +153,9 @@ public class MemoryUserDatabase implemen
* @param pathname The new pathname
*/
public void setPathname(String pathname) {
-
this.pathname = pathname;
this.pathnameOld = pathname + ".old";
this.pathnameNew = pathname + ".new";
-
}
@@ -194,9 +173,7 @@ public class MemoryUserDatabase implemen
* @param readonly the new status
*/
public void setReadonly(boolean readonly) {
-
this.readonly = readonly;
-
}
@@ -222,10 +199,8 @@ public class MemoryUserDatabase implemen
}
-
// --------------------------------------------------------- Public Methods
-
/**
* Finalize access to this user database.
*
@@ -242,7 +217,6 @@ public class MemoryUserDatabase implemen
groups.clear();
}
}
-
}
@@ -298,8 +272,7 @@ public class MemoryUserDatabase implemen
* @param fullName The full name of the new user
*/
@Override
- public User createUser(String username, String password,
- String fullName) {
+ public User createUser(String username, String password, String fullName) {
if (username == null || username.length() == 0) {
String msg = sm.getString("memoryUserDatabase.nullUser");
@@ -316,50 +289,44 @@ public class MemoryUserDatabase implemen
/**
- * Return the {@link Group} with the specified group name, if any;
- * otherwise return <code>null</code>.
+ * Return the {@link Group} with the specified group name, if any; otherwise
+ * return <code>null</code>.
*
* @param groupname Name of the group to return
*/
@Override
public Group findGroup(String groupname) {
-
synchronized (groups) {
return groups.get(groupname);
}
-
}
/**
- * Return the {@link Role} with the specified role name, if any;
- * otherwise return <code>null</code>.
+ * Return the {@link Role} with the specified role name, if any; otherwise
+ * return <code>null</code>.
*
* @param rolename Name of the role to return
*/
@Override
public Role findRole(String rolename) {
-
synchronized (roles) {
return roles.get(rolename);
}
-
}
/**
- * Return the {@link User} with the specified user name, if any;
- * otherwise return <code>null</code>.
+ * Return the {@link User} with the specified user name, if any; otherwise
+ * return <code>null</code>.
*
* @param username Name of the user to return
*/
@Override
public User findUser(String username) {
-
synchronized (users) {
return users.get(username);
}
-
}
@@ -384,17 +351,13 @@ public class MemoryUserDatabase implemen
// Construct a digester to read the XML input file
Digester digester = new Digester();
try {
- digester.setFeature(
- "http://apache.org/xml/features/allow-java-encodings", true);
+ digester.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
} catch (Exception e) {
log.warn(sm.getString("memoryUserDatabase.xmlFeatureEncoding"), e);
}
- digester.addFactoryCreate("tomcat-users/group",
- new MemoryGroupCreationFactory(this), true);
- digester.addFactoryCreate("tomcat-users/role",
- new MemoryRoleCreationFactory(this), true);
- digester.addFactoryCreate("tomcat-users/user",
- new MemoryUserCreationFactory(this), true);
+ digester.addFactoryCreate("tomcat-users/group", new MemoryGroupCreationFactory(this), true);
+ digester.addFactoryCreate("tomcat-users/role", new MemoryRoleCreationFactory(this), true);
+ digester.addFactoryCreate("tomcat-users/user", new MemoryUserCreationFactory(this), true);
// Parse the XML input to load this database
digester.parse(is);
@@ -446,7 +409,6 @@ public class MemoryUserDatabase implemen
}
roles.remove(role.getRolename());
}
-
}
@@ -457,25 +419,23 @@ public class MemoryUserDatabase implemen
*/
@Override
public void removeUser(User user) {
-
synchronized (users) {
users.remove(user.getUsername());
}
-
}
/**
* Check for permissions to save this user database to persistent storage
* location.
+ *
* @return <code>true</code> if the database is writable
*/
public boolean isWriteable() {
File file = new File(pathname);
if (!file.isAbsolute()) {
- file = new File(System.getProperty(Globals.CATALINA_BASE_PROP),
- pathname);
+ file = new File(System.getProperty(Globals.CATALINA_BASE_PROP), pathname);
}
File dir = file.getParentFile();
return dir.exists() && dir.isDirectory() && dir.canWrite();
@@ -483,8 +443,8 @@ public class MemoryUserDatabase implemen
/**
- * Save any updated information to the persistent storage location for
- * this user database.
+ * Save any updated information to the persistent storage location for this
+ * user database.
*
* @exception Exception if any exception is thrown during saving
*/
@@ -541,8 +501,7 @@ public class MemoryUserDatabase implemen
// Check for errors that occurred while printing
if (writer.checkError()) {
- throw new IOException(sm.getString("memoryUserDatabase.writeException",
- fileNew.getAbsolutePath()));
+ throw new IOException(sm.getString("memoryUserDatabase.writeException", fileNew.getAbsolutePath()));
}
} catch (IOException e) {
if (fileNew.exists() && !fileNew.delete()) {
@@ -565,8 +524,7 @@ public class MemoryUserDatabase implemen
}
if (fileOrig.exists()) {
if (!fileOrig.renameTo(fileOld)) {
- throw new IOException(sm.getString("memoryUserDatabase.renameOld",
- fileOld.getAbsolutePath()));
+ throw new IOException(sm.getString("memoryUserDatabase.renameOld", fileOld.getAbsolutePath()));
}
}
if (!fileNew.renameTo(fileOrig)) {
@@ -575,8 +533,7 @@ public class MemoryUserDatabase implemen
log.warn(sm.getString("memoryUserDatabase.restoreOrig", fileOld));
}
}
- throw new IOException(sm.getString("memoryUserDatabase.renameNew",
- fileOrig.getAbsolutePath()));
+ throw new IOException(sm.getString("memoryUserDatabase.renameNew", fileOrig.getAbsolutePath()));
}
if (fileOld.exists() && !fileOld.delete()) {
throw new IOException(sm.getString("memoryUserDatabase.fileDelete", fileOld));
@@ -605,7 +562,6 @@ public class MemoryUserDatabase implemen
}
-
/**
* Digester object creation factory for group instances.
*/
@@ -615,6 +571,7 @@ class MemoryGroupCreationFactory extends
this.database = database;
}
+
@Override
public Object createObject(Attributes attributes) {
String groupname = attributes.getValue("groupname");
@@ -660,6 +617,7 @@ class MemoryRoleCreationFactory extends
this.database = database;
}
+
@Override
public Object createObject(Attributes attributes) {
String rolename = attributes.getValue("rolename");
@@ -684,6 +642,7 @@ class MemoryUserCreationFactory extends
this.database = database;
}
+
@Override
public Object createObject(Attributes attributes) {
String username = attributes.getValue("username");
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org