Source Code Cross Referenced for JSXUserManager.java in  » Net » DrFTPD » net » sf » drftpd » master » usermanager » jsx » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » DrFTPD » net.sf.drftpd.master.usermanager.jsx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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 JSX.ObjIn;
021:
022:        import net.sf.drftpd.DuplicateElementException;
023:        import net.sf.drftpd.FatalException;
024:        import net.sf.drftpd.FileExistsException;
025:
026:        import org.apache.log4j.Level;
027:        import org.apache.log4j.Logger;
028:
029:        import org.drftpd.GlobalContext;
030:        import org.drftpd.commands.UserManagement;
031:        import org.drftpd.dynamicdata.KeyNotFoundException;
032:
033:        import org.drftpd.master.ConnectionManager;
034:        import org.drftpd.usermanager.NoSuchUserException;
035:        import org.drftpd.usermanager.User;
036:        import org.drftpd.usermanager.UserExistsException;
037:        import org.drftpd.usermanager.UserFileException;
038:        import org.drftpd.usermanager.UserManager;
039:
040:        import java.io.File;
041:        import java.io.FileNotFoundException;
042:        import java.io.FileReader;
043:        import java.io.IOException;
044:
045:        import java.util.ArrayList;
046:        import java.util.Collection;
047:        import java.util.Hashtable;
048:        import java.util.Iterator;
049:
050:        /**
051:         * @author mog
052:         * @version $Id: JSXUserManager.java 984 2005-02-11 02:22:16Z zubov $
053:         */
054:        public class JSXUserManager implements  UserManager {
055:            private static final Logger logger = Logger
056:                    .getLogger(JSXUserManager.class.getName());
057:            private GlobalContext _gctx;
058:            String userpath = "users/jsx/";
059:            File userpathFile = new File(userpath);
060:            Hashtable users = new Hashtable();
061:
062:            public JSXUserManager() throws UserFileException {
063:                if (!userpathFile.exists() && !userpathFile.mkdirs()) {
064:                    throw new UserFileException(new IOException(
065:                            "Error creating folders: " + userpathFile));
066:                }
067:
068:                String[] userfilenames = userpathFile.list();
069:                int numUsers = 0;
070:
071:                for (int i = 0; i < userfilenames.length; i++) {
072:                    String string = userfilenames[i];
073:
074:                    if (string.endsWith(".xml")) {
075:                        numUsers++;
076:                    }
077:                }
078:
079:                if (numUsers == 0) {
080:                    User user = create("drftpd");
081:                    user.setGroup("drftpd");
082:                    user.setPassword("drftpd");
083:                    user.getKeyedMap().setObject(UserManagement.RATIO,
084:                            new Float(0));
085:
086:                    try {
087:                        user.addIPMask("*@127.0.0.1");
088:                        user.addIPMask("*@0:0:0:0:0:0:0:1");
089:                    } catch (DuplicateElementException e) {
090:                    }
091:
092:                    try {
093:                        user.addSecondaryGroup("siteop");
094:                    } catch (DuplicateElementException e1) {
095:                    }
096:
097:                    user.commit();
098:                }
099:            }
100:
101:            public User create(String username) throws UserFileException {
102:                try {
103:                    getUserByName(username);
104:
105:                    //bad
106:                    throw new FileExistsException("User already exists");
107:                } catch (IOException e) {
108:                    //bad
109:                    throw new UserFileException(e);
110:                } catch (NoSuchUserException e) {
111:                    //good
112:                }
113:
114:                JSXUser user = new JSXUser(this , username);
115:                users.put(user.getName(), user);
116:
117:                return user;
118:            }
119:
120:            public boolean exists(String username) {
121:                return getUserFile(username).exists();
122:            }
123:
124:            public Collection getAllGroups() throws UserFileException {
125:                Collection users = this .getAllUsers();
126:                ArrayList ret = new ArrayList();
127:
128:                for (Iterator iter = users.iterator(); iter.hasNext();) {
129:                    User myUser = (User) iter.next();
130:                    Collection myGroups = myUser.getGroups();
131:
132:                    for (Iterator iterator = myGroups.iterator(); iterator
133:                            .hasNext();) {
134:                        String myGroup = (String) iterator.next();
135:
136:                        if (!ret.contains(myGroup)) {
137:                            ret.add(myGroup);
138:                        }
139:                    }
140:                }
141:
142:                return ret;
143:            }
144:
145:            public Collection getAllUsers() throws UserFileException {
146:                ArrayList users = new ArrayList();
147:
148:                String[] userpaths = userpathFile.list();
149:
150:                for (int i = 0; i < userpaths.length; i++) {
151:                    String userpath = userpaths[i];
152:
153:                    if (!userpath.endsWith(".xml")) {
154:                        continue;
155:                    }
156:
157:                    String username = userpath.substring(0, userpath.length()
158:                            - ".xml".length());
159:
160:                    try {
161:                        users.add((JSXUser) getUserByNameUnchecked(username));
162:
163:                        // throws IOException
164:                    } catch (NoSuchUserException e) {
165:                    } // continue
166:                }
167:
168:                return users;
169:            }
170:
171:            public Collection getAllUsersByGroup(String group)
172:                    throws UserFileException {
173:                Collection users = getAllUsers();
174:
175:                for (Iterator iter = users.iterator(); iter.hasNext();) {
176:                    JSXUser user = (JSXUser) iter.next();
177:
178:                    if (!user.isMemberOf(group)) {
179:                        iter.remove();
180:                    }
181:                }
182:
183:                return users;
184:            }
185:
186:            public User getUserByNameUnchecked(String username)
187:                    throws NoSuchUserException, UserFileException {
188:                try {
189:                    JSXUser user = (JSXUser) users.get(username);
190:
191:                    if (user != null) {
192:                        return user;
193:                    }
194:
195:                    ObjIn in;
196:
197:                    try {
198:                        in = new ObjIn(new FileReader(getUserFile(username)));
199:                    } catch (FileNotFoundException ex) {
200:                        throw new NoSuchUserException("No such user");
201:                    }
202:
203:                    try {
204:                        user = (JSXUser) in.readObject();
205:
206:                        //throws RuntimeException
207:                        user.setUserManager(this );
208:                        users.put(user.getName(), user);
209:                        //user.reset(getGlobalContext());
210:
211:                        return user;
212:                    } catch (ClassNotFoundException e) {
213:                        throw new FatalException(e);
214:                    } finally {
215:                        in.close();
216:                    }
217:                } catch (Throwable ex) {
218:                    if (ex instanceof  NoSuchUserException) {
219:                        throw (NoSuchUserException) ex;
220:                    }
221:
222:                    throw new UserFileException("Error loading " + username, ex);
223:                }
224:            }
225:
226:            private GlobalContext getGlobalContext() {
227:                return _gctx;
228:            }
229:
230:            public User getUserByName(String username)
231:                    throws NoSuchUserException, UserFileException {
232:                JSXUser user = (JSXUser) getUserByNameUnchecked(username);
233:
234:                if (user.isDeleted()) {
235:                    throw new NoSuchUserException(user.getName()
236:                            + " is deleted");
237:                }
238:
239:                user.reset(getGlobalContext());
240:
241:                return user;
242:            }
243:
244:            public File getUserFile(String username) {
245:                return new File(userpath + username + ".xml");
246:            }
247:
248:            void remove(JSXUser user) {
249:                this .users.remove(user.getName());
250:            }
251:
252:            void rename(JSXUser oldUser, String newUsername)
253:                    throws UserExistsException {
254:                if (users.contains(newUsername)) {
255:                    throw new UserExistsException("user " + newUsername
256:                            + " exists");
257:                }
258:
259:                users.remove(oldUser.getName());
260:                users.put(newUsername, oldUser);
261:            }
262:
263:            public void saveAll() throws UserFileException {
264:                logger.log(Level.INFO, "Saving userfiles");
265:
266:                for (Iterator iter = users.values().iterator(); iter.hasNext();) {
267:                    Object obj = iter.next();
268:
269:                    if (!(obj instanceof  JSXUser)) {
270:                        throw new ClassCastException(
271:                                "Only accepts JSXUser objects");
272:                    }
273:
274:                    JSXUser user = (JSXUser) obj;
275:                    user.commit();
276:                }
277:            }
278:
279:            public void init(GlobalContext gctx) {
280:                _gctx = gctx;
281:            }
282:
283:            public User getUserByNameIncludeDeleted(String argument)
284:                    throws NoSuchUserException, UserFileException {
285:                return getUserByName(argument);
286:            }
287:
288:            public User getUserByIdent(String ident)
289:                    throws NoSuchUserException, UserFileException {
290:                for (Iterator iter = getAllUsers().iterator(); iter.hasNext();) {
291:                    User user = (User) iter.next();
292:                    try {
293:                        String uident = (String) user.getKeyedMap().getObject(
294:                                UserManagement.IRCIDENT);
295:                        if (uident.equals(ident)) {
296:                            return user;
297:                        }
298:                    } catch (KeyNotFoundException e1) {
299:                    }
300:                }
301:                throw new NoSuchUserException("No user found with ident = "
302:                        + ident);
303:            }
304:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.