lenya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gre...@apache.org
Subject svn commit: r169175 - in /lenya/branches/BRANCH_1_2_X: lib/jcifs-mock.jar src/java/org/apache/lenya/ac/cifs/CIFSUser.java src/java/org/apache/lenya/ac/ldap/LDAPUser.java src/webapp/lenya/pubs/default/config/ac/passwd/cifs.properties.sample
Date Sun, 08 May 2005 22:02:45 GMT
Author: gregor
Date: Sun May  8 15:02:45 2005
New Revision: 169175

URL: http://svn.apache.org/viewcvs?rev=169175&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/branches/BRANCH_1_2_X/lib/jcifs-mock.jar   (with props)
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/ac/cifs/CIFSUser.java   (with props)
    lenya/branches/BRANCH_1_2_X/src/webapp/lenya/pubs/default/config/ac/passwd/cifs.properties.sample
Modified:
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/ac/ldap/LDAPUser.java

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

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

Added: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/ac/cifs/CIFSUser.java
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/ac/cifs/CIFSUser.java?rev=169175&view=auto
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/ac/cifs/CIFSUser.java (added)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/ac/cifs/CIFSUser.java Sun May  8
15:02:45 2005
@@ -0,0 +1,171 @@
+/*
+ * 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.log4j.Category;
+import org.apache.log4j.Logger;
+
+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;
+    private static Category log =  Logger.getLogger(CIFSUser.class);
+
+    // 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 (log.isInfoEnabled()) {
+                log.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/branches/BRANCH_1_2_X/src/java/org/apache/lenya/ac/cifs/CIFSUser.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/ac/ldap/LDAPUser.java
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/ac/ldap/LDAPUser.java?rev=169175&r1=169174&r2=169175&view=diff
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/ac/ldap/LDAPUser.java (original)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/ac/ldap/LDAPUser.java Sun May  8
15:02:45 2005
@@ -38,6 +38,7 @@
 import org.apache.lenya.ac.AccessControlException;
 import org.apache.lenya.ac.file.FileUser;
 import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
 
 import com.sun.jndi.ldap.LdapCtxFactory;
 
@@ -47,7 +48,7 @@
  */
 public class LDAPUser extends FileUser {
     private static Properties defaultProperties = null;
-    private static Category log = Category.getInstance(LDAPUser.class);
+    private static Category log =  Logger.getLogger(LDAPUser.class);
 
     public static final String LDAP_ID = "ldapid";
     private static String LDAP_PROPERTIES_FILE = "ldap.properties"; 

Added: lenya/branches/BRANCH_1_2_X/src/webapp/lenya/pubs/default/config/ac/passwd/cifs.properties.sample
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/webapp/lenya/pubs/default/config/ac/passwd/cifs.properties.sample?rev=169175&view=auto
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/webapp/lenya/pubs/default/config/ac/passwd/cifs.properties.sample
(added)
+++ lenya/branches/BRANCH_1_2_X/src/webapp/lenya/pubs/default/config/ac/passwd/cifs.properties.sample
Sun May  8 15:02:45 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


Mime
View raw message