dao = $dao; $this->grouperConfig = $grouperConfig; } /** * Update user information into the database, creating a new user or adding * new identities to it. * @param \RAP\User $user */ public function saveUser(User $user) { $primarySpecified = true; // If new user if ($user->id === null) { $primarySpecified = false; $user->id = $this->dao->createUser(); } foreach ($user->identities as $identity) { if ($identity->id === null) { $identity->id = $this->dao->insertIdentity($identity, $user->id); if (!$primarySpecified) { $this->dao->setPrimaryIdentity($user->id, $identity->id); $identity->primary = true; } } } } public function findUserByIdentity($type, $identifier) { return $this->dao->findUserByIdentity($type, $identifier); } /** * Build an URL for the web service endpoint that needs to be called in order * to move groups from one user to the other during a join operation. * @return string grouper URL for the PrepareToJoinServlet */ private function getJoinURL() { $joinURL = $this->grouperConfig['wsURL']; if (substr($joinURL, -1) !== '/') { $joinURL .= '/'; } $joinURL .= 'ia2join'; return $joinURL; } public function joinUsers($userId1, $userId2) { // Call Grouper for moving groups and privileges from one user to the other if ($this->grouperConfig !== null) { //create cURL connection $conn = curl_init($this->getJoinURL()); //set options curl_setopt($conn, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($conn, CURLOPT_RETURNTRANSFER, true); curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($conn, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($conn, CURLOPT_USERPWD, $this->grouperConfig['user'] . ":" . $this->grouperConfig['password']); //set data to be posted curl_setopt($conn, CURLOPT_POST, 1); curl_setopt($conn, CURLOPT_POSTFIELDS, "subject1Id=RAP:$userId1&subject2Id=RAP:$userId2"); //perform the request $response = curl_exec($conn); $info = curl_getinfo($conn); if ($info['http_code'] === 200) { curl_close($conn); } else { //show information regarding the error curl_close($conn); http_response_code(500); die('Error: Grouper response code: ' . $info['http_code']); } } // Call DAO for performing join operation into the RAP database. $this->dao->joinUsers($userId1, $userId2); } }