Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function createAction(Request $request){
- $em = $this->getDoctrine()->getManager();
- $post_send = $request->request->get('userbundle_user');
- if (array_key_exists('id', $post_send)) {
- $ldap_success = true;
- $entity = $em->getRepository('UserBundle:User')->find($post_send['id']);
- }else{
- $ldapconn = ldap_connect("10.0.0.230")
- or die("Could not connect to LDAP server.");
- $ldap_success = false;
- if ($ldapconn) {
- try{
- $ldapbind = ldap_bind($ldapconn, $post_send['username'], $post_send['password']);
- //Now I have to check if the user exist first on the Active Directory
- //$ldaptree = "OU=SBSUsers,OU=Users,OU=MyBusiness,DC=myDomain,DC=local" I'm not really sure what should I put here;
- //$ldapsearch = ldap_search($ldapconn,$ldaptree, $post_send['username']) or die ("Error in search query: ".ldap_error($ldapconn));+
- if ($ldapbind) {
- $ldap_success = true;
- } else {
- $ldap_success = false;
- }
- }
- catch(Exception $e){
- $ldap_success = false;
- }
- }
- $entity = new User();
- }
- if( $ldap_success && $ldapsearch){ //Here I expect both true, the success conecction and the search, only with both true I will create a user.
- $entity->setUsername($post_send['username']);
- $entity->setRut($post_send['rut']);
- if (array_key_exists('password', $post_send)) {
- if ( $post_send['password'] != "" ) {
- $entity->setPassword($post_send['password']);
- $this->setSecurePassword($entity);
- }
- }
- $entity->setEmail($post_send['email']);
- $entity->setDateAdded(new DateTime());
- $entity->setIsActive(true);
- $entity->setIsAdmin(true);
- $entity->setUserRoles($em->getRepository('UserBundle:Role')->find( $post_send['admin_roles_id'] ));
- $entity->setWizardCompleted(true);
- $em->persist($entity);
- $em->flush();
- $json = new JsonUtils();
- return $json->arrayToJson(array("id"=>$entity->getId()));
- }
- return $json->arrayToJson( array("sueccess"=>false ) );
- }
- $ldapconn = ldap_connect("10.0.0.230");
- ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
- ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0)
- // Use a LDAP service account with only read access...
- $searchUser = 'user@myDomain.com';
- $searchPass = '12345';
- $ldap_success = false;
- if (@ldap_bind($ldapconn, $searchUser, $searchPass)) {
- $attributes = ['cn'];
- $filter = "(&(objectClass=user)(objectCategory=person)(userPrincipalName=".ldap_escape($post_send['username'], null, LDAP_ESCAPE_FILTER)."))";
- $baseDn = "DC=myDomain,DC=com";
- $results = @ldap_search($ldapconn, $baseDn, $filter, $attributes);
- $info = @ldap_get_entries($ldapconn, $results);
- $ldap_success = ($info && $info['count'] === 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement