You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by gr...@apache.org on 2005/05/09 00:04:12 UTC

svn commit: r169177 - in /lenya/trunk: lib/jcifs-mock.jar src/java/org/apache/lenya/ac/cifs/CIFSUser.java src/webapp/lenya/pubs/default/config/ac/passwd/cifs.properties.sample

Author: gregor
Date: Sun May  8 15:04:12 2005
New Revision: 169177

URL: http://svn.apache.org/viewcvs?rev=169177&view=rev
Log:
Added CIFSUser implementation by Doug Chestnut and Peter Shipley. This allows to authenticate users against CIFS using JCIFS. Lenya ships with a mock jar, replace with the real thing if you want to use this. This resolves http://issues.apache.org/bugzilla/show_bug.cgi?id=27289

Added:
    lenya/trunk/lib/jcifs-mock.jar   (with props)
    lenya/trunk/src/java/org/apache/lenya/ac/cifs/CIFSUser.java   (with props)
    lenya/trunk/src/webapp/lenya/pubs/default/config/ac/passwd/cifs.properties.sample

Added: lenya/trunk/lib/jcifs-mock.jar
URL: http://svn.apache.org/viewcvs/lenya/trunk/lib/jcifs-mock.jar?rev=169177&view=auto
==============================================================================
Binary file - no diff available.

Propchange: lenya/trunk/lib/jcifs-mock.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: lenya/trunk/src/java/org/apache/lenya/ac/cifs/CIFSUser.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/ac/cifs/CIFSUser.java?rev=169177&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/ac/cifs/CIFSUser.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/ac/cifs/CIFSUser.java Sun May  8 15:04:12 2005
@@ -0,0 +1,167 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ *  
+ */
+
+package org.apache.lenya.ac.cifs;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.lenya.ac.file.FileUser;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+
+import jcifs.smb.NtlmPasswordAuthentication;
+import jcifs.smb.SmbAuthException;
+import jcifs.smb.SmbException;
+import jcifs.smb.SmbSession;
+
+import jcifs.UniAddress;
+import java.net.UnknownHostException;
+
+/**
+ * CIFS user.
+ * @version $Id$
+ */
+public class CIFSUser extends FileUser {
+
+    private static Properties defaultProperties = null;
+
+    // The name for the cifs.properties domain controller lookup
+    private static final String DOMAIN_CONTROLLER = "domain-controller";
+
+    // The name for the cifs.properties domain name lookup
+    private static final String DOMAIN = "domain";
+
+
+    /**
+    * Creates a new CIFSUser object.
+    */
+    public CIFSUser() {
+
+    }
+
+    /**
+    * Create a CIFSUser
+    */
+    public CIFSUser(File configurationDirectory, String id,
+                    String fullName,String email,String password) {
+        super(configurationDirectory, id, fullName, email, password);
+
+    }
+
+    /**
+     * Initializes this user.
+     * @throws ConfigurationException when something went wrong.
+     */
+    protected void initialize() throws ConfigurationException {
+       try {
+            readProperties(super.getConfigurationDirectory());
+        } catch (final IOException ioe) {
+            throw new ConfigurationException("Reading cifs.properties file in ["+
+                        super.getConfigurationDirectory()+"] failed", ioe);
+        }
+    }
+
+    /**
+     * Create a new CIFSUser from a configuration
+     * @param config the <code>Configuration</code> specifying the user details
+     * @throws ConfigurationException if the user could not be instantiated
+     */
+    public void configure(Configuration config) throws ConfigurationException {
+        super.configure(config);
+        initialize();
+    }
+
+    /**
+     * Authenticate a user. This is done by NTDomain Authentication
+     *  using jcifs
+     * @param password to authenticate with
+     * @return true if the given password matches the password for this user
+     */
+    public boolean authenticate(String password) {
+
+        System.setProperty("jcifs.smb.client.disablePlainTextPasswords",
+                            "false" );
+        try {
+            UniAddress mydomaincontroller = UniAddress.getByName(
+                                                getDomainController());
+            NtlmPasswordAuthentication mycreds = new
+                                NtlmPasswordAuthentication(
+                                        getDomainName(),
+                                        super.getId(),
+                                        password);
+            SmbSession.logon( mydomaincontroller, mycreds );
+            // SUCCESS
+            return true;
+        } catch( final SmbAuthException sae ) {
+            // AUTHENTICATION FAILURE
+			if (getLogger().isInfoEnabled()) {
+	            getLogger().info("Authentication against [" + getDomainController() +"]" +
+                         " failed for " + getDomainName() + "/" +  super.getId());
+            }
+            return false;
+        } catch(final SmbException se ) {
+            // NETWORK PROBLEMS?
+			return false;
+        } catch(final  UnknownHostException unho) {
+            return false;
+        }
+
+    }
+
+    /**
+     * Read the properties
+     * @throws IOException if the properties cannot be found.
+     */
+    private void readProperties(File configurationDirectory) throws IOException {
+        // create and load default properties
+        File propertiesFile = new File(configurationDirectory, "cifs.properties");
+
+        if (defaultProperties == null) {
+            defaultProperties = new Properties();
+
+            FileInputStream in = null;
+            try {
+                in = new FileInputStream(propertiesFile);
+                defaultProperties.load(in);
+            } finally {
+                if (in != null) {
+                    in.close();
+                }
+            }
+
+        }
+    }
+
+    /**
+     * Get the domain controller we want to authenticate against
+     * @return the name of the domain controller
+     */
+     private String getDomainController() {
+         return (String)defaultProperties.get(DOMAIN_CONTROLLER);
+     }
+
+    /**
+     * Get the domain name
+     * @return the domain name
+     */
+     private String getDomainName() {
+         return (String)defaultProperties.get(DOMAIN);
+     }
+
+}
\ No newline at end of file

Propchange: lenya/trunk/src/java/org/apache/lenya/ac/cifs/CIFSUser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lenya/trunk/src/java/org/apache/lenya/ac/cifs/CIFSUser.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: lenya/trunk/src/webapp/lenya/pubs/default/config/ac/passwd/cifs.properties.sample
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/pubs/default/config/ac/passwd/cifs.properties.sample?rev=169177&view=auto
==============================================================================
--- lenya/trunk/src/webapp/lenya/pubs/default/config/ac/passwd/cifs.properties.sample (added)
+++ lenya/trunk/src/webapp/lenya/pubs/default/config/ac/passwd/cifs.properties.sample Sun May  8 15:04:12 2005
@@ -0,0 +1,5 @@
+# the name of the domain controller (or samba sever) to authenticate against
+domain-controller=my-domain-controller
+
+# domain/workgroup name to use
+domain=WORKGROUP
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org