001: /*
002: * This file is part of DrFTPD, Distributed FTP Daemon.
003: *
004: * DrFTPD is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * DrFTPD is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with DrFTPD; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018: package org.drftpd.usermanager.javabeans;
019:
020: import java.beans.XMLEncoder;
021: import java.io.IOException;
022: import java.io.Serializable;
023:
024: import org.apache.log4j.Logger;
025: import org.drftpd.commands.UserManagement;
026: import org.drftpd.io.SafeFileOutputStream;
027: import org.drftpd.usermanager.AbstractUser;
028: import org.drftpd.usermanager.AbstractUserManager;
029: import org.drftpd.usermanager.UserFileException;
030: import org.drftpd.usermanager.UserManager;
031:
032: /**
033: * @author mog
034: * @version $Id: BeanUser.java 1513 2006-10-13 22:41:08Z tdsoul $
035: */
036: public class BeanUser extends AbstractUser implements Serializable {
037:
038: private BeanUserManager _um;
039: private String _password = "";
040: private boolean _purged;
041: private static final Logger logger = Logger
042: .getLogger(BeanUser.class);
043:
044: public BeanUser(String username) {
045: super (username);
046: }
047:
048: public BeanUser(BeanUserManager manager, String username) {
049: super (username);
050: _um = manager;
051: }
052:
053: public AbstractUserManager getAbstractUserManager() {
054: return _um;
055: }
056:
057: public UserManager getUserManager() {
058: return _um;
059: }
060:
061: public boolean checkPassword(String password) {
062: return password.equals(_password);
063: }
064:
065: public void commit() throws UserFileException {
066: if (_purged)
067: return;
068: XMLEncoder out = null;
069: try {
070: out = _um.getXMLEncoder(new SafeFileOutputStream(_um
071: .getUserFile(getName())));
072: out.writeObject(this );
073: } catch (IOException ex) {
074: throw new UserFileException(ex);
075: } finally {
076: if (out != null)
077: out.close();
078: }
079: }
080:
081: public void purge() {
082: _purged = true;
083: _um.delete(getName());
084: }
085:
086: public String getPassword() {
087: return _password;
088: }
089:
090: public void setPassword(String password) {
091: _password = password;
092: }
093:
094: public void setUserManager(BeanUserManager manager) {
095: _um = manager;
096: }
097:
098: /**
099: * Setter for userfile backwards comptibility.
100: * Should work but i had nothing to test with.
101: */
102: // public void setGroupSlots(int s) {
103: // getKeyedMap().setObject(UserManagement.GROUPSLOTS, s);
104: // }
105: /**
106: * Setter for userfile backwards comptibility.
107: * Should work but i had nothing to test with.
108: */
109: public void setGroupLeechSlots(short s) {
110: getKeyedMap().setObject(UserManagement.LEECHSLOTS, s);
111: }
112: }
|