Commit 442dc945 authored by Piers Harding's avatar Piers Harding Committed by Aaron Wells
Browse files

Bug 1393536: remove debug and parameterise remote oauth user

behatnotneeded

Change-Id: Ica193fac3c4ee0d000c503f61205b226da344466
parent 8745d56f
......@@ -1869,7 +1869,9 @@ function handle_event($event, $data) {
safe_require($name, $sub->plugin);
$classname = 'Plugin' . ucfirst($name) . ucfirst($sub->plugin);
try {
call_static_method($classname, $sub->callfunction, $event, $data);
if (method_exists($classname, $sub->callfunction)) {
call_static_method($classname, $sub->callfunction, $event, $data);
}
}
catch (Exception $e) {
log_warn("Event $event caused an exception from plugin $classname "
......@@ -2060,7 +2062,7 @@ abstract class Plugin implements IPlugin {
// are web service connections enabled?
if (!get_config('webservice_connections_enabled')) {
error_log('disabled');
log_debug('get_webservice_connections: disabled');
return array();
}
......@@ -2109,7 +2111,6 @@ abstract class Plugin implements IPlugin {
}
// other static parameters - one per line
// error_log('connection: '.var_export($c, true));
if (!empty($c->parameters)) {
$params = explode("\n", $c->parameters);
foreach ($params as $p) {
......@@ -2147,7 +2148,6 @@ abstract class Plugin implements IPlugin {
case WEBSERVICE_TYPE_XMLRPC:
require_once(get_config('docroot') . "webservice/xmlrpc/lib.php");
error_log('xmlrpc auth: '.var_export($auth, true));
$client = new webservice_xmlrpc_client($c->url, $auth);
if ($c->authtype == WEBSERVICE_AUTH_CERT) {
$client->setCertificate($c->certificate);
......@@ -2166,7 +2166,7 @@ abstract class Plugin implements IPlugin {
break;
default:
error_log("Unknown WEBSERVICE_TYPE: ".$c->type);
log_error("Unknown WEBSERVICE_TYPE: ".$c->type);
break;
}
if ($client) {
......@@ -2175,9 +2175,6 @@ abstract class Plugin implements IPlugin {
}
}
syslog(LOG_INFO, "Mahara triggered get_webservice_connections");
error_log("Mahara triggered get_webservice_connections");
return $connections;
}
......
......@@ -36,4 +36,4 @@ require_once(get_config('docroot') . 'webservice/lib.php');
// reload/upgrade the web services configuration
external_reload_webservices();
error_log('web service plugins reloaded');
\ No newline at end of file
log_info('web service plugins reloaded');
\ No newline at end of file
......@@ -104,24 +104,62 @@ class mahara_user_external extends external_api {
$keys = array_keys(self::autologin_redirect_parameters()->keys);
$params = array_combine($keys, func_get_args());
error_log('in autologin_redirect: '.var_export($params, true));
$user = get_record('usr', 'username', $params['ext_user_username'], 'deleted', 0);
log_debug('in autologin_redirect: '.var_export($params, true));
$user_field = (get_config('autologin_redirect_username_field') ? get_config('autologin_redirect_username_field') : 'username');
log_debug('in autologin_redirect: user field: '.$user_field);
if (in_array($user_field, array('username', 'email'))) {
$user = get_record('usr', $user_field, $params['ext_user_username'], 'deleted', 0);
log_debug('in autologin_redirect: user by field: '.var_export($user, true));
}
else if ($user_field == 'studentid') {
// now find the user by institution studentid
$user_id = get_field('usr_institution', 'usr', 'studentid', $params['ext_user_username'], 'institution', $WEBSERVICE_INSTITUTION);
log_debug('in autologin_redirect: usr_institution id: '.var_export($user_id, true));
if ($user_id) {
$user = get_record('usr', 'id', $user_id, 'deleted', 0);
log_debug('in autologin_redirect: user by usr_institution: '.var_export($user, true));
}
}
else {
// must be a remote user field
$user = null;
$auths = explode(',', $user_field);
foreach ($auths as $auth) {
list($institution, $authtype) = explode(':', $auth);
// only institutions for the web service user token
if ($WEBSERVICE_INSTITUTION == $institution) {
// now find the user by remote
$instance_id = get_field('auth_instance', 'id', 'instancename', $authtype, 'institution', $WEBSERVICE_INSTITUTION);
log_debug('in autologin_redirect: auth_instance id: '.$instance_id);
if ($instance_id) {
$user_id = get_field('auth_remote_user', 'localusr', 'remoteusername', $params['ext_user_username'], 'authinstance', $instance_id);
log_debug('in autologin_redirect: auth_remote_user id: '.$user_id);
if ($user_id) {
$user = get_record('usr', 'id', $user_id, 'deleted', 0);
log_debug('in autologin_redirect: user by auth_remote_user: '.var_export($user, true));
}
}
}
}
}
if (empty($user) || empty($user->id) || $user->id < 1) {
// logout
error_log('cant find user - logout');
log_debug('cant find user - logout');
$USER->logout();
redirect(get_config('wwwroot'));
die();
}
else {
log_debug('reanimating: '.var_export($user->username, true));
$USER->reanimate($user->id, $user->authinstance);
}
error_log('reanimating: '.var_export($user->username, true));
$USER->reanimate($user->id, $user->authinstance);
if (empty($params['resource_link_id'])) {
error_log('no resource_link_id - now jumping to: '.get_config('wwwroot'));
log_debug('no resource_link_id - now jumping to: ' . get_config('wwwroot'));
redirect(get_config('wwwroot'));
}
else {
error_log('now jumping to: '.$params['resource_link_id']);
log_debug('now jumping to: ' . $params['resource_link_id']);
redirect($params['resource_link_id']);
}
......
......@@ -163,9 +163,7 @@ class mahara_view_external extends external_api {
array('users'=>$users));
$result = array();
error_log('in get_views_for_user: '.var_export($params, true));
log_debug('in get_views_for_user: '.var_export($params, true));
// if this is a get all users - then lets get them all
if (empty($params['users'])) {
return $result;
......@@ -185,8 +183,6 @@ class mahara_view_external extends external_api {
}
$auth_instance = get_record('auth_instance', 'id', $user->authinstance);
// error_log('User: '.var_export($user, true));
// error_log('auth instance: '.var_export($auth_instance, true));
$USER->reanimate($user->id, $user->authinstance);
require_once('view.php');
$data = View::view_search((isset($u['query']) ? $u['query'] : null), null, (object) array('owner' => $USER->get('id')), null, null, 0, true, null, null, true);
......@@ -248,7 +244,6 @@ class mahara_view_external extends external_api {
$views['data'][]= $view;
}
error_log('Collections data: '.var_export($data->collections->data, true));
foreach ($data->collections->data as $collection) {
$collection = array('name' => $collection->name,
'description' => $collection->description,
......@@ -265,11 +260,10 @@ error_log('Collections data: '.var_export($data->collections->data, true));
$userarray['views'] = $views;
error_log('Views: '.var_export($data, true));
$result[] = $userarray;
}
error_log('Results: '.var_export($result, true));
log_debug('get_views_for_user Results: '.var_export($result, true));
return $result;
}
......@@ -463,7 +457,7 @@ error_log('Collections data: '.var_export($data->collections->data, true));
$collection = new Collection($viewid);
$title = $collection->get('name');
$description = $collection->get('description');
error_log("is a collection");
log_debug("is a collection");
// Can't submit an empty collection, because it won't be viewable.
if (!$collection->views()) {
......@@ -471,10 +465,10 @@ error_log('Collections data: '.var_export($data->collections->data, true));
}
if ($lock) {
error_log("we are locking");
log_debug("we are locking");
// Check whether the collection is already submitted
if ($collection->is_submitted()) {
error_log("collection already submitted");
log_debug("collection already submitted");
// If this is already submitted to something else, throw an exception
if ($collection->get('submittedgroup') || $collection->get('submittedhost') !== $remotewwwroot) {
throw new CollectionSubmissionException(get_string('collectionalreadysubmitted', 'view'));
......@@ -486,7 +480,7 @@ error_log('Collections data: '.var_export($data->collections->data, true));
$access = $collection->get_invisible_token();
}
else {
error_log("do the submit");
log_debug("do the submit");
$collection->submit(null, $remotewwwroot, $userid);
$access = $collection->new_token(false);
}
......@@ -501,15 +495,15 @@ error_log('Collections data: '.var_export($data->collections->data, true));
}
}
else {
error_log("its a view");
log_debug("its a view");
$view = new View($viewid);
$title = $view->get('title');
$description = $view->get('description');
if ($lock) {
error_log('we are locking');
log_debug('we are locking');
if ($view->is_submitted()) {
error_log('view already submitted');
log_debug('view already submitted');
// If this is already submitted to something else, throw an exception
if ($view->get('submittedgroup') || $view->get('submittedhost') !== $remotewwwroot) {
throw new ViewSubmissionException(get_string('viewalreadysubmitted', 'view'));
......@@ -521,7 +515,7 @@ error_log('Collections data: '.var_export($data->collections->data, true));
$access = View::get_invisible_token($viewid);
}
else {
error_log('doing the submit');
log_debug('doing the submit');
View::_db_submit(array($viewid), null, $remotewwwroot, $userid);
$access = View::new_token($viewid, false);
}
......@@ -563,7 +557,7 @@ error_log('Collections data: '.var_export($data->collections->data, true));
$result[]= $data;
}
error_log('Results: '.var_export($result, true));
log_debug('submit_view_for_assessment Results: '.var_export($result, true));
return $result;
}
......@@ -631,12 +625,11 @@ error_log('Collections data: '.var_export($data->collections->data, true));
*/
public static function release_submitted_view($views) {
global $WEBSERVICE_INSTITUTION, $WEBSERVICE_OAUTH_USER, $USER;
error_log('in here');
$params = self::validate_parameters(self::release_submitted_view_parameters(),
array('views' => $views));
$result = array();
error_log('in unlock: '.var_export($params, true));
log_debug('in unlock: '.var_export($params, true));
// if this is a get all views - then lets get them all
......@@ -666,12 +659,12 @@ error_log('Collections data: '.var_export($data->collections->data, true));
if (isset($v['iscollection']) && $v['iscollection']) {
require_once('collection.php');
$collection = new Collection($v['viewid']);
error_log('releasing collection');
log_debug('releasing collection');
$collection->release($teacher);
}
else {
$view = new View($v['viewid']);
error_log('releasing view');
log_debug('releasing view');
View::_db_release(array($v['viewid']), $view->get('owner'));
}
......
......@@ -1209,8 +1209,6 @@ class ' . $classname . ' {
}
public function Security ($data) {
//error_log("username: " . $data->UsernameToken->Username);
//error_log("password: " . $data->UsernameToken->Password);
//throw new WebserviceAccessException(get_string("accessnotallowed", "webservice"));
return true;
}
......@@ -1766,16 +1764,14 @@ abstract class webservice_base_server extends webservice_server {
protected function execute() {
// validate params, this also sorts the params properly, we need the correct order in the next part
ksort($this->parameters);
error_log('going to run validate_parameters against: '.var_export($this->parameters, true));
log_debug('going to run validate_parameters against: '.var_export($this->parameters, true));
$params = call_user_func(array($this->function->classname, 'validate_parameters'), $this->function->parameters_desc, $this->parameters);
error_log('after parms');
// execute - yay!
error_log('executing: '.$this->function->classname."/".$this->function->methodname);
log_debug('executing: '.$this->function->classname."/".$this->function->methodname);
$this->returns = call_user_func_array(array($this->function->classname, $this->function->methodname), array_values($params));
error_log('after execute: '.var_export($this->returns, true));
log_debug('after execute: '.var_export($this->returns, true));
}
}
......
......@@ -55,7 +55,6 @@ class OAuthStoreSession extends OAuthStoreAbstract
$session_array['authorize_uri'] = $options['authorize_uri'];
$session_array['access_token_uri'] = $options['access_token_uri'];
$this->session = $session_array;
error_log('setting $SESSION values - oauth');
$SESSION->set('oauth_' . $options['consumer_key'], $this->session);
}
......
......@@ -158,7 +158,6 @@ class webservice_rest_client {
$url = $this->serverurl . '?' . $this->auth . (empty($this->auth) ? '' : '&') . 'alt=json';
$this->serverurl = $url;
$hostname = parse_url($url, PHP_URL_HOST);
// error_log("Parameters: ".var_export($data, true));
$headers = (empty($this->headers) ? "" : implode("\r\n", $this->headers)."\r\n");
$context = array('http' => array ('method' => $method,
'header' => "Content-Type: application/json\r\n".
......@@ -188,7 +187,7 @@ class webservice_rest_client {
$this->serverurl = $this->serverurl. '?'.$this->auth . '&wsfunction='. $functionname;
$result = webservice_download_file_content($this->serverurl, $this->headers, $params,
false, 300, 20, get_config('disablesslchecks'), null, false, true);
error_log("REST client response: ".var_export($result, true));
log_debug("REST client response: ".var_export($result, true));
}
//after the call, for those not using JSON, parseout the results
......
......@@ -88,7 +88,6 @@ class webservice_rest_server extends webservice_base_server {
// try 2 Legged
if (OAuthRequestVerifier::requestIsSigned()) {
try {
error_log('trying 2 Legged');
$oauth_token = $this->oauth_server->verifyExtended(false);
$this->authmethod = WEBSERVICE_AUTHMETHOD_OAUTH_TOKEN;
$store = OAuthStore::instance();
......@@ -99,7 +98,6 @@ class webservice_rest_server extends webservice_base_server {
}
catch (OAuthException2 $e) {
// let all others fail
error_log('failed: '.var_export($e, true));
$oauth_token = false;
}
}
......@@ -107,7 +105,6 @@ class webservice_rest_server extends webservice_base_server {
// try 3 Legged
if (!$oauth_token) {
try {
error_log('trying 3 Legged');
$oauth_token = $this->oauth_server->verifyExtended();
$this->authmethod = WEBSERVICE_AUTHMETHOD_OAUTH_TOKEN;
$token = $this->oauth_server->getParam('oauth_token');
......@@ -153,7 +150,6 @@ class webservice_rest_server extends webservice_base_server {
// merge parameters from JSON request body if there is one
if ($this->format == 'json') {
// get request body
error_log('this is JSON');
$values = (array)json_decode(@file_get_contents('php://input'), true);
if (!empty($values)) {
$this->parameters = array_merge($this->parameters, $values);
......
......@@ -121,14 +121,12 @@ class webservice_xmlrpc_client extends Zend_XmlRpc_Client {
}
$xml = $this->_lastRequest->__toString();
// error_log('preparing: '.$xml);
if ($this->publickey) {
require_once(get_config('docroot') . 'api/xmlrpc/lib.php');
$openssl = OpenSslRepo::singleton();
$xml = xmldsig_envelope($xml);
$xml = xmlenc_envelope($xml, $this->publickey);
}
// error_log('Sending message ');
$http->setRawData($xml);
$httpResponse = $http->request(Zend_Http_Client::POST);
......@@ -148,7 +146,6 @@ class webservice_xmlrpc_client extends Zend_XmlRpc_Client {
}
$this->_lastResponse = $response;
$payload = $httpResponse->getBody();
// error_log('what did I get back: '.$payload);
try {
$xml = new SimpleXMLElement($payload);
......@@ -160,16 +157,11 @@ class webservice_xmlrpc_client extends Zend_XmlRpc_Client {
// Cascading switch. Kinda.
try {
if ($xml->getName() == 'encryptedMessage') {
// error_log('doing decrypt');
// $this->payload_encrypted = true;
$payload = xmlenc_envelope_strip($xml);
// error_log('de decrypt: '.$payload);
$xml = new SimpleXMLElement($payload);
}
if ($xml->getName() == 'signedMessage') {
// error_log('doing signature');
// $this->payload_signed = true;
$payload = $this->xmldsig_envelope_strip($xml, $this->publickey);
}
}
......@@ -185,14 +177,11 @@ class webservice_xmlrpc_client extends Zend_XmlRpc_Client {
// Sign and encrypt our response, even though we don't know if the
// request was signed and encrypted
$response = xmldsig_envelope($response);
// error_log("checked signature");
$response = xmlenc_envelope($response, $this->publickey);
$xml = $response;
// error_log('was encrypted');
}
}
// error_log('final response: '.$payload);
$this->_lastResponse->loadXml($payload);
}
......
......@@ -497,7 +497,6 @@ class webservice_xmlrpc_server extends webservice_zend_server {
// only both if we can find a public key
$HTTP_RAW_POST_DATA = file_get_contents('php://input');
// error_log('whats in the public key: '.$this->publickey);
if (!empty($this->publickey)) {
// A singleton provides our site's SSL info
require_once(get_config('docroot') . 'api/xmlrpc/lib.php');
......@@ -511,7 +510,6 @@ class webservice_xmlrpc_server extends webservice_zend_server {
} catch (Exception $e) {
throw new XmlrpcServerException('Payload is not a valid XML document', 6001);
}
// error_log('HTTP_RAW_POST_DATA: '.$payload);
// Cascading switch. Kinda.
try {
......@@ -550,7 +548,6 @@ class webservice_xmlrpc_server extends webservice_zend_server {
}
// if XML has been grabbed already then it must be turned into a request object
// error_log('whats the answer: '.$payload);
if ($payload) {
$request = new Zend_XmlRpc_Request();
$result = $request->loadXML($payload);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment