Guest User

Untitled

a guest
Jul 5th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. $ldap = Ldap::create('ext_ldap', array(
  2. 'host' => 'my-server',
  3. 'encryption' => 'none',
  4. ));
  5. ...
  6.  
  7. #service.yaml
  8.  
  9. parameters:
  10. ldap.host: XX.XX.XX.XX
  11.  
  12. services:
  13. #...
  14.  
  15. AppServiceLdapConnection:
  16. arguments: ['%ldap.host%', '%ldap.domain%']
  17.  
  18. SymfonyComponentLdapLdap:
  19. arguments: ['@SymfonyComponentLdapAdapterExtLdapAdapter']
  20. SymfonyComponentLdapAdapterExtLdapAdapter:
  21. arguments:
  22. - host: '%ldap.host%'
  23. port: 389
  24. encryption: none
  25. options:
  26. protocol_version: 3
  27. referrals: false
  28.  
  29. security:
  30. providers:
  31. #in_memory: { memory: ~ }
  32. my_ldap:
  33. ldap:
  34. service: SymfonyComponentLdapLdap
  35. base_dn: dc=assoc,dc=org
  36. search_dn: cn=read-only-,dc=assoc,dc=org
  37. search_password: POeJKz1532
  38. default_roles: ROLE_USER
  39. uid_key: userPrincipalName
  40. filter: ({uid_key}={username})
  41. firewalls:
  42. dev:
  43. pattern: ^/(_(profiler|wdt)|css|images|js)/
  44. security: false
  45. main:
  46. anonymous: ~
  47. form_login_ldap:
  48. provider: my_ldap
  49. login_path: login
  50. check_path: login_check
  51. service: SymfonyComponentLdapLdap
  52. dn_string: '{username}@assoc.org'
  53. query_string: '(&(sAMAccountName={username})(DC=assoc,DC=org))'
  54.  
  55. access_control:
  56. - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  57. - { path: ^/, roles: IS_AUTHENTICATED_FULLY }
  58.  
  59. <form action="{{ path('login') }}" method="post">
  60.  
  61. {% if error %}
  62. <div class="alert alert-danger" role="alert">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
  63. {% endif %}
  64.  
  65. <input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
  66.  
  67. <label for="username">Username</label>
  68. <input type="email" id="username" name="_username" value="{{ last_username }}" required autofocus>
  69.  
  70. <label for="password">Password</label>
  71. <input type="password" id="password" name="_password" required>
  72.  
  73. <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
  74.  
  75. </form>
  76.  
  77. # SecurityController
  78.  
  79. /**
  80. * @Route("/login", name="login")
  81. */
  82. public function login(Request $request, AuthenticationUtils $authenticationUtils)
  83. {
  84. // get the login error if there is one
  85. $error = $authenticationUtils->getLastAuthenticationError();
  86.  
  87. // last username entered by the user
  88. $lastUsername = $authenticationUtils->getLastUsername();
  89.  
  90. return $this->render('security/login.html.twig', array(
  91. 'last_username' => $lastUsername,
  92. 'error' => $error,
  93. ));
  94. }
Add Comment
Please, Sign In to add comment