Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.14 KB | None | 0 0
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!--
  3.  
  4. Copyright (c) 2005, Southpaw Technology
  5. All Rights Reserved
  6.  
  7. PROPRIETARY INFORMATION. This software is proprietary to
  8. Southpaw Technology, and is not to be reproduced, transmitted,
  9. or disclosed in any way without written permission.
  10.  
  11. -->
  12.  
  13. <config version="2">
  14.  
  15.  
  16. <!-- directory pointing to the temp and log files of Tactic -->
  17. <install>
  18. <hostname>localhost</hostname>
  19. <tmp_dir>/TACTIC/tactic_temp</tmp_dir>
  20. </install>
  21.  
  22.  
  23. <!-- external services -->
  24. <services>
  25. <mailserver></mailserver>
  26. <python>python</python>
  27. <python_path>/TACTIC/custom</python_path>
  28. <render_submit_class></render_submit_class>
  29. <render_dispatcher></render_dispatcher>
  30. <system_class></system_class>
  31. <process_count>16</process_count>
  32. <thread_count>75</thread_count>
  33. <process_time_alive></process_time_alive>
  34. </services>
  35.  
  36.  
  37. <!-- database -->
  38. <database>
  39. <vendor>PostgreSQL</vendor>
  40. <server>localhost</server>
  41. <port>5432</port>
  42. <user>postgres</user>
  43. <password>none</password>
  44. <sobject_database>sthpw</sobject_database>
  45. <pool_max_connections>1</pool_max_connections>
  46. </database>
  47.  
  48.  
  49. <perforce>
  50. <web_dir>perforce</web_dir>
  51. <p4>p4</p4>
  52. <port>1666</port>
  53. </perforce>
  54.  
  55.  
  56.  
  57. <security>
  58. <ldap_server>ldap://172.16.10.10:389</ldap_server>
  59. <ldap_path>{login}@barajoun.local</ldap_path>
  60. <version>2</version>
  61. <ticket_expiry>10 hour</ticket_expiry>
  62. <authenticate_mode>autocreate</authenticate_mode>
  63. <authenticate_class>security.CustomLdapAuthenticate</authenticate_class>
  64. <authenticate_version>2</authenticate_version>
  65. <auto_create_user>false</auto_create_user>
  66. <api_require_password>true</api_require_password>
  67. <api_password></api_password>
  68. </security>
  69.  
  70.  
  71. <look>
  72. <palette>AQUA</palette>
  73. </look>
  74.  
  75.  
  76. <checkin>
  77. <asset_base_dir>/nas/projects</asset_base_dir>
  78. <web_base_dir>/assets</web_base_dir>
  79. <win32_local_base_dir>C:/spt</win32_local_base_dir>
  80. <linux_local_base_dir>/tmp/sthpw</linux_local_base_dir>
  81. <win32_sandbox_dir>C:/spt/sandbox</win32_sandbox_dir>
  82. <linux_sandbox_dir>/nas/sandbox</linux_sandbox_dir>
  83. <win32_client_repo_dir></win32_client_repo_dir>
  84. <linux_client_repo_dir></linux_client_repo_dir>
  85. <win32_client_handoff_dir></win32_client_handoff_dir>
  86. <linux_client_handoff_dir>/nas/sandbox/handoff</linux_client_handoff_dir>
  87. <win32_server_handoff_dir></win32_server_handoff_dir>
  88. <linux_server_handoff_dir>/nas/sandbox/handoff</linux_server_handoff_dir>
  89. <sudo_no_password>false</sudo_no_password>
  90. <version_padding>3</version_padding>
  91. </checkin>
  92.  
  93.  
  94.  
  95. </config>
  96.  
  97.  
  98. ###########################################################
  99. #
  100. # Copyright (c) 2005, Southpaw Technology
  101. # All Rights Reserved
  102. #
  103. # PROPRIETARY INFORMATION. This software is proprietary to
  104. # Southpaw Technology, and is not to be reproduced, transmitted,
  105. # or disclosed in any way without written permission.
  106. #
  107. #
  108. #
  109. __all__ = ['CustomLdapAuthenticate']
  110. import tacticenv
  111. import hashlib
  112. import ldap
  113.  
  114. from pyasm.common import SecurityException, Config, Common
  115. from pyasm.security import Login, Authenticate
  116. from pyasm.search import Search, SearchType
  117.  
  118.  
  119. LDAP_SERVER = 'ldap://172.16.10.10'
  120. LDAP_USER = 'abhishek@barajoun.local'
  121. LDAP_PASSWORD = 'barajoun@2014foobarnul'
  122. BASE_DN = "ou=BarajounUSERS,dc=barajoun,dc=local"
  123.  
  124. def search_ldap_info(l, login):
  125. #if not basedn:
  126. basedn = BASE_DN
  127. # remove domain
  128. tmps = login.split('\\')
  129. if len(tmps) > 1:
  130. login = tmps[1]
  131.  
  132. # choose a filter that can identify the login entry in AD
  133. #filter = "(uid=%s)"%login
  134. #filter = "(cn=Some name*)"
  135. #filter = "(&(objectClass=user)(uid=%s))"%login
  136. filter = "(sAMAccountName=%s)"%login
  137.  
  138. scope = ldap.SCOPE_SUBTREE # ldap.SCOPE_BASE, ldap.SCOPE_ONELEVEL
  139. results = l.search_s(basedn, scope, filter)
  140.  
  141. if len(results) != 1:
  142. print "More than 1 login entry found in LDAP. Exit!"
  143. return {}
  144.  
  145.  
  146. dn, entry = results[0]
  147. dn = str(dn)
  148.  
  149. name = entry.get("name")
  150.  
  151.  
  152. mail = entry.get("mail")
  153. if not mail or mail == ['']:
  154. mail = entry.get("userPrincipalName")
  155. info = {'name': name[0], 'email': mail[0]}
  156. return info
  157.  
  158. class CustomLdapAuthenticate(Authenticate):
  159. '''Authenticate using LDAP logins'''
  160.  
  161.  
  162.  
  163. def get_mode(my):
  164. '''let config decide whether it's autocreate or cache'''
  165. return None
  166.  
  167. def verify(my, login_name, password):
  168. # replace cn=attribute with cn={login} in the config ldap_path
  169. # e.g. cn={login},o=organization,ou=server,dc=domain
  170. path = Config.get_value("security", "ldap_path")
  171. server = Config.get_value("security", "ldap_server")
  172. assert path, server
  173.  
  174. my.login_name = login_name
  175. my.internal = True
  176. path = path.replace("{login}", login_name)
  177. #import ldap
  178.  
  179. try:
  180. l = ldap.initialize(server)
  181. # For AD, it may need these before simple_bind_s()
  182. #l.protocol_version = 3
  183. #l.set_option(ldap.OPT_REFERRALS, 0)
  184. l.simple_bind_s(path, password)
  185. my.ldap_info = search_ldap_info(l, login_name)
  186. l.unbind()
  187. print login_name
  188. return True
  189. except Exception, e:
  190. login = Login.get_by_login(login_name)
  191. # check if it's an external account and verify with standard approach
  192. # comment out external check for now
  193. """
  194. if login and login.get_value('location', no_exception=True) == 'external':
  195. auth_class = "pyasm.security.TacticAuthenticate"
  196. authenticate = Common.create_from_class_path(auth_class)
  197. is_authenticated = authenticate.verify(login_name, password)
  198. if is_authenticated == True:
  199. my.internal = False
  200. return True
  201. """
  202. raise SecurityException("Login/Password combination incorrect. %s" %e.__str__())
  203.  
  204. def add_user_info(my, login, password):
  205. '''update password, first and last name in tactic account'''
  206. if not my.internal:
  207. return
  208.  
  209. encrypted = hashlib.md5(password).hexdigest()
  210. login.set_value("password", encrypted)
  211.  
  212. name = my.ldap_info.get('name')
  213. if name:
  214. name_parts = name.split(',')
  215. if len(name_parts) == 2:
  216. login.set_value("first_name", name_parts[1].strip())
  217. login.set_value("last_name", name_parts[0].strip())
  218. else:
  219. login.set_value("first_name", name)
  220.  
  221. login.set_value("license_type", 'user')
  222. # comment out location attribute for basic implementation
  223. #login.set_value("location", "internal")
  224. email = my.ldap_info.get('email')
  225. if email:
  226. login.set_value("email", email)
  227.  
  228. # Hard code adding this user to a group so he can view projects
  229. # this can't be done in a trigger yet
  230. login_in_group = Search.eval("@SOBJECT(sthpw/login_in_group['login','%s']['login_group','user'])" %my.login_name, single=True)
  231. if not login_in_group:
  232. group = Search.eval("@SOBJECT(sthpw/login_in_group['login_group','user'])", single=True)
  233. if not group:
  234. group = SearchType.create('sthpw/login_group')
  235. group.set_value('code','user')
  236. group.set_value('login_group','user')
  237. group.set_value('access_level','low')
  238. group.commit(triggers=False)
  239. login.add_to_group("user")
  240.  
  241.  
  242. if __name__ == '__main__':
  243. ldap_server = LDAP_SERVER
  244. l = ldap.initialize(ldap_server)
  245. #ldap_path = 'cn=%sou=unit,dc=SOMECOMPANY,dc=tld' %user_name
  246. ldap_path = LDAP_USER
  247. password = LDAP_PASSWORD
  248.  
  249.  
  250. try:
  251. # For AD, it may need these before simple_bind_s()
  252. l.protocol_version = 3
  253. l.set_option(ldap.OPT_REFERRALS, 0)
  254. num = l.simple_bind_s(ldap_path, password)
  255. #dn = l.whoami_s()
  256.  
  257. print "login succeeded"
  258.  
  259. result = search_ldap_info(l, ldap_path)
  260. print "INFO ", result
  261. l.unbind()
  262. except:
  263. print "failed"
  264. raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement