LDAP Add Users with Coldfusion

This document is outdated. Please refer to Add LDAP Integration With Group Management for instruction on LDAP integration.

Example of how to add users to Confluence with a Coldfusion form

Like many users of Confluence - we are struggling with how to maintain users in our LDAP repository (Active directory) and also in confluence. So far, we come up with a reasonably simple temporary solution while the rocket scientists at Atlassian figure out true LDAP implementation. Thanks to David Ross for help with the API.

What follows is a cold fusion form which (when submitted) will create users in confluence if they don't already exist.

Later this week, I will be adding functionality to add security groups that exist in LDAP to confluence.

Please feel free to make suggestions or comments as you see fit. I'll add some comments later as well.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>Confluence LDAP</title>
</head>

<body>
<cfset nouser = 0>
<cfif not parameterexists(form.submit)>
   <cfform name="loginform" format="XML" skin="basic">
   <cfformgroup type="vertical">
   <cfinput type="Text" name="Username" label="Username">
   <cfinput type="Password" name="Password" label="Password" width="250">
   </cfformgroup>
   <cfinput type="Submit" name="Submit" label="Submit" Value="Submit">
   </cfform>
<cfelse>
    <cfldap action="QUERY"
	        name="getldapuser"
	     	ATTRIBUTES="MemberOf,givenName,sn,physicalDeliveryOfficeName"
	        start="DC=capcare, DC=com"
	        scope="SUBTREE"
	        server="SERVERADDRESS.YOURDOMAIN.org"
	        timeout="60"
		filter="sAMAccountName=#form.username#"
		<!--- the username to look for in lines 16 and 18--->
	        username="ccmg\#form.username#"
	        password="#form.password#"
		rebind="Yes">
		<cfset ValidLogin ="Yes">
     <cfinvoke webservice="http://tomcat/confluence/rpc/soap/confluenceservice-v1.wsdl"
     method="login"
     returnvariable="token">
     <cfinvokeargument name="arg0" value="admin"/>
     <cfinvokeargument name="arg1" value="ADMIN_PASSWORD_GOES_HERE"/>
     </cfinvoke>
 <cftry>
     <cfinvoke   webservice="http://tomcat/confluence/rpc/soap/confluenceservice-v1.wsdl"
     method="getUser"
     returnvariable="userOBJECT">
     <cfinvokeargument name="arg0" value="#token#"/>
     <cfinvokeargument name="arg1" value="#form.username#"/>
     </cfinvoke>
     <cfcatch type="Any">
     <cfset nouser=1>
     </cfcatch>
  </cftry>
<cfif nouser NEQ 0> 
     No user -- gonna make one <br>
     <cfset userclass = userOBJECT1.getClass()/>
     <cfset newuser =  userclass.newInstance()/>
     <cfset newuser.setName("#form.username#")/>
     <cfset newuser.setemail("#form.username#@YOURDOMAIN.com")/>
     <cfset newuser.setfullname("#getldapuser.givenname# #getldapuser.sn#")/>
     <cfset newuser.seturl("http://tomcat/confluence/display/#form.username#")/>
     <cfinvoke   webservice="http://tomcat/confluence/rpc/soap/confluenceservice-v1.wsdl"
          method="addUser"
          returnvariable="userOBJECT2">
          <cfinvokeargument name="arg0" value="#token#"/>
          <cfinvokeargument name="arg1" value="#newuser#"/>
          <cfinvokeargument name="arg2" value="#form.password#"/> 
     </cfinvoke>
     Created user <cfoutput>#form.username#</cfoutput>
<cfelse>
     user <cfoutput>#form.username#</cfoutput> already exists in confluence.
</cfif> 

</cfif>
</body>
</html>

Labels

scripts scripts Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.