FileDocCategorySizeDatePackage
UserManager.javaAPI DocAzureus 3.0.3.46143Sun Aug 20 03:46:26 BST 2006org.gudy.azureus2.ui.console.multiuser

UserManager

public class UserManager extends Object
The usermanager is responsible for reading the users configuration file and loading in all of the possible users. It is also responsible for authenticating a username/password
author
pauld

Fields Summary
private static final String
USER_DB_CONFIG_FILE
private static UserManager
instance
private Map
usersMap
private final String
fileName
Constructors Summary
public UserManager(String fileName)

param
configFile

	
	  	 
	  
	
		super();
		this.fileName = fileName;
	
Methods Summary
public voidaddUser(org.gudy.azureus2.ui.console.UserProfile user)
adds another user to the users list

param
user

		usersMap.put( user.getUsername().toLowerCase(), user );
	
public org.gudy.azureus2.ui.console.UserProfileauthenticate(java.lang.String username, java.lang.String password)
attempts to locate a user with the specified username and then verifies that the specified password is the same as the password associated with that user

param
username
param
password
return

		UserProfile profile = getUser(username);
		if( profile != null)
		{
			if( profile.authenticate( password ) )
				return profile;
		}
		return null;
	
public voiddeleteUser(java.lang.String userName)
removes the user with the specified name

param
userName

		usersMap.remove(userName.toLowerCase());
	
protected voiddoLoad(java.io.InputStream in)

		XMLDecoder decoder = new XMLDecoder( in );
		UserManagerConfig managerConfig = (UserManagerConfig)decoder.readObject();
		for (Iterator iter = managerConfig.getUsers().iterator(); iter.hasNext();) {
			UserProfile user = (UserProfile) iter.next();
			usersMap.put(user.getUsername().toLowerCase(), user);
		}
		System.out.println("UserManager: registered " + usersMap.size() + " users");
		decoder.close();
	
protected voiddoSave(java.io.OutputStream out)

		UserManagerConfig config = new UserManagerConfig();
		List users = new ArrayList( usersMap.values() );
		config.setUsers(users);
		
		XMLEncoder encoder = new XMLEncoder( new BufferedOutputStream( out ) );
		encoder.writeObject(config);
		encoder.close();
	
public static org.gudy.azureus2.ui.console.multiuser.UserManagergetInstance(org.gudy.azureus2.plugins.PluginInterface pi)

		
		if( instance == null )
		{
			String azureusUserDir = pi.getUtilities().getAzureusUserDir();
			File dbFile = new File(azureusUserDir, USER_DB_CONFIG_FILE);
			
			try {
				instance = new UserManager(dbFile.getCanonicalPath());
				if( dbFile.exists() )
				{
					System.out.println("loading user configuration from: " + dbFile.getCanonicalPath());
					instance.load();
				}
				else
				{
					System.out.println("file: " + dbFile.getCanonicalPath() + " does not exist. using 'null' user manager");
				}
			} catch (IOException e)
			{
				throw new AzureusCoreException("Unable to instantiate default user manager");
			}
			
		}
		return instance;
	
public org.gudy.azureus2.ui.console.UserProfilegetUser(java.lang.String username)
returns the profile for the user with the specified username otherwise null if there is no such user

param
username
return

		return (UserProfile) usersMap.get(username.toLowerCase());
	
public java.util.CollectiongetUsers()

		return Collections.unmodifiableCollection(usersMap.values());
	
public voidload()
load a new UserManager object from the specified input stream. The input stream should contain an XML document as encoded by the save() method

param
in
return
UserManager object
throws
FileNotFoundException

		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fileName));
		doLoad( bis );
	
public voidsave()
write the UserManager configuration out to the specified output stream. the configuration is stored in XML format as specified by the XMLEncoder class

param
out
throws
FileNotFoundException
see
XMLEncoder

		OutputStream out = new FileOutputStream(fileName);
		doSave(out);