fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [11011] bookingfrontend: altinn II


From: Sigurd Nes
Subject: [Fmsystem-commits] [11011] bookingfrontend: altinn II
Date: Thu, 21 Mar 2013 14:53:28 +0000

Revision: 11011
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11011
Author:   sigurdne
Date:     2013-03-21 14:53:27 +0000 (Thu, 21 Mar 2013)
Log Message:
-----------
bookingfrontend: altinn II

Modified Paths:
--------------
    trunk/bookingfrontend/inc/class.bouser.inc.php
    trunk/bookingfrontend/templates/base/config.tpl

Modified: trunk/bookingfrontend/inc/class.bouser.inc.php
===================================================================
--- trunk/bookingfrontend/inc/class.bouser.inc.php      2013-03-20 13:03:02 UTC 
(rev 11010)
+++ trunk/bookingfrontend/inc/class.bouser.inc.php      2013-03-21 14:53:27 UTC 
(rev 11011)
@@ -2,14 +2,15 @@
        class bookingfrontend_bouser
        {
                const ORGNR_SESSION_KEY = 'orgnr';
-               
+
                public
                        $orgnr = null;
 
                protected
                        $default_module = 'bookingfrontend',
-                       $module;
-               
+                       $module,
+                       $config;
+
                /**
                 * Debug for testing
                 * @access public
@@ -20,33 +21,35 @@
                public function __construct() {
                        $this->set_module();
                        $this->orgnr = $this->get_user_orgnr_from_session();
+                       $this->config           = 
CreateObject('phpgwapi.config','bookingfrontend');
+                       $this->config->read();
                }
-               
+
                protected function set_module($module = null)
                {
                        $this->module = is_string($module) ? $module : 
$this->default_module;
                }
-               
+
                public function get_module()
                {
                        return $this->module;
                }
-               
+
                public function log_in()
                {
                        $this->log_off();
-                       $this->orgnr = $this->get_user_orgnr_from_auth_header();
 
-/*
-                       try 
+                       $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')
                        {
-                               
createObject('booking.sfValidatorNorwegianOrganizationNumber')->clean($this->orgnr);
+                               $this->orgnr = $this->log_in_altinn2();
                        }
-                       catch (sfValidatorError $e)
+                       else
                        {
-//                             return null;
+                               $this->orgnr = 
$this->get_user_orgnr_from_auth_header();
                        }
-*/
+
                        if ($this->is_logged_in())
                        {
                                $this->write_user_orgnr_to_session();
@@ -63,18 +66,18 @@
 
                        return $this->is_logged_in();
                }
-               
+
                public function log_off()
                {
                        $this->clear_user_orgnr();
                        $this->clear_user_orgnr_from_session();
                }
-               
+
                protected function clear_user_orgnr()
                {
                        $this->orgnr = null;
                }
-               
+
                public function get_user_orgnr()
                {
                        if(!$this->orgnr)
@@ -83,12 +86,12 @@
                        }
                        return $this->orgnr;
                }
-               
+
                public function is_logged_in()
                {
                        return !!$this->get_user_orgnr();
                }
-               
+
                public function is_organization_admin($organization_id = null)
                {
                        // FIXME!!!!!! REMOVE THIS ONCE ALTINN IS OPERATIONAL
@@ -126,7 +129,7 @@
                        $group = $so->read_single($group_id);
                        return 
$this->is_organization_admin($group['organization_id']);
                }
-               
+
                protected function write_user_orgnr_to_session()
                {
                        if (!$this->is_logged_in())
@@ -136,12 +139,12 @@
 
                        phpgwapi_cache::session_set($this->get_module(), 
self::ORGNR_SESSION_KEY, $this->get_user_orgnr());
                }
-               
+
                protected function clear_user_orgnr_from_session()
                {
                        phpgwapi_cache::session_clear($this->get_module(), 
self::ORGNR_SESSION_KEY);
                }
-               
+
                protected function get_user_orgnr_from_session()
                {
                        try {
@@ -150,18 +153,170 @@
                                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()
                {
-                       $config         = 
CreateObject('phpgwapi.config','bookingfrontend');
-                       $config->read();
+                       $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.*$/';
 
-                       $header_key = isset($config->config_data['header_key']) 
&& $config->config_data['header_key'] ? $config->config_data['header_key'] : 
'Osso-User-Dn';
-                       $header_regular_expression = 
isset($config->config_data['header_regular_expression']) && 
$config->config_data['header_regular_expression'] ? 
$config->config_data['header_regular_expression'] : '/^cn=(.*),cn=users.*$/';
-
                        $headers = getallheaders();
 
-                       if(isset($config->config_data['debug']) && 
$config->config_data['debug'])
+                       if(isset($this->config->config_data['debug']) && 
$this->config->config_data['debug'])
                        {
                                $this->debug = true;
                                echo 'headers:<br>';
@@ -184,29 +339,29 @@
 
                        $options = array();
                        $options['soap_version'] = SOAP_1_1;
-                       $options['location']    = 
isset($config->config_data['soap_location']) && 
$config->config_data['soap_location'] ? $config->config_data['soap_location'] : 
'';// 'http://soat1a.srv.bergenkom.no:8888/gateway/services/BrukerService-v1';
-                       $options['uri']                 = 
isset($config->config_data['soap_uri']) && $config->config_data['soap_uri'] ? 
$config->config_data['soap_uri'] : '';// 'http://soat1a.srv.bergenkom.no';
+                       $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($config->config_data['soap_proxy_host']) && 
$config->config_data['soap_proxy_host'])
+                       if(isset($this->config->config_data['soap_proxy_host']) 
&& $this->config->config_data['soap_proxy_host'])
                        {
-                               $options['proxy_host']  = 
$config->config_data['soap_proxy_host'];
+                               $options['proxy_host']  = 
$this->config->config_data['soap_proxy_host'];
                        }
 
-                       if(isset($config->config_data['soap_proxy_port']) && 
$config->config_data['soap_proxy_port'])
+                       if(isset($this->config->config_data['soap_proxy_port']) 
&& $this->config->config_data['soap_proxy_port'])
                        {
-                               $options['proxy_port']  = 
$config->config_data['soap_proxy_port'];
+                               $options['proxy_port']  = 
$this->config->config_data['soap_proxy_port'];
                        }
-                       $options['encoding']    = 
isset($config->config_data['soap_encoding']) && 
$config->config_data['soap_encoding'] ? $config->config_data['soap_encoding'] : 
'UTF-8';
-                       $options['login']               = 
isset($config->config_data['soap_login']) && $config->config_data['soap_login'] 
? $config->config_data['soap_login'] : '';
-                       $options['password']    = 
isset($config->config_data['soap_password']) && 
$config->config_data['soap_password'] ? $config->config_data['soap_password'] : 
'';
+                       $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($config->config_data['soap_wsdl']) && 
$config->config_data['soap_wsdl'] ? $config->config_data['soap_wsdl'] : '';// 
'http://soat1a.srv.bergenkom.no:8888/gateway/services/BrukerService-v1?wsdl';
+                       $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($config->config_data['authentication_method']) && 
$config->config_data['authentication_method'] ? 
$config->config_data['authentication_method'] : '';
+                       $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;

Modified: trunk/bookingfrontend/templates/base/config.tpl
===================================================================
--- trunk/bookingfrontend/templates/base/config.tpl     2013-03-20 13:03:02 UTC 
(rev 11010)
+++ trunk/bookingfrontend/templates/base/config.tpl     2013-03-21 14:53:27 UTC 
(rev 11011)
@@ -12,6 +12,15 @@
                <tr class="row_off">
                        <td 
colspan="2">&nbsp;<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>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]