Ejemplo n.º 1
0
 /**
  * Asserts that a connection to the University's LDAP can be made.
  * This test will ask you for your NetID and password to authenticate.
  */
 public function test_university_ldap_connection()
 {
     $uid = $this->ask_for_input("\nYour NetID: ");
     $pass = $this->ask_for_password('Password: ');
     try {
         $uniLDAP = new UniversityLdap($uid, $pass);
         $attributes = $uniLDAP->get_attributes();
         // Assert that the expected netID was returned
         $this->assertEquals($attributes[UniversityLdap::CIFID_FIELD][0], $uid);
         // Ensure the student id is an 8 digit string
         $student_id = $attributes[UniversityLdap::STUDENT_ID_FIELD][0];
         $this->assertEquals(strlen($student_id), 8);
         $this->assertTrue(is_numeric($student_id));
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates a new CifUser for the given credentials.
  * If the user already exists in CIF LDAP, this method does nothing.
  * If they do not exist, their account will be initialed with data from University LDAP.
  * An AFS volume will also be created for the user's file storage if they don't already have one.
  *
  * @param string $netid The user's netID.
  * @param string $password The user's password, necessary for connecting to University LDAP.
  * @param int $lcc The user's LCC.
  * @return CifUser A CifUser object for the newly created user.
  */
 public static function create($netid, $password, $lcc)
 {
     $netid = strtolower(trim($netid));
     $lcc = intval($lcc);
     try {
         $uni_ldap = new UniversityLdap($netid, $password);
     } catch (Exception $e) {
         throw new PasswordException('Unable to connect to University servers. Bad username/password?');
     }
     $attributes = self::parse_attributes($uni_ldap->get_attributes(), 'UniversityLdap');
     // Set the user's LCC here because University LDAP doesn't give it to us
     $attributes['lcc'] = $lcc;
     return CifUser::create_from($attributes, $password);
 }