Source Code Cross Referenced for FileLoginModule.java in  » Database-ORM » MMBase » org » mmbase » security » implementation » basic » 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 » Database ORM » MMBase » org.mmbase.security.implementation.basic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:        This software is OSI Certified Open Source Software.
004:        OSI Certified is a certification mark of the Open Source Initiative.
005:
006:        The license (Mozilla version 1.0) can be read at the MMBase site.
007:        See http://www.MMBase.org/license
008:
009:         */
010:        package org.mmbase.security.implementation.basic;
011:
012:        import java.util.Map;
013:        import java.io.File;
014:
015:        import org.mmbase.security.Rank;
016:
017:        import org.mmbase.util.ExtendedProperties;
018:        import org.mmbase.util.logging.Logger;
019:        import org.mmbase.util.logging.Logging;
020:
021:        /**
022:         * Simple implemetation, to provide authentication from files...
023:         * @javadoc
024:         * @author Eduard Witteveen
025:         * @version $Id: FileLoginModule.java,v 1.7 2008/01/10 14:12:24 michiel Exp $
026:         */
027:        public class FileLoginModule implements  LoginModule {
028:            private static Logger log = Logging
029:                    .getLoggerInstance(FileLoginModule.class.getName());
030:            private File configFile = null;
031:
032:            public void load(Map<String, Object> properties) {
033:                String passwordFile = (String) properties.get("file");
034:
035:                if (passwordFile == null || passwordFile.equals("")) {
036:                    configFile = new File(org.mmbase.module.core.MMBaseContext
037:                            .getConfigPath()
038:                            + java.io.File.separator + "accounts.properties");
039:                    log
040:                            .warn("property file not specified, now using as config file :"
041:                                    + configFile);
042:                } else {
043:                    configFile = new File(passwordFile);
044:                }
045:
046:                if (!configFile.isAbsolute()) {
047:                    File parentFile = (File) properties.get("_parentFile");
048:                    log.debug("" + configFile.getPath() + " is not absolute.");
049:                    configFile = new File(parentFile.getParent()
050:                            + File.separator + configFile.getPath());
051:                    log.debug("Trying " + configFile.getAbsolutePath());
052:                }
053:
054:                log
055:                        .debug("trying to load file login modules with password file:"
056:                                + configFile.getAbsolutePath());
057:
058:                if (!configFile.exists()) {
059:                    log.error("file: '" + configFile + "' did not exist.");
060:                    throw new org.mmbase.security.SecurityException("file: '"
061:                            + configFile + "' did not exist.");
062:                }
063:                if (!configFile.isFile()) {
064:                    log.error("file: '" + configFile + "' is not a file.");
065:                    throw new org.mmbase.security.SecurityException("file: '"
066:                            + configFile + "' is not a file.");
067:                }
068:                if (!configFile.canRead()) {
069:                    log.error("file: '" + configFile + "' is not readable.");
070:                    throw new org.mmbase.security.SecurityException("file: '"
071:                            + configFile + "' is not readable.");
072:                }
073:                log.debug("file login loaded");
074:            }
075:
076:            public boolean login(NameContext user,
077:                    Map<String, Object> loginInfo, Object[] parameters) {
078:                if (!loginInfo.containsKey("username"))
079:                    throw new org.mmbase.security.SecurityException(
080:                            "key 'username' not found  in login information");
081:                if (!loginInfo.containsKey("password"))
082:                    throw new org.mmbase.security.SecurityException(
083:                            "key 'password' not found  in login information");
084:                ExtendedProperties reader = new ExtendedProperties();
085:
086:                log.debug("reading accounts from " + configFile);
087:                java.util.Hashtable accounts = reader.readProperties(configFile
088:                        .getAbsolutePath());
089:
090:                if (accounts == null) {
091:                    log.error("Could not find accounts!");
092:                }
093:
094:                // do a list with usernames and passwords...
095:                log.debug("There are  " + accounts.size()
096:                        + " users which can logon to our system");
097:                if (!accounts.containsKey(loginInfo.get("username"))) {
098:                    log.debug("username: '" + loginInfo.get("username")
099:                            + "' not found");
100:                    return false;
101:                }
102:                String neededPass = (String) accounts.get(loginInfo
103:                        .get("username"));
104:                if (!neededPass.equals(loginInfo.get("password"))) {
105:                    log
106:                            .debug("username/password combination invalid(in HashTable values user:'"
107:                                    + loginInfo.get("username")
108:                                    + "' password:'"
109:                                    + loginInfo.get("password") + "')");
110:                    return false;
111:                }
112:
113:                // set the identifier
114:                user.setIdentifier((String) loginInfo.get("username"));
115:
116:                // Admins are admins
117:                if ("admin".equals(loginInfo.get("username"))) {
118:                    user.setRank(Rank.getRank("administrator"));
119:                }
120:
121:                log.info("user: '" + loginInfo.get("username")
122:                        + "' passed this login module");
123:                return true;
124:            }
125:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.