Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ldap = Ldap::create('ext_ldap', array(
- 'host' => 'my-server',
- 'encryption' => 'none',
- ));
- ...
- #service.yaml
- parameters:
- ldap.host: XX.XX.XX.XX
- services:
- #...
- AppServiceLdapConnection:
- arguments: ['%ldap.host%', '%ldap.domain%']
- SymfonyComponentLdapLdap:
- arguments: ['@SymfonyComponentLdapAdapterExtLdapAdapter']
- SymfonyComponentLdapAdapterExtLdapAdapter:
- arguments:
- - host: '%ldap.host%'
- port: 389
- encryption: none
- options:
- protocol_version: 3
- referrals: false
- security:
- providers:
- #in_memory: { memory: ~ }
- my_ldap:
- ldap:
- service: SymfonyComponentLdapLdap
- base_dn: dc=assoc,dc=org
- search_dn: cn=read-only-,dc=assoc,dc=org
- search_password: POeJKz1532
- default_roles: ROLE_USER
- uid_key: userPrincipalName
- filter: ({uid_key}={username})
- firewalls:
- dev:
- pattern: ^/(_(profiler|wdt)|css|images|js)/
- security: false
- main:
- anonymous: ~
- form_login_ldap:
- provider: my_ldap
- login_path: login
- check_path: login_check
- service: SymfonyComponentLdapLdap
- dn_string: '{username}@assoc.org'
- query_string: '(&(sAMAccountName={username})(DC=assoc,DC=org))'
- access_control:
- - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- - { path: ^/, roles: IS_AUTHENTICATED_FULLY }
- <form action="{{ path('login') }}" method="post">
- {% if error %}
- <div class="alert alert-danger" role="alert">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
- {% endif %}
- <input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
- <label for="username">Username</label>
- <input type="email" id="username" name="_username" value="{{ last_username }}" required autofocus>
- <label for="password">Password</label>
- <input type="password" id="password" name="_password" required>
- <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
- </form>
- # SecurityController
- /**
- * @Route("/login", name="login")
- */
- public function login(Request $request, AuthenticationUtils $authenticationUtils)
- {
- // get the login error if there is one
- $error = $authenticationUtils->getLastAuthenticationError();
- // last username entered by the user
- $lastUsername = $authenticationUtils->getLastUsername();
- return $this->render('security/login.html.twig', array(
- 'last_username' => $lastUsername,
- 'error' => $error,
- ));
- }
Add Comment
Please, Sign In to add comment