[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [11012] bookingfrontend: altinn II
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [11012] bookingfrontend: altinn II |
Date: |
Fri, 22 Mar 2013 08:23:14 +0000 |
Revision: 11012
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11012
Author: sigurdne
Date: 2013-03-22 08:23:13 +0000 (Fri, 22 Mar 2013)
Log Message:
-----------
bookingfrontend: altinn II
Modified Paths:
--------------
trunk/bookingfrontend/inc/class.bouser.inc.php
trunk/bookingfrontend/inc/custom/default/Altinn_Bergen_kommune.php
trunk/bookingfrontend/templates/base/config.tpl
Added Paths:
-----------
trunk/bookingfrontend/inc/custom/default/Altinn2_Bergen_kommune.php
Modified: trunk/bookingfrontend/inc/class.bouser.inc.php
===================================================================
--- trunk/bookingfrontend/inc/class.bouser.inc.php 2013-03-21 14:53:27 UTC
(rev 11011)
+++ trunk/bookingfrontend/inc/class.bouser.inc.php 2013-03-22 08:23:13 UTC
(rev 11012)
@@ -39,17 +39,26 @@
{
$this->log_off();
- $auth_provider =
isset($this->config->config_data['auth_provider']) &&
$this->config->config_data['auth_provider'] ?
$this->config->config_data['auth_provider'] : 'altinn1';
-
- if($auth_provider =='altinn2')
+ $authentication_method =
isset($this->config->config_data['authentication_method']) &&
$this->config->config_data['authentication_method'] ?
$this->config->config_data['authentication_method'] : '';
+
+ if(!$authentication_method)
{
- $this->orgnr = $this->log_in_altinn2();
+ throw new LogicException('authentication_method
not chosen');
}
- else
+
+ $file =
PHPGW_SERVER_ROOT."/bookingfrontend/inc/custom/default/{$authentication_method}";
+
+ if(!is_file($file))
{
- $this->orgnr =
$this->get_user_orgnr_from_auth_header();
+ throw new LogicException("authentication method
\"{$authentication_method}\" not available");
}
+ require_once $file;
+
+ $external_user = new bookingfrontend_external_user();
+
+ $this->orgnr = $external_user->get_user_org_id();
+
if ($this->is_logged_in())
{
$this->write_user_orgnr_to_session();
@@ -153,236 +162,4 @@
return null;
}
}
-
- protected function log_in_altinn2()
- {
- $headers = getallheaders();
- if(isset($this->config->config_data['debug']) &&
$this->config->config_data['debug'])
- {
- $this->debug = true;
- echo 'headers:<br>';
- _debug_array($headers);
- }
-
- $fodsels_nr = substr($headers['Osso-User-Dn'],2, 11);
-// $fodsels_nr = '02035701829'; // test
-
- $request =
- "<soapenv:Envelope
-
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
- xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
-
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
-
xmlns:v1=\"http://bergen.kommune.no/biz/bk/altinn/altinnreporteesservice/v1\">
- <soapenv:Body>
- <v1:getOrganisasjonsAvgivere>
-
<fodselsNr>{$fodsels_nr}</fodselsNr>
- </v1:getOrganisasjonsAvgivere>
- </soapenv:Body>
- </soapenv:Envelope>";
-
- $location_URL =
"http://wsm01e-t.usrv.ubergenkom.no:8888/gateway/services/AltinnReporteesService";
#A-test
-
- $client = new SoapClient(null, array(
- 'location' => $location_URL,
- 'uri' => "",
- 'trace' => 1,
- ));
-
- try
- {
- $response =
$client->__doRequest($request,$location_URL,$location_URL,1);
-
- $reader = new XMLReader();
- $reader->xml($response);
-
- $orgs = array();
- $orgs_validate = array();
- while ($reader->read())
- {
- if ($reader->nodeType ==
XMLREADER::ELEMENT && $reader->localName == 'return')
- {
- $xml = new DOMDocument('1.0',
'utf-8');
- $xml->formatOutput = true;
- $domnode = $reader->expand();
- $xml->appendChild($domnode);
- unset($domnode);
- $_org_id =
$xml->getElementsByTagName('organizationNumber')->item(0)->nodeValue;
- $orgs[] = array
- (
- 'id' => $_org_id,
- 'name' =>
$xml->getElementsByTagName('name')->item(0)->nodeValue,
- );
- $orgs_validate[] = $_org_id;
- }
- }
- }
- catch (SoapFault $exception)
- {
- echo "Dette gikk ikke så bra.";
- var_dump(get_class($exception));
- var_dump($exception);
- }
-
- $stage = phpgw::get_var('stage');
- $org_id = phpgw::get_var('org_id');
-
- if($stage == 2 && $fodsels_nr && in_array($org_id,
$orgs_validate))
- {
- try
- {
- return
createObject('booking.sfValidatorNorwegianOrganizationNumber')->clean($org_id);
- }
- catch (sfValidatorError $e)
- {
- if($this->debug)
- {
- echo $e->getMessage();
- die();
- }
- return null;
- }
-
- }
-
- foreach ( $orgs as $org)
- {
- $selected = '';
- if ( $org_id == $org['id'])
- {
- $selected = 'selected = "selected"';
- }
-
- $org_option .= <<<HTML
- <option
value='{$org['id']}'{$selected}>{$org['name']}</option>
-
-HTML;
- }
-
- if($orgs)
- {
- $action =
$GLOBALS['phpgw']->link('/bookingfrontend/login.php', array('stage' => 2));
- $message = 'Velg organisasjon';
-
- $org_select = <<<HTML
- <p>
- <label
for="org_id">Velg Organisasjon:</label>
- <select
name="org_id" id="org_id">
-
{$org_option}
- </select>
- </p>
-HTML;
-
- }
- else
- {
- $action =
$GLOBALS['phpgw']->link('/bookingfrontend/index.php');
- $message = 'Ikke representant for noen
organisasjon';
- $org_select = '';
- }
-
- $html = <<<HTML
- <!DOCTYPE html>
- <html>
- <head>
- <title>Velg organisasjon</title>
- <meta http-equiv="Content-Type"
content="text/html; charset=utf-8">
- </head>
- <body>
- <h2>{$message}</h2>
- <form action="{$action}" method="post">
- <fieldset>
- <legend>
- Organisasjon
- </legend>
- $org_select
- <p>
- <input
type="submit" name="submit" value="Fortsett" />
- </p>
- </fieldset>
- </form>
- </body>
- </html>
-HTML;
-
- echo $html;
-
- $GLOBALS['phpgw']->common->phpgw_exit();
- }
-
- protected function get_user_orgnr_from_auth_header()
- {
- $header_key =
isset($this->config->config_data['header_key']) &&
$this->config->config_data['header_key'] ?
$this->config->config_data['header_key'] : 'Osso-User-Dn';
- $header_regular_expression =
isset($this->config->config_data['header_regular_expression']) &&
$this->config->config_data['header_regular_expression'] ?
$this->config->config_data['header_regular_expression'] :
'/^cn=(.*),cn=users.*$/';
-
- $headers = getallheaders();
-
- if(isset($this->config->config_data['debug']) &&
$this->config->config_data['debug'])
- {
- $this->debug = true;
- echo 'headers:<br>';
- _debug_array($headers);
- }
-
- if(isset($headers[$header_key]) &&
$headers[$header_key])
- {
- $matches = array();
-
preg_match_all($header_regular_expression,$headers[$header_key], $matches);
- $userid = $matches[1][0];
-
- if($this->debug)
- {
- echo 'matches:<br>';
- _debug_array($matches);
- }
-
- }
-
- $options = array();
- $options['soap_version'] = SOAP_1_1;
- $options['location'] =
isset($this->config->config_data['soap_location']) &&
$this->config->config_data['soap_location'] ?
$this->config->config_data['soap_location'] : '';//
'http://soat1a.srv.bergenkom.no:8888/gateway/services/BrukerService-v1';
- $options['uri'] =
isset($this->config->config_data['soap_uri']) &&
$this->config->config_data['soap_uri'] ? $this->config->config_data['soap_uri']
: '';// 'http://soat1a.srv.bergenkom.no';
- $options['trace'] = 1;
-
- if(isset($this->config->config_data['soap_proxy_host'])
&& $this->config->config_data['soap_proxy_host'])
- {
- $options['proxy_host'] =
$this->config->config_data['soap_proxy_host'];
- }
-
- if(isset($this->config->config_data['soap_proxy_port'])
&& $this->config->config_data['soap_proxy_port'])
- {
- $options['proxy_port'] =
$this->config->config_data['soap_proxy_port'];
- }
- $options['encoding'] =
isset($this->config->config_data['soap_encoding']) &&
$this->config->config_data['soap_encoding'] ?
$this->config->config_data['soap_encoding'] : 'UTF-8';
- $options['login'] =
isset($this->config->config_data['soap_login']) &&
$this->config->config_data['soap_login'] ?
$this->config->config_data['soap_login'] : '';
- $options['password'] =
isset($this->config->config_data['soap_password']) &&
$this->config->config_data['soap_password'] ?
$this->config->config_data['soap_password'] : '';
-
- $wsdl = isset($this->config->config_data['soap_wsdl'])
&& $this->config->config_data['soap_wsdl'] ?
$this->config->config_data['soap_wsdl'] : '';//
'http://soat1a.srv.bergenkom.no:8888/gateway/services/BrukerService-v1?wsdl';
-
- $authentication_method =
isset($this->config->config_data['authentication_method']) &&
$this->config->config_data['authentication_method'] ?
$this->config->config_data['authentication_method'] : '';
-
- require_once
PHPGW_SERVER_ROOT."/bookingfrontend/inc/custom/default/{$authentication_method}";
-
- $external_user = new booking_external_user($wsdl,
$options, $userid, $this->debug);
- // test values
- //$external_user = (object) 'ciao';
$external_user->login = 994239929;
-
- if($this->debug)
- {
- echo 'External user:<br>';
- _debug_array($external_user);
- }
- try
- {
- return
createObject('booking.sfValidatorNorwegianOrganizationNumber')->clean($external_user->login);
- }
- catch (sfValidatorError $e)
- {
- if($this->debug)
- {
- echo $e->getMessage();
- die();
- }
- return null;
- }
- }
}
Added: trunk/bookingfrontend/inc/custom/default/Altinn2_Bergen_kommune.php
===================================================================
--- trunk/bookingfrontend/inc/custom/default/Altinn2_Bergen_kommune.php
(rev 0)
+++ trunk/bookingfrontend/inc/custom/default/Altinn2_Bergen_kommune.php
2013-03-22 08:23:13 UTC (rev 11012)
@@ -0,0 +1,207 @@
+<?php
+ /**
+ * phpGroupWare
+ *
+ * @author Sigurd Nes <address@hidden>
+ * @copyright Copyright (C) 2010 Free Software Foundation, Inc.
http://www.fsf.org/
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @internal Development of this application was funded by
http://www.bergen.kommune.no/
+ * @package phpgroupware
+ * @subpackage communication
+ * @category core
+ * @version $Id: Altinn_Bergen_kommune.php 4887 2010-02-23 10:33:44Z
sigurd $
+ */
+
+ /*
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+ /**
+ * Wrapper for custom methods
+ *
+ * @package phpgroupware
+ * @subpackage bookingfrontend
+ */
+
+ class bookingfrontend_external_user extends bookingfrontend_bouser
+ {
+
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ public function get_user_org_id()
+ {
+
+ $headers = getallheaders();
+ if(isset($this->config->config_data['debug']) &&
$this->config->config_data['debug'])
+ {
+ $this->debug = true;
+ echo 'headers:<br>';
+ _debug_array($headers);
+ }
+
+ $fodsels_nr = substr($headers['Osso-User-Dn'],2, 11);
+ // $fodsels_nr = '02035701829'; // test
+
+ if($this->debug)
+ {
+ echo 'fødselsnr:<br>';
+ _debug_array($fodsels_nr);
+ }
+
+ $request =
+ "<soapenv:Envelope
+
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
+ xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
+
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
+
xmlns:v1=\"http://bergen.kommune.no/biz/bk/altinn/altinnreporteesservice/v1\">
+ <soapenv:Body>
+ <v1:getOrganisasjonsAvgivere>
+
<fodselsNr>{$fodsels_nr}</fodselsNr>
+ </v1:getOrganisasjonsAvgivere>
+ </soapenv:Body>
+ </soapenv:Envelope>";
+
+ $location_URL =
isset($this->config->config_data['soap_location']) &&
$this->config->config_data['soap_location'] ?
$this->config->config_data['soap_location'] :
'';//"http://wsm01e-t.usrv.ubergenkom.no:8888/gateway/services/AltinnReporteesService";
#A-test
+ $location_URL =
"http://wsm01e-t.usrv.ubergenkom.no:8888/gateway/services/AltinnReporteesService";
#A-test
+
+ $client = new SoapClient(null, array(
+ 'location' => $location_URL,
+ 'uri' => "",
+ 'trace' => 1,
+ ));
+
+ try
+ {
+ $response =
$client->__doRequest($request,$location_URL,$location_URL,1);
+
+ $reader = new XMLReader();
+ $reader->xml($response);
+
+ $orgs = array();
+ $orgs_validate = array();
+ while ($reader->read())
+ {
+ if ($reader->nodeType ==
XMLREADER::ELEMENT && $reader->localName == 'return')
+ {
+ $xml = new DOMDocument('1.0',
'utf-8');
+ $xml->formatOutput = true;
+ $domnode = $reader->expand();
+ $xml->appendChild($domnode);
+ unset($domnode);
+ $_org_id =
$xml->getElementsByTagName('organizationNumber')->item(0)->nodeValue;
+ $orgs[] = array
+ (
+ 'id' => $_org_id,
+ 'name' =>
$xml->getElementsByTagName('name')->item(0)->nodeValue,
+ );
+ $orgs_validate[] = $_org_id;
+ }
+ }
+ }
+ catch (SoapFault $exception)
+ {
+ echo "Dette gikk ikke så bra.";
+ var_dump(get_class($exception));
+ var_dump($exception);
+ }
+
+ $stage = phpgw::get_var('stage');
+ $org_id = phpgw::get_var('org_id');
+
+ if($stage == 2 && $fodsels_nr && in_array($org_id,
$orgs_validate))
+ {
+ try
+ {
+ return
createObject('booking.sfValidatorNorwegianOrganizationNumber')->clean($org_id);
+ }
+ catch (sfValidatorError $e)
+ {
+ if($this->debug)
+ {
+ echo $e->getMessage();
+ die();
+ }
+ return null;
+ }
+
+ }
+
+ foreach ( $orgs as $org)
+ {
+ $selected = '';
+ if ( $org_id == $org['id'])
+ {
+ $selected = 'selected = "selected"';
+ }
+
+ $org_option .= <<<HTML
+ <option
value='{$org['id']}'{$selected}>{$org['name']}</option>
+
+HTML;
+ }
+
+ if($orgs)
+ {
+ $action =
$GLOBALS['phpgw']->link('/bookingfrontend/login.php', array('stage' => 2));
+ $message = 'Velg organisasjon';
+
+ $org_select = <<<HTML
+ <p>
+ <label
for="org_id">Velg Organisasjon:</label>
+ <select
name="org_id" id="org_id">
+
{$org_option}
+ </select>
+ </p>
+HTML;
+
+ }
+ else
+ {
+ $action =
$GLOBALS['phpgw']->link('/bookingfrontend/index.php');
+ $message = 'Ikke representant for noen
organisasjon';
+ $org_select = '';
+ }
+
+ $html = <<<HTML
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <title>Velg organisasjon</title>
+ <meta http-equiv="Content-Type"
content="text/html; charset=utf-8">
+ </head>
+ <body>
+ <h2>{$message}</h2>
+ <form action="{$action}" method="post">
+ <fieldset>
+ <legend>
+ Organisasjon
+ </legend>
+ $org_select
+ <p>
+ <input
type="submit" name="submit" value="Fortsett" />
+ </p>
+ </fieldset>
+ </form>
+ </body>
+ </html>
+HTML;
+
+ echo $html;
+
+ $GLOBALS['phpgw']->common->phpgw_exit();
+ }
+ }
Modified: trunk/bookingfrontend/inc/custom/default/Altinn_Bergen_kommune.php
===================================================================
--- trunk/bookingfrontend/inc/custom/default/Altinn_Bergen_kommune.php
2013-03-21 14:53:27 UTC (rev 11011)
+++ trunk/bookingfrontend/inc/custom/default/Altinn_Bergen_kommune.php
2013-03-22 08:23:13 UTC (rev 11012)
@@ -34,32 +34,63 @@
* @subpackage bookingfrontend
*/
- /**
- * START WRAPPER
- */
-
- class booking_external_user
+ class bookingfrontend_external_user extends bookingfrontend_bouser
{
- /**
- * The resulting external user
- * @access public
- * @var string
- */
- public $login = 0;
+ public function __construct()
+ {
+ parent::__construct();
+ }
- /**
- * Debug for testing
- * @access public
- * @var bool
- */
- public $debug = false;
+ public function get_user_org_id()
+ {
- public function __construct($wsdl, $options, $userid, $debug =
false)
- {
- if($debug)
+ $header_key =
isset($this->config->config_data['header_key']) &&
$this->config->config_data['header_key'] ?
$this->config->config_data['header_key'] : 'Osso-User-Dn';
+ $header_regular_expression =
isset($this->config->config_data['header_regular_expression']) &&
$this->config->config_data['header_regular_expression'] ?
$this->config->config_data['header_regular_expression'] :
'/^cn=(.*),cn=users.*$/';
+
+ $headers = getallheaders();
+
+ if(isset($this->config->config_data['debug']) &&
$this->config->config_data['debug'])
{
$this->debug = true;
+ echo 'headers:<br>';
+ _debug_array($headers);
}
+
+ if(isset($headers[$header_key]) &&
$headers[$header_key])
+ {
+ $matches = array();
+
preg_match_all($header_regular_expression,$headers[$header_key], $matches);
+ $userid = $matches[1][0];
+
+ if($this->debug)
+ {
+ echo 'matches:<br>';
+ _debug_array($matches);
+ }
+
+ }
+
+ $options = array();
+ $options['soap_version'] = SOAP_1_1;
+ $options['location'] =
isset($this->config->config_data['soap_location']) &&
$this->config->config_data['soap_location'] ?
$this->config->config_data['soap_location'] : '';//
'http://soat1a.srv.bergenkom.no:8888/gateway/services/BrukerService-v1';
+ $options['uri'] =
isset($this->config->config_data['soap_uri']) &&
$this->config->config_data['soap_uri'] ? $this->config->config_data['soap_uri']
: '';// 'http://soat1a.srv.bergenkom.no';
+ $options['trace'] = 1;
+
+ if(isset($this->config->config_data['soap_proxy_host'])
&& $this->config->config_data['soap_proxy_host'])
+ {
+ $options['proxy_host'] =
$this->config->config_data['soap_proxy_host'];
+ }
+
+ if(isset($this->config->config_data['soap_proxy_port'])
&& $this->config->config_data['soap_proxy_port'])
+ {
+ $options['proxy_port'] =
$this->config->config_data['soap_proxy_port'];
+ }
+ $options['encoding'] =
isset($this->config->config_data['soap_encoding']) &&
$this->config->config_data['soap_encoding'] ?
$this->config->config_data['soap_encoding'] : 'UTF-8';
+ $options['login'] =
isset($this->config->config_data['soap_login']) &&
$this->config->config_data['soap_login'] ?
$this->config->config_data['soap_login'] : '';
+ $options['password'] =
isset($this->config->config_data['soap_password']) &&
$this->config->config_data['soap_password'] ?
$this->config->config_data['soap_password'] : '';
+
+ $wsdl = isset($this->config->config_data['soap_wsdl'])
&& $this->config->config_data['soap_wsdl'] ?
$this->config->config_data['soap_wsdl'] : '';//
'http://soat1a.srv.bergenkom.no:8888/gateway/services/BrukerService-v1?wsdl';
+
try
{
$BrukerService = new BrukerService($wsdl,
$options);
@@ -75,31 +106,37 @@
}
}
- if(isset($BrukerService) && $BrukerService)
- {
- $ctx = new UserContext();
+ $ctx = new UserContext();
- $ctx->appid = 'portico';
- $ctx->onBehalfOfId= $userid;
- $ctx->userid = $userid;
- $ctx->transactionid =
$GLOBALS['phpgw_info']['server']['install_id']; // KAN UTELATES. BENYTTES I.F.M
SUPPORT. LEGG INN EN FOR DEG UNIK ID.
+ $ctx->appid = 'portico';
+ $ctx->onBehalfOfId= $userid;
+ $ctx->userid = $userid;
+ $ctx->transactionid =
$GLOBALS['phpgw_info']['server']['install_id']; // KAN UTELATES. BENYTTES I.F.M
SUPPORT. LEGG INN EN FOR DEG UNIK ID.
- $request = new retrieveBruker();
- $request->userContext = $ctx;
- $request->userid = $userid;
+ $request = new retrieveBruker();
+ $request->userContext = $ctx;
+ $request->userid = $userid;
- $response =
$BrukerService->retrieveBruker($request);
- $Bruker = $response->return;
- $this->login = $Bruker->ou; // organisasjons nr
+ $response = $BrukerService->retrieveBruker($request);
+ $Bruker = $response->return;
+
+ try
+ {
+ return
createObject('booking.sfValidatorNorwegianOrganizationNumber')->clean($Bruker->ou);
}
+ catch (sfValidatorError $e)
+ {
+ if($this->debug)
+ {
+ echo $e->getMessage();
+ die();
+ }
+ return null;
+ }
}
}
/**
- * END WRAPPER - custom code beyond this point
- */
-
- /**
* soap client for altinn supported external login service at Bergen
Kommune
* this code is generated by the
http://code.google.com/p/wsdl2php-interpreter/
*
Modified: trunk/bookingfrontend/templates/base/config.tpl
===================================================================
--- trunk/bookingfrontend/templates/base/config.tpl 2013-03-21 14:53:27 UTC
(rev 11011)
+++ trunk/bookingfrontend/templates/base/config.tpl 2013-03-22 08:23:13 UTC
(rev 11012)
@@ -12,15 +12,6 @@
<tr class="row_off">
<td
colspan="2"> <b>{lang_bookingfrontend_settings}</b></td>
</tr>
- <tr class="row_off">
- <td>{lang_auth_provider}:</td>
- <td>
- <select name="newsettings[auth_provider]">
- <option value="altinn1"
{selected_auth_provider_altinn1}>Altinn I</option>
- <option value="altinn2"
{selected_auth_provider_altinn2}>Altinn II</option>
- </select>
- </td>
- </tr>
<tr class="row_on">
<td>{lang_remote_authentication}:</td>
<td>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [11012] bookingfrontend: altinn II,
Sigurd Nes <=