Пример #1
0
 /**
  * This method should handle any authentication and report back to the subject
  *
  * @access	public
  * @param   array 	$credentials Array holding the user credentials	
  * @param 	array   $options     Array of extra options
  * @param	object	$response	Authentication response object
  * @return	boolean
  * @since 1.5
  */
 function onAuthenticate($credentials, $options, &$response)
 {
     // This file is needed to use the Repository class
     require_once dirname(__FILE__) . '/alfresco-php-library/Repository.php';
     // Get the URL of the Alfresco repository as a parameter of the plugin
     $plugin =& JPluginHelper::getPlugin('authentication', 'joosco');
     $pluginParams = new JParameter($plugin->params);
     // Set the variables
     $repositoryUrl = $pluginParams->get('alf-url');
     $userName = $credentials['username'];
     $password = $credentials['password'];
     // Connect to the repository
     $repository = new Repository($repositoryUrl);
     $ticket = null;
     try {
         // Try to create a ticket
         $ticket = $repository->authenticate($userName, $password);
         // If the ticket fails, it means that the username and/or password are wrong
         $_SESSION["ticket"] = $ticket;
         $response->status = JAUTHENTICATE_STATUS_SUCCESS;
         // There's no way to get the Alfresco name or email address of the user
         // The only thing to do is wait for an update of the Alfresco PHP API
         $response->username = $credentials['username'];
         $response->email = $credentials['username'] . "@alfresco.user";
         $response->fullname = $credentials['username'];
     } catch (Exception $e) {
         // Wrong username or password creates an exception
         $response->status = JAUTHENTICATE_STATUS_FAILURE;
         $response->error_message = 'Authentication failed';
     }
 }
Пример #2
0
 public function testCreateSession()
 {
     $repository = new Repository();
     $ticket = $repository->authenticate("admin", "admin");
     $session = $repository->createSession($ticket);
     $this->assertNotNull($session);
     $this->assertEquals("http://localhost:8080/alfresco/api", $session->repository->connectionUrl);
     $this->assertEquals($ticket, $session->ticket);
     // TODO for now if no ticket is provided a null session is returned
     $session2 = $repository->createSession();
     $this->assertNull($session2);
 }
Пример #3
0
 protected function getConnection()
 {
     if ($this->alfresco == null) {
         if (!empty($this->alfrescoUrl)) {
             $repository = new Repository($this->alfrescoUrl);
             try {
                 $ticket = $repository->authenticate($this->alfrescoUser, $this->alfrescoPass);
             } catch (Exception $e) {
                 za()->log()->err("Failed authenticating to Alfresco");
                 return;
             }
             $this->alfresco = $repository->createSession($ticket);
             $this->spacesStore = new SpacesStore($this->alfresco);
         }
     }
     return $this->alfresco;
 }
 * 
 * Note: any changes to this file should be uploaded to the wiki
 */
// Include the required Alfresco PHP API objects
if (isset($_SERVER["ALF_AVAILABLE"]) == false) {
    require_once "Alfresco/Service/Repository.php";
    require_once "Alfresco/Service/Session.php";
    require_once "Alfresco/Service/SpacesStore.php";
}
// Specify the connection details
$repositoryUrl = "http://localhost:8080/alfresco/api";
$userName = "******";
$password = "******";
// Authenticate the user and create a session
$repository = new Repository($repositoryUrl);
$ticket = $repository->authenticate($userName, $password);
$session = $repository->createSession($ticket);
// Create a reference to the 'SpacesStore'
$spacesStore = new SpacesStore($session);
// Use a serach to get the content node we are updating
$nodes = $session->query($spacesStore, "PATH:\"app:company_home/app:guest_home/cm:Alfresco-Tutorial.pdf\"");
$contentNode = $nodes[0];
// Update the property if the form has been posted with the correct details
if (isset($_REQUEST["update"]) == true) {
    // Set the updated title and decription values
    $contentNode->cm_title = $_REQUEST["title"];
    $contentNode->cm_description = $_REQUEST["description"];
    // Save the session.  This ensures that the updates are presisted back to the repository.
    // If this save call is not made the changes made will be lost when the session object is destroyed.
    $session->save();
}
Пример #5
0
/**
 * Connect to an external Alfresco DMS repository.
 *
 * In the event of any error the object paramter '$errormsg' will be set
 * to an approriate value.
 *
 * @uses $USER
 * @param string $username The username to authenticate with.
 * @param string $password The password to authenticate with.
 * @return bool True on sucess, False otherwise.
 */
    function connect($username, $password) {
        global $USER;

        if (ELIS_FILES_DEBUG_TRACE) mtrace('connect(' . $username . ', ' . $password . ')');

        $this->errormsg = '';

        if (empty($username) || empty($password)) {
            $this->errormsg = get_string('usernameorpasswordempty', 'repository_elisfiles');
            return false;
        }

    /// Create the session
        $repository = new Repository($this->get_repourl());
        $ticket     = null;

        if (!isset($USER->alfresoSession)) {
            $ticket = $repository->authenticate($username, $password);
            $USER->alfrescoTicket = $ticket;
            $USER->alfrescoLogin  = time();
        }

        return true;
    }
Пример #6
0
    // Get the login details
    $username = null;
    if (isset($_REQUEST["loginForm:user-name"]) == true) {
        $username = $_REQUEST["loginForm:user-name"];
    }
    $password = null;
    if (isset($_REQUEST["loginForm:user-password"]) == true) {
        $password = $_REQUEST["loginForm:user-password"];
    }
    // Set a null failure message
    $failure = null;
    if ($username != null && $password != null) {
        try {
            // Try and create a ticket
            $alfRepository = new Repository();
            $ticket = $alfRepository->authenticate($username, $password);
            if (isset($ticket) == true) {
                // Redirect to the index page with the ticket information
                $url = "/alfresco/php/wiki/index.php?alfTicket=" . $ticket . "&alfUser="******"&title=" . $title;
                }
                header("Location: " . $url);
                exit;
            }
        } catch (Exception $e) {
            // Need to indicate that the login failed
            $failure = "Login to MediaWiki failed, please try again.";
        }
    }
}