Source Code Cross Referenced for CIFSUser.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » ac » cifs » 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 » Content Management System » apache lenya 2.0 » org.apache.lenya.ac.cifs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         * 
009:         * http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software distributed under the License
012:         * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
013:         * or implied. See the License for the specific language governing permissions and limitations under
014:         * the License.
015:         *  
016:         */
017:
018:        package org.apache.lenya.ac.cifs;
019:
020:        import java.io.File;
021:        import java.io.FileInputStream;
022:        import java.io.IOException;
023:        import java.util.Properties;
024:
025:        import org.apache.lenya.ac.ItemManager;
026:        import org.apache.lenya.ac.file.FileUser;
027:
028:        import org.apache.avalon.framework.configuration.Configuration;
029:        import org.apache.avalon.framework.configuration.ConfigurationException;
030:        import org.apache.avalon.framework.logger.Logger;
031:
032:        import jcifs.smb.NtlmPasswordAuthentication;
033:        import jcifs.smb.SmbAuthException;
034:        import jcifs.smb.SmbException;
035:        import jcifs.smb.SmbSession;
036:
037:        import jcifs.UniAddress;
038:        import java.net.UnknownHostException;
039:
040:        /**
041:         * CIFS user.
042:         * @version $Id: CIFSUser.java 485769 2006-12-11 17:41:23Z andreas $
043:         */
044:        public class CIFSUser extends FileUser {
045:
046:            /**
047:             * 
048:             */
049:            private static final long serialVersionUID = 1L;
050:
051:            private static Properties defaultProperties = null;
052:
053:            // The name for the cifs.properties domain controller lookup
054:            private static final String DOMAIN_CONTROLLER = "domain-controller";
055:
056:            // The name for the cifs.properties domain name lookup
057:            private static final String DOMAIN = "domain";
058:
059:            /**
060:             * Creates a new CIFSUser object.
061:             * @param itemManager The item manager.
062:             * @param logger The logger.
063:             */
064:            public CIFSUser(ItemManager itemManager, Logger logger) {
065:                super (itemManager, logger);
066:
067:            }
068:
069:            /**
070:             * Create a CIFSUser
071:             * @param itemManager The item manager.
072:             * @param logger The logger.
073:             * @param id The user ID.
074:             * @param fullName The user's name.
075:             * @param email The e-mail address.
076:             * @param password The password.
077:             */
078:            public CIFSUser(ItemManager itemManager, Logger logger, String id,
079:                    String fullName, String email, String password) {
080:                super (itemManager, logger, id, fullName, email, password);
081:
082:            }
083:
084:            /**
085:             * Initializes this user.
086:             * @throws ConfigurationException when something went wrong.
087:             */
088:            protected void initialize() throws ConfigurationException {
089:                try {
090:                    readProperties(super .getConfigurationDirectory());
091:                } catch (final IOException ioe) {
092:                    throw new ConfigurationException(
093:                            "Reading cifs.properties file in ["
094:                                    + super .getConfigurationDirectory()
095:                                    + "] failed", ioe);
096:                }
097:            }
098:
099:            /**
100:             * Create a new CIFSUser from a configuration
101:             * @param config the <code>Configuration</code> specifying the user
102:             *        details
103:             * @throws ConfigurationException if the user could not be instantiated
104:             */
105:            public void configure(Configuration config)
106:                    throws ConfigurationException {
107:                super .configure(config);
108:                initialize();
109:            }
110:
111:            /**
112:             * Authenticate a user. This is done by NTDomain Authentication using jcifs
113:             * @param password to authenticate with
114:             * @return true if the given password matches the password for this user
115:             */
116:            public boolean authenticate(String password) {
117:
118:                System.setProperty(
119:                        "jcifs.smb.client.disablePlainTextPasswords", "true");
120:                try {
121:                    UniAddress mydomaincontroller = UniAddress
122:                            .getByName(getDomainController());
123:                    NtlmPasswordAuthentication mycreds = new NtlmPasswordAuthentication(
124:                            getDomainName(), super .getId(), password);
125:                    SmbSession.logon(mydomaincontroller, mycreds);
126:                    // SUCCESS
127:                    return true;
128:                } catch (final SmbAuthException sae) {
129:                    // AUTHENTICATION FAILURE
130:                    if (getLogger().isInfoEnabled()) {
131:                        getLogger().info(
132:                                "Authentication against ["
133:                                        + getDomainController() + "]"
134:                                        + " failed for " + getDomainName()
135:                                        + "/" + super .getId());
136:                    }
137:                    return false;
138:                } catch (final SmbException se) {
139:                    // NETWORK PROBLEMS?
140:                    return false;
141:                } catch (final UnknownHostException unho) {
142:                    return false;
143:                }
144:
145:            }
146:
147:            /**
148:             * Read the properties
149:             * @param configurationDirectory The configuration directory.
150:             * @throws IOException if the properties cannot be found.
151:             */
152:            private void readProperties(File configurationDirectory)
153:                    throws IOException {
154:                // create and load default properties
155:                File propertiesFile = new File(configurationDirectory,
156:                        "cifs.properties");
157:
158:                if (defaultProperties == null) {
159:                    defaultProperties = new Properties();
160:
161:                    FileInputStream in = null;
162:                    try {
163:                        in = new FileInputStream(propertiesFile);
164:                        defaultProperties.load(in);
165:                    } finally {
166:                        if (in != null) {
167:                            in.close();
168:                        }
169:                    }
170:
171:                }
172:            }
173:
174:            /**
175:             * Get the domain controller we want to authenticate against
176:             * @return the name of the domain controller
177:             */
178:            private String getDomainController() {
179:                return (String) defaultProperties.get(DOMAIN_CONTROLLER);
180:            }
181:
182:            /**
183:             * Get the domain name
184:             * @return the domain name
185:             */
186:            private String getDomainName() {
187:                return (String) defaultProperties.get(DOMAIN);
188:            }
189:
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.