Created
April 29, 2020 00:42
-
-
Save bdkosher/9f7025b8c5136ea23dc060d767fc0989 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='org.springframework.security', module='spring-security-core', version='3.2.5.RELEASE') | |
@Grab(group='org.springframework.security', module='spring-security-ldap', version='3.2.5.RELEASE') | |
import groovy.transform.* | |
import javax.naming.NamingException | |
import javax.naming.directory.Attribute | |
import javax.naming.directory.Attributes | |
import org.springframework.ldap.core.* | |
import org.springframework.security.ldap.* | |
def url = 'ldap://someserver:389/DC=FOO,DC=COM' | |
def user = /CN=Wolf\, Joseph,CN=Users,DC=FOO,DC=COM/ | |
def pass = 'xxxxxxxx' | |
def template = new SpringSecurityLdapTemplate({ -> | |
new DefaultSpringSecurityContextSource(url).with { | |
userDn = user | |
password = pass | |
afterPropertiesSet() | |
delegate | |
} | |
}()) | |
String val(Attributes atts, String name) { | |
atts.get(name).get().toString() | |
} | |
@TupleConstructor | |
class User { | |
String id, username, name, email, company, department | |
@Override | |
String toString() { | |
"$id,$username,$email,$company,$department" | |
} | |
} | |
def users = [] | |
new File(/C:\Users\jwolf2\Desktop\svn_committers_btw_2016-10-01_and_2017-10-12.txt/).eachLine { line -> | |
if (line.trim() == '') return | |
if (line.split(' ').length > 1) return | |
try { | |
template.search('CN=Users', "(sAMAccountName=$line)", { atts -> | |
new User(val(atts, 'employeeID'), | |
val(atts, 'sAMAccountName'), | |
val(atts, 'cn'), | |
val(atts, 'mail'), | |
val(atts, 'company'), | |
val(atts, 'department')) | |
} as AttributesMapper).each { users << it } | |
} catch (e) { | |
println "Couldn't search for $line - $e.message" | |
} | |
} | |
def out = new File(/C:\Users\jwolf2\Desktop\svn_committers_btw_2016-10-01_and_2017-10-12_full.csv/) | |
out << "ID,Username,Email,Company,Department\n" | |
users.each { | |
println it | |
out << "$it\n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment