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 net.sf.drftpd.master.usermanager.jsx;
019:
020: import java.io.File;
021: import java.io.IOException;
022: import java.io.ObjectInputStream;
023: import java.util.ArrayList;
024:
025: import net.sf.drftpd.master.usermanager.AbstractUser;
026: import net.sf.drftpd.util.Crypt;
027:
028: import org.drftpd.usermanager.PlainTextPasswordUser;
029: import org.drftpd.usermanager.UnixPassword;
030: import org.drftpd.usermanager.UserExistsException;
031: import org.drftpd.usermanager.UserFileException;
032: import org.drftpd.usermanager.UserManager;
033:
034: /**
035: * @author mog
036: * @version $Id: JSXUser.java 1114 2005-03-13 01:26:58Z zubov $
037: */
038: public class JSXUser extends AbstractUser implements
039: PlainTextPasswordUser, UnixPassword {
040: private String unixPassword;
041: private String password;
042: private transient JSXUserManager _usermanager;
043: private transient boolean purged;
044:
045: public JSXUser(JSXUserManager usermanager, String username) {
046: super (username);
047: created = System.currentTimeMillis();
048: _usermanager = usermanager;
049: }
050:
051: public boolean checkPassword(String password) {
052: if (this .password == null) {
053: if (this .unixPassword == null) {
054: throw new IllegalStateException("no password set");
055: }
056:
057: if (this .unixPassword.equals(Crypt.crypt(this .unixPassword
058: .substring(0, 2), password))) {
059: setPassword(password);
060:
061: return true;
062: }
063:
064: return false;
065: }
066:
067: return this .password.equals(password);
068: }
069:
070: public void setPassword(String password) {
071: this .unixPassword = null;
072: this .password = password;
073: }
074:
075: public String getPassword() {
076: return this .password;
077: }
078:
079: public void rename(String username) throws UserExistsException,
080: UserFileException {
081: _usermanager.rename(this , username); // throws ObjectExistsException
082: _usermanager.getUserFile(this .getName()).delete();
083: this .username = username;
084: commit(); // throws IOException
085: }
086:
087: public void commit() throws UserFileException {
088: throw new UnsupportedOperationException();
089: }
090:
091: public void purge() {
092: this .purged = true;
093: _usermanager.remove(this );
094:
095: File userfile = _usermanager.getUserFile(this .getName());
096: userfile.delete();
097: }
098:
099: protected void finalize() throws Throwable {
100: this .commit();
101: }
102:
103: public void update() {
104: //an update was made, but commit() should be called from all places so we don't need to do anything.
105: //if we do, make sure it's implemented in all set and update methods in AbstractUser
106: }
107:
108: public String getUnixPassword() {
109: return unixPassword;
110: }
111:
112: public void setUnixPassword(String password) {
113: this .password = null;
114: this .unixPassword = password;
115: }
116:
117: private void readObject(ObjectInputStream stream)
118: throws IOException, ClassNotFoundException {
119: stream.defaultReadObject();
120:
121: if (groups == null) {
122: groups = new ArrayList();
123: }
124:
125: if (ipMasks == null) {
126: ipMasks = new ArrayList();
127: }
128:
129: if (tagline == null) {
130: tagline = "";
131: }
132: }
133:
134: public void setUserManager(JSXUserManager manager) {
135: _usermanager = manager;
136: }
137:
138: public UserManager getUserManager() {
139: return _usermanager;
140: }
141: }
|