Create user accounts in an LDAP-based IdP server after registration, so that Shibbole...
authorPanagiotis Astithas <pastith@gmail.com>
Wed, 5 May 2010 12:45:25 +0000 (15:45 +0300)
committerPanagiotis Astithas <pastith@gmail.com>
Wed, 5 May 2010 12:45:25 +0000 (15:45 +0300)
.classpath
COPYING
README.txt
docs/3rd-party/NOTICE [moved from NOTICE with 100% similarity]
docs/3rd-party/jldap/COPYRIGHT [new file with mode: 0644]
docs/3rd-party/jldap/LICENSE [new file with mode: 0644]
ear/lib/ldap.jar [new file with mode: 0644]
jboss/conf/gss.properties
src/gr/ebs/gss/server/Registration.java
src/gr/ebs/gss/server/ejb/ExternalAPI.java
src/gr/ebs/gss/server/ejb/ExternalAPIBean.java

index be651dc..5602f3e 100644 (file)
@@ -26,5 +26,6 @@
        <classpathentry kind="lib" path="lib/gwt-gears.jar"/>
        <classpathentry kind="lib" path="ear/lib/commons-httpclient-3.1.jar"/>
        <classpathentry kind="lib" path="lib/gwt-dnd-3.0.1.jar"/>
+       <classpathentry kind="lib" path="ear/lib/ldap.jar"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
diff --git a/COPYING b/COPYING
index c6a8c79..c7e16c9 100644 (file)
--- a/COPYING
+++ b/COPYING
@@ -757,3 +757,8 @@ from other locations.
   License: Creative Commons Attribution 3.0 License
     http://creativecommons.org/licenses/by/3.0/
   Source code availability: http://www.dolem.com/lytebox/
+
+* Java LDAP
+  License: The OpenLDAP Public License
+    http://www.openldap.org/software/release/license.html
+  Source code availability: http://www.openldap.org/jldap/
\ No newline at end of file
index 08d1017..ff5378d 100644 (file)
@@ -17,6 +17,7 @@ This product includes software developed by:
  - The GWT Widget project (http://gwt-widget.sourceforge.net/)
  - The gwt-google-apis project (http://code.google.com/p/gwt-google-apis/)
  - The Lytebox project (http://www.dolem.com/lytebox/)
+ - The OpenLDAP project (http://www.openldap.org/jldap/)
  
 This product includes icons developed by:
  - Everaldo Coelho and the Crystal Project (http://www.everaldo.com/crystal/)
similarity index 100%
rename from NOTICE
rename to docs/3rd-party/NOTICE
diff --git a/docs/3rd-party/jldap/COPYRIGHT b/docs/3rd-party/jldap/COPYRIGHT
new file mode 100644 (file)
index 0000000..9782311
--- /dev/null
@@ -0,0 +1,38 @@
+Copyright 1998-2005 The OpenLDAP Foundation
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted only as authorized by the OpenLDAP
+Public License.
+
+A copy of this license is available in the file LICENSE in the
+top-level directory of the distribution or, alternatively, at
+<http://www.OpenLDAP.org/license.html>.
+
+OpenLDAP is a registered trademark of the OpenLDAP Foundation.
+
+Individual files and/or contributed packages may be copyright by
+other parties and subject to additional restrictions.
+
+This work is derived from the University of Michigan LDAP v3.3
+distribution.  Information concerning this software is available
+at <http://www.umich.edu/~dirsvcs/ldap/>.
+
+This work also contains materials derived from public sources.
+
+Additional information about OpenLDAP can be obtained at
+<http://www.openldap.org/>.
+
+---
+Portions Copyright (C) 1999 - 2003 Novell, Inc. All Rights Reserved.
+
+THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
+TREATIES. USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT
+TO VERSION 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS
+AVAILABLE AT HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE
+"LICENSE-2.0.1" IN THE TOP-LEVEL DIRECTORY OF THE DISTRIBUTION.
+ANY USE OR EXPLOITATION OF THIS WORK OTHER THAN AS AUTHORIZED IN
+VERSION 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, OR OTHER PRIOR WRITTEN
+CONSENT FROM NOVELL, COULD SUBJECT THE PERPETRATOR TO CRIMINAL AND
+CIVIL LIABILITY.
+
diff --git a/docs/3rd-party/jldap/LICENSE b/docs/3rd-party/jldap/LICENSE
new file mode 100644 (file)
index 0000000..05ad757
--- /dev/null
@@ -0,0 +1,47 @@
+The OpenLDAP Public License
+  Version 2.8, 17 August 2003
+
+Redistribution and use of this software and associated documentation
+("Software"), with or without modification, are permitted provided
+that the following conditions are met:
+
+1. Redistributions in source form must retain copyright statements
+   and notices,
+
+2. Redistributions in binary form must reproduce applicable copyright
+   statements and notices, this list of conditions, and the following
+   disclaimer in the documentation and/or other materials provided
+   with the distribution, and
+
+3. Redistributions must contain a verbatim copy of this document.
+
+The OpenLDAP Foundation may revise this license from time to time.
+Each revision is distinguished by a version number.  You may use
+this Software under terms of this license revision or under the
+terms of any subsequent revision of the license.
+
+THIS SOFTWARE IS PROVIDED BY THE OPENLDAP FOUNDATION AND ITS
+CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT
+SHALL THE OPENLDAP FOUNDATION, ITS CONTRIBUTORS, OR THE AUTHOR(S)
+OR OWNER(S) OF THE SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+The names of the authors and copyright holders must not be used in
+advertising or otherwise to promote the sale, use or other dealing
+in this Software without specific, written prior permission.  Title
+to copyright in this Software shall at all times remain with copyright
+holders.
+
+OpenLDAP is a registered trademark of the OpenLDAP Foundation.
+
+Copyright 1999-2003 The OpenLDAP Foundation, Redwood City,
+California, USA.  All Rights Reserved.  Permission to copy and
+distribute verbatim copies of this document is granted.
diff --git a/ear/lib/ldap.jar b/ear/lib/ldap.jar
new file mode 100644 (file)
index 0000000..643b5e6
Binary files /dev/null and b/ear/lib/ldap.jar differ
index 1e02435..b3d8375 100644 (file)
@@ -29,3 +29,13 @@ testUsername=past@ebs.gr
 onlyRegisterWithCode=false
 # An introductory text for the invitation code page.
 invitesIntro=You may sign up for the service by submitting the invitation code that you received.
+# The LDAP server where user accounts will be created.
+ldapHost=hal2.ebs.gr
+# The DN to use when connecting to the LDAP server.
+bindDn=cn=Manager,dc=ebs,dc=gr
+# The password to use when connecting to the LDAP server.
+bindPassword=secret
+# The base DN where user accounts will be created.
+baseDn=ou=people,dc=ebs,dc=gr
+# The LDAP objectClass to use for new accounts.
+objectClass=inetOrgPerson
index 972c9bd..2e885bb 100644 (file)
@@ -183,6 +183,14 @@ public class Registration extends HttpServlet {
                                response.sendRedirect(errorUrl);
                                return;
                        }
+                       try {
+                               getService().createLdapUser(username, name, email, password);
+                       } catch (Exception exc) {
+                               String error = "An error occurred while communicating with the Shibboleth IdP";
+                               logger.error(error, exc);
+                               response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, error);
+                               return;
+                       }
                        final UserDTO userDto = new TransactionHelper<UserDTO>().tryExecute(new Callable<UserDTO>() {
                                @Override
                                public UserDTO call() throws Exception {
index e754bff..3707971 100644 (file)
@@ -1218,4 +1218,14 @@ public interface ExternalAPI {
         */
        public Invitation findInvite(String code);
 
+       /**
+        * Create a new user in the connected IdP.
+        *
+        * @param username the username of the new user
+        * @param name the name of the new user
+        * @param email the e-mail of the new user
+        * @param password the password of the new user
+        */
+       public void createLdapUser(String username, String name, String email, String password);
+
 }
index 8c43734..f718103 100644 (file)
@@ -107,6 +107,12 @@ import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
+import com.novell.ldap.LDAPAttribute;
+import com.novell.ldap.LDAPAttributeSet;
+import com.novell.ldap.LDAPConnection;
+import com.novell.ldap.LDAPEntry;
+import com.novell.ldap.LDAPException;
+
 /**
  * The concrete implementation of the ExternalAPI interface.
  *
@@ -2634,4 +2640,32 @@ public class ExternalAPIBean implements ExternalAPI, ExternalAPIRemote {
                return dao.findInvite(code);
        }
 
+       @Override
+       public void createLdapUser(String username, String name, String email, String password) {
+               LDAPConnection lc = new LDAPConnection();
+        LDAPAttributeSet attributeSet = new LDAPAttributeSet();
+        attributeSet.add(new LDAPAttribute("objectClass",
+                       getConfiguration().getString("objectClass")));
+        attributeSet.add(new LDAPAttribute("uid", username));
+        attributeSet.add(new LDAPAttribute("cn", new String[]{name}));
+        attributeSet.add(new LDAPAttribute("sn", name)); // XXX
+        attributeSet.add(new LDAPAttribute("mail", email));
+        attributeSet.add(new LDAPAttribute("userPassword", password));
+        String dn = "uid=" + username + "," + getConfiguration().getString("baseDn");
+        LDAPEntry newEntry = new LDAPEntry(dn, attributeSet);
+        try {
+               lc.connect(getConfiguration().getString("ldapHost"), LDAPConnection.DEFAULT_PORT);
+               lc.bind(LDAPConnection.LDAP_V3, getConfiguration().getString("bindDn"),
+                               getConfiguration().getString("bindPassword").getBytes("UTF8"));
+               lc.add(newEntry);
+               logger.info("Successfully added LDAP account: " + dn);
+               lc.disconnect();
+        } catch(LDAPException e) {
+               throw new RuntimeException(e);
+        } catch(UnsupportedEncodingException e) {
+               throw new RuntimeException(e);
+        }
+
+       }
+
 }