PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/Supportworks Server/html/simplesamlphp/modules/consent/www/getconsent.php

https://bitbucket.org/bittercreek_projects/supportworks
PHP | 154 lines | 108 code | 20 blank | 26 comment | 21 complexity | 6fd3d8baa9b019ad8d838c67205bbf66 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * Consent script
  4. *
  5. * This script displays a page to the user, which requests that the user
  6. * authorizes the release of attributes.
  7. *
  8. * @package SimpleSAMLphp
  9. */
  10. /**
  11. * Explicit instruct consent page to send no-cache header to browsers to make
  12. * sure the users attribute information are not store on client disk.
  13. *
  14. * In an vanilla apache-php installation is the php variables set to:
  15. *
  16. * session.cache_limiter = nocache
  17. *
  18. * so this is just to make sure.
  19. */
  20. session_cache_limiter('nocache');
  21. $globalConfig = SimpleSAML_Configuration::getInstance();
  22. SimpleSAML_Logger::info('Consent - getconsent: Accessing consent interface');
  23. if (!array_key_exists('StateId', $_REQUEST)) {
  24. throw new SimpleSAML_Error_BadRequest(
  25. 'Missing required StateId query parameter.'
  26. );
  27. }
  28. $id = $_REQUEST['StateId'];
  29. $state = SimpleSAML_Auth_State::loadState($id, 'consent:request');
  30. if (array_key_exists('core:SP', $state)) {
  31. $spentityid = $state['core:SP'];
  32. } else if (array_key_exists('saml:sp:State', $state)) {
  33. $spentityid = $state['saml:sp:State']['core:SP'];
  34. } else {
  35. $spentityid = 'UNKNOWN';
  36. }
  37. // The user has pressed the yes-button
  38. if (array_key_exists('yes', $_REQUEST)) {
  39. if (array_key_exists('saveconsent', $_REQUEST)) {
  40. SimpleSAML_Logger::stats('consentResponse remember');
  41. } else {
  42. SimpleSAML_Logger::stats('consentResponse rememberNot');
  43. }
  44. $statsInfo = array(
  45. 'remember' => array_key_exists('saveconsent', $_REQUEST),
  46. );
  47. if (isset($state['Destination']['entityid'])) {
  48. $statsInfo['spEntityID'] = $state['Destination']['entityid'];
  49. }
  50. SimpleSAML_Stats::log('consent:accept', $statsInfo);
  51. if ( array_key_exists('consent:store', $state)
  52. && array_key_exists('saveconsent', $_REQUEST)
  53. && $_REQUEST['saveconsent'] === '1'
  54. ) {
  55. // Save consent
  56. $store = $state['consent:store'];
  57. $userId = $state['consent:store.userId'];
  58. $targetedId = $state['consent:store.destination'];
  59. $attributeSet = $state['consent:store.attributeSet'];
  60. SimpleSAML_Logger::debug(
  61. 'Consent - saveConsent() : [' . $userId . '|' .
  62. $targetedId . '|' . $attributeSet . ']'
  63. );
  64. try {
  65. $store->saveConsent($userId, $targetedId, $attributeSet);
  66. } catch (Exception $e) {
  67. SimpleSAML_Logger::error('Consent: Error writing to storage: ' . $e->getMessage());
  68. }
  69. }
  70. SimpleSAML_Auth_ProcessingChain::resumeProcessing($state);
  71. }
  72. // Prepare attributes for presentation
  73. $attributes = $state['Attributes'];
  74. $noconsentattributes = $state['consent:noconsentattributes'];
  75. // Remove attributes that do not require consent
  76. foreach ($attributes AS $attrkey => $attrval) {
  77. if (in_array($attrkey, $noconsentattributes)) {
  78. unset($attributes[$attrkey]);
  79. }
  80. }
  81. $para = array(
  82. 'attributes' => &$attributes
  83. );
  84. // Reorder attributes according to attributepresentation hooks
  85. SimpleSAML_Module::callHooks('attributepresentation', $para);
  86. // Make, populate and layout consent form
  87. $t = new SimpleSAML_XHTML_Template($globalConfig, 'consent:consentform.php');
  88. $t->data['srcMetadata'] = $state['Source'];
  89. $t->data['dstMetadata'] = $state['Destination'];
  90. $t->data['yesTarget'] = SimpleSAML_Module::getModuleURL('consent/getconsent.php');
  91. $t->data['yesData'] = array('StateId' => $id);
  92. $t->data['noTarget'] = SimpleSAML_Module::getModuleURL('consent/noconsent.php');
  93. $t->data['noData'] = array('StateId' => $id);
  94. $t->data['attributes'] = $attributes;
  95. $t->data['checked'] = $state['consent:checked'];
  96. // Fetch privacypolicy
  97. if (array_key_exists('privacypolicy', $state['Destination'])) {
  98. $privacypolicy = $state['Destination']['privacypolicy'];
  99. } elseif (array_key_exists('privacypolicy', $state['Source'])) {
  100. $privacypolicy = $state['Source']['privacypolicy'];
  101. } else {
  102. $privacypolicy = false;
  103. }
  104. if ($privacypolicy !== false) {
  105. $privacypolicy = str_replace(
  106. '%SPENTITYID%',
  107. urlencode($spentityid),
  108. $privacypolicy
  109. );
  110. }
  111. $t->data['sppp'] = $privacypolicy;
  112. // Set focus element
  113. switch ($state['consent:focus']) {
  114. case 'yes':
  115. $t->data['autofocus'] = 'yesbutton';
  116. break;
  117. case 'no':
  118. $t->data['autofocus'] = 'nobutton';
  119. break;
  120. case null:
  121. default:
  122. break;
  123. }
  124. if (array_key_exists('consent:store', $state)) {
  125. $t->data['usestorage'] = true;
  126. } else {
  127. $t->data['usestorage'] = false;
  128. }
  129. if (array_key_exists('consent:hiddenAttributes', $state)) {
  130. $t->data['hiddenAttributes'] = $state['consent:hiddenAttributes'];
  131. } else {
  132. $t->data['hiddenAttributes'] = array();
  133. }
  134. $t->show();