ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
SAP.php
Go to the documentation of this file.
1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3
31require_once 'Auth/Container.php';
35require_once 'PEAR.php';
36
55
56 // {{{ properties
57
61 var $options = array(
62 'CLIENT' => '000',
63 'LANG' => 'EN',
64 'GETSSO2' => true,
65 );
66
67 // }}}
68 // {{{ Auth_Container_SAP()
69
95 {
96 $saprfc_loaded = PEAR::loadExtension('saprfc');
97 if (!$saprfc_loaded) {
98 return PEAR::raiseError('Cannot use SAP authentication, '
99 .'SAPRFC extension not loaded!');
100 }
101 if (empty($options['R3NAME']) && empty($options['ASHOST'])) {
102 return PEAR::raiseError('R3NAME or ASHOST required for authentication');
103 }
104 $this->options = array_merge($this->options, $options);
105 }
106
107 // }}}
108 // {{{ fetchData()
109
117 function fetchData($username, $password)
118 {
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);
124 if (!$rfc) {
125 $message = "Couldn't connect to the SAP system.";
126 $error = $this->getError();
127 if ($error['message']) {
128 $message .= ': ' . $error['message'];
129 }
130 PEAR::raiseError($message, null, null, null, @$erorr['all']);
131 return false;
132 } else {
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);
139 } else {
140 PEAR::raiseError("SSO ticket retrieval failed");
141 }
142 }
143 @saprfc_close($rfc);
144 return true;
145 }
146
147 }
148
149 // }}}
150 // {{{ getError()
151
158 function getError()
159 {
160
161 $error = array();
162 $sap_error = saprfc_error();
163 if (empty($err)) {
164 return $error;
165 }
166 $err = explode("n", $sap_error);
167 foreach ($err AS $line) {
168 $item = split(':', $line);
169 $error[strtolower(trim($item[0]))] = trim($item[1]);
170 }
171 $error['all'] = $sap_error;
172 return $error;
173 }
174
175 // }}}
176
177}
178
179?>
const AUTH_LOG_DEBUG
Auth Log level - DEBUG.
Definition: Auth.php:59
Auth_Container_SAP($options)
Class constructor.
Definition: SAP.php:94
fetchData($username, $password)
Performs username and password check.
Definition: SAP.php:117
getError()
Retrieves the last error from the SAP connection and returns it as an array.
Definition: SAP.php:158
log($message, $level=AUTH_LOG_DEBUG)
Log a message to the Auth log.
Definition: Container.php:246
loadExtension($ext)
OS independant PHP extension load.
Definition: PEAR.php:745
& raiseError($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
This method is a wrapper that returns an instance of the configured error class with this object's de...
Definition: PEAR.php:524