2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
5 * Storage driver for use against a SAP system using the SAPRFC PHP extension.
7 * Requires the SAPRFC ext available at http://saprfc.sourceforge.net/
11 * LICENSE: This source file is subject to version 3.01 of the PHP license
12 * that is available through the world-wide-web at the following URI:
13 * http://www.php.net/license/3_01.txt. If you did not receive a copy of
14 * the PHP License and are unable to obtain it through the web, please
15 * send a note to license@php.net so we can mail you a copy immediately.
17 * @category Authentication
19 * @author Stoyan Stefanov <ssttoo@gmail.com>
20 * @author Adam Ashley <aashley@php.net>
21 * @copyright 2001-2006 The PHP Group
22 * @license http://www.php.net/license/3_01.txt PHP License 3.01
23 * @version CVS: $Id: SAP.php 289654 2009-10-15 04:52:48Z aashley $
24 * @link http://pear.php.net/package/Auth
25 * @since File available since Release 1.4.0
29 * Include Auth_Container base class
31 require_once 'Auth/Container.php';
33 * Include PEAR for error handling
35 require_once 'PEAR.php';
38 * Performs authentication against a SAP system using the SAPRFC PHP extension.
40 * When the option GETSSO2 is TRUE (default)
41 * the Single Sign-On (SSO) ticket is retrieved
42 * and stored as an Auth attribute called 'sap'
43 * in order to be reused for consecutive connections.
45 * @category Authentication
47 * @author Stoyan Stefanov <ssttoo@gmail.com>
48 * @author Adam Ashley <aashley@php.net>
49 * @copyright 2001-2006 The PHP Group
50 * @license http://www.php.net/license/3_01.txt PHP License 3.01
51 * @version Release: 1.6.2 File: $Revision: 289654 $
52 * @since Class available since Release 1.4.0
54 class Auth_Container_SAP extends Auth_Container {
59 * @var array Default options
68 // {{{ Auth_Container_SAP()
71 * Class constructor. Checks that required options
72 * are present and that the SAPRFC extension is loaded
74 * Options that can be passed and their defaults:
91 * @param array array of options.
94 function Auth_Container_SAP($options)
96 $saprfc_loaded = PEAR::loadExtension('saprfc');
97 if (!$saprfc_loaded) {
98 return PEAR::raiseError('Cannot use SAP authentication, '
99 .'SAPRFC extension not loaded!');
101 if (empty($options['R3NAME']) && empty($options['ASHOST'])) {
102 return PEAR::raiseError('R3NAME or ASHOST required for authentication');
104 $this->options = array_merge($this->options, $options);
111 * Performs username and password check
113 * @param string Username
114 * @param string Password
115 * @return boolean TRUE on success (valid user), FALSE otherwise
117 function fetchData($username, $password)
119 $this->log('Auth_Container_SAP::fetchData() called.', AUTH_LOG_DEBUG);
120 $connection_options = $this->options;
121 $connection_options['USER'] = $username;
122 $connection_options['PASSWD'] = $password;
123 $rfc = saprfc_open($connection_options);
125 $message = "Couldn't connect to the SAP system.";
126 $error = $this->getError();
127 if ($error['message']) {
128 $message .= ': ' . $error['message'];
130 PEAR::raiseError($message, null, null, null, @$error['all']);
133 if (!empty($this->options['GETSSO2'])) {
134 $this->log('Attempting to retrieve SSO2 ticket.', AUTH_LOG_DEBUG);
135 if ($ticket = @saprfc_get_ticket($rfc)) {
136 $this->options['MYSAPSSO2'] = $ticket;
137 unset($this->options['GETSSO2']);
138 $this->_auth_obj->setAuthData('sap', $this->options);
140 PEAR::raiseError("SSO ticket retrieval failed");
153 * Retrieves the last error from the SAP connection
154 * and returns it as an array.
156 * @return array Array of error information
162 $sap_error = saprfc_error();
166 $err = explode("n", $sap_error);
167 foreach ($err AS $line) {
168 $item = split(':', $line);
169 $error[strtolower(trim($item[0]))] = trim($item[1]);
171 $error['all'] = $sap_error;