forked from mjr5749/wlst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateActiveDirectoryAuthenticator.py
163 lines (126 loc) · 5.47 KB
/
createActiveDirectoryAuthenticator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
print "************************************************************************"
print "*** WebLogic AD Authenticator creation script - "
print "*** Follow the prompts as instructed. Values in parenthesis are the "
print "*** default values that will be used if you simply press Enter."
print "************************************************************************"
def getPropertyValue( propertyName, displayMessage=None, defaultValue=None ):
"""Gets a property from the local namespace, then global namespace, and then prompts user
Keyword arguments:
propertyName -- key to look up in namespaces, else what is displayed to user in prompt. If its a key, it must not contain spaces or spaces must be escaped in property file
displayMessage (optional)-- message to display to user when prompting
defaultValue (optional)-- default value to use if value not found or user doesn't specify
"""
if not propertyName:
print "*** getPropertyValue: PropertyName is a required parameter"
return ""
propertyValue = ""
# put the default in the display message
if not defaultValue:
defaultMsg = "Please enter a value for " + propertyName + ": "
else:
defaultMsg = "Please enter a value for " + propertyName + " (" + defaultValue + "): "
# check locals
if propertyName in locals():
propertyValue = locals()[propertyName]
# check globals
elif propertyName in globals():
propertyValue = globals()[propertyName]
# if still not set, setup prompt message and query user
if not propertyValue:
if displayMessage:
msg = displayMessage
else:
msg = defaultMsg
propertyValue = raw_input(msg)
# use the default if one is specified and no value was found/specified
if (not propertyValue) and defaultValue:
propertyValue = defaultValue
print propertyName + " is set to",propertyValue
return propertyValue
providerName = "ADAuthenticator"
domain = ""
ldapusr = ""
ldappwd = ""
ldapdomain = ""
ldapport = 389;
ldapSSL = False;
ldapbaseDN = ""
wluser = "weblogic"
wlpwd = ""
wladminserver = ""
providerName = getPropertyValue("Security Provider Name", None, providerName)
# Collect Admin Server
wladminserver = getPropertyValue("WebLogic Admin Server", "Please enter WebLogic Admin Server host and post (i.e. server:7101): ", None)
if wladminserver == "":
print "*** ERROR: You must enter a WebLogic Admin Server and port."
exit(-1)
# Collect WebLogic user
wluser = getPropertyValue("WebLogic User", None, "weblogic")
# Collect WebLogic user password
wlpwd = getPropertyValue("WebLogic User Password", None, None)
# Collect WebLogic domain
domain = getPropertyValue("WebLogic Domain", None, None)
if domain == "":
print "*** ERROR: You must enter a domain."
exit(-1)
# Collect LDAP Domain
ldapdomain = getPropertyValue("LDAP Domain", None, ldapdomain)
# Collect LDAP Port
ldapport = int(getPropertyValue( "LDAP Port", "Please enter LDAP port, 389 (default) or 636 (SSL): ", str(ldapport)))
# Collect LDAP SSL Enabled
ldapSSL = getPropertyValue("LDAP over SSL", "Enable LDAP over SSL, true or false (false): ", "false")
if ldapSSL.lower() == "true":
ldapSSL = True
else:
ldapSSL = False
# Collect LDAP Base DN
ldapbaseDN = getPropertyValue("LDAP Base DN", None, ldapbaseDN)
# Collect LDAP User
ldapusr = getPropertyValue("LDAP User (i.e [email protected])", None, None)
# Collect LDAP User password
ldappwd = getPropertyValue("LDAP User Password", None, None)
if ldapusr == "" or ldappwd == "" :
print "*** ERROR: You must enter an LDAP username and password."
exit(-1)
connect(wluser, wlpwd, wladminserver)
edit()
# make the default authenticator sufficient
startEdit()
cd('/SecurityConfiguration/' + domain + '/Realms/myrealm/AuthenticationProviders/DefaultAuthenticator')
cmo.setControlFlag('SUFFICIENT')
activate()
startEdit()
cd('/SecurityConfiguration/' + domain + '/Realms/myrealm')
cmo.createAuthenticationProvider(providerName, 'weblogic.security.providers.authentication.ActiveDirectoryAuthenticator')
cd('/SecurityConfiguration/' + domain + '/Realms/myrealm/AuthenticationProviders/' + providerName)
cmo.setControlFlag('SUFFICIENT')
cmo.setUseRetrievedUserNameAsPrincipal(true)
activate()
startEdit()
cmo.setUserNameAttribute('sAMAccountName')
cmo.setPrincipal(ldapusr)
cmo.setHost(ldapdomain)
cmo.setPort(ldapport)
cmo.setSSLEnabled(ldapSSL)
cmo.setAllUsersFilter('(&(sAMAccountName=*)(objectclass=user))')
cmo.setAllGroupsFilter('(&(sAMAccountName=*)(objectclass=group))')
cmo.setGroupFromNameFilter('(&(sAMAccountName=%g)(objectclass=group))')
cmo.setCredential(ldappwd)
cmo.setGroupBaseDN(ldapbaseDN)
cmo.setUserFromNameFilter('(&(sAMAccountName=%u)(objectclass=user))')
cmo.setStaticGroupNameAttribute('sAMAccountName')
cmo.setUserBaseDN(ldapbaseDN)
# prevents cyclically nested AD groups from causing the JVM to seg fault (kinda bad)
print "*** Limiting nested group membership searching to 25 levels..."
cmo.setGroupMembershipSearching('limited')
cmo.setMaxGroupMembershipSearchLevel(25)
activate()
startEdit()
cd('/SecurityConfiguration/' + domain + '/Realms/myrealm')
set('AuthenticationProviders',jarray.array([ObjectName('Security:Name=myrealm'+providerName), ObjectName('Security:Name=myrealmDefaultAuthenticator'), ObjectName('Security:Name=myrealmDefaultIdentityAsserter')], ObjectName))
save()
activate()
print "************************************************************************"
print "*** Successfully created authentication provider. Please restart your server(s)."
print "************************************************************************"
disconnect()