From 1b0a6cb6ac8902f4cc39588ae9cf7c5f77c8d0c4 Mon Sep 17 00:00:00 2001
From: Ubbo Veentjer <veentjer@sub.uni-goettingen.de>
Date: Sat, 11 Oct 2014 00:23:24 +0200
Subject: [PATCH] transfer changes from esx1 to git

---
 .../WebAuthN/PutAttributes.php                |  2 +-
 .../WebAuthN/authenticate.php                 |  2 +-
 .../locale/de/lang_main.inc                   | 10 +++---
 .../locale/en/lang_main.inc                   | 10 +++---
 .../tglib/LDAP.class.php                      | 33 ++++++++++++++++---
 .../tglib/RBAC.class.php                      |  2 +-
 6 files changed, 42 insertions(+), 17 deletions(-)

diff --git a/info.textgrid.middleware.tgauth.webauth/WebAuthN/PutAttributes.php b/info.textgrid.middleware.tgauth.webauth/WebAuthN/PutAttributes.php
index ff9ce97..3a49366 100755
--- a/info.textgrid.middleware.tgauth.webauth/WebAuthN/PutAttributes.php
+++ b/info.textgrid.middleware.tgauth.webauth/WebAuthN/PutAttributes.php
@@ -11,7 +11,7 @@ include("../tglib/LDAP.class.php");
 include("../tglib/WebUtils.class.php");
 
 
-$configfile = "../../../config_tgwebauth.xml";
+$configfile = "/etc/textgrid/tgauth/conf/config_tgwebauth.xml";
 
 $util = new WebUtils;
 
diff --git a/info.textgrid.middleware.tgauth.webauth/WebAuthN/authenticate.php b/info.textgrid.middleware.tgauth.webauth/WebAuthN/authenticate.php
index 2cf5653..7caf443 100644
--- a/info.textgrid.middleware.tgauth.webauth/WebAuthN/authenticate.php
+++ b/info.textgrid.middleware.tgauth.webauth/WebAuthN/authenticate.php
@@ -9,7 +9,7 @@
 mb_internal_encoding("UTF-8");
 
 $config = new DOMDocument();
-$config->load('../../../config_tgwebauth.xml');
+$config->load('/etc/textgrid/tgauth/conf/config_tgwebauth.xml');
 $xpath = new DOMXPath($config);
 $xpath->registerNamespace("c", "http://textgrid.info/namespaces/middleware/tgwebauth");
 
diff --git a/info.textgrid.middleware.tgauth.webauth/locale/de/lang_main.inc b/info.textgrid.middleware.tgauth.webauth/locale/de/lang_main.inc
index 64dec16..49b51a4 100644
--- a/info.textgrid.middleware.tgauth.webauth/locale/de/lang_main.inc
+++ b/info.textgrid.middleware.tgauth.webauth/locale/de/lang_main.inc
@@ -1,4 +1,4 @@
-authn_error_status = TextGrid konnte Sie nicht authentifizieren.
+authn_error_status = DARIAH konnte Sie nicht authentifizieren.
 
 further_information = Weitere Angaben
 
@@ -24,7 +24,7 @@ no_tgauth_instance_heading = Keine TgAuth-Instanz angegeben
 
 no_tgauth_instance_detail = Bitte geben Sie eine g&uuml;ltige Zeichenkette in der authZinstance-Variable an.
 
-authn_failure_heading = Authentifizierung am TextGrid-Community-Account-Server fehlgeschlagen
+authn_failure_heading = Authentifizierung am DARIAH-Community-Account-Server fehlgeschlagen
 
 authn_failure_detail_id_missing = Authentifizierung nicht m&ouml;glich, keine Benutzer-ID angegeben. Wenn Sie Ihr Passwort vergessen haben, klicken Sie bitte auf die nachstehende Schaltfl&auml;che.
 
@@ -38,7 +38,7 @@ sid_create_failure_heading = Sitzungserstellung in RBAC fehlgeschlagen
 
 shib_login_failure_heading = Shibboleth-Anmeldung &uuml;ber DFN-AAI fehlgeschlagen
 
-shib_login_failure_detail = Kein Identifizierer angegeben. TextGrid ben&ouml;tigt das Attribut <b>eduPersonPrincipalName</b>, um Sie zu identifizieren, aber Ihre Organisation hat dieses nicht angegeben. Bitte setzen Sie sicht mit dem Rechenzentrum Ihrer Organisation in Verbindung, um dieses Attribut an TextGrid zu &uuml;bermitteln. Siehe dazu <a href=\"http://www.textgrid.de/1-0/registrierung.html\">http://www.textgrid.de/1-0/registrierung.html</a>.
+shib_login_failure_detail = Kein Identifizierer angegeben. TextGrid ben&ouml;tigt das Attribut <b>eduPersonPrincipalName</b>, um Sie zu identifizieren, aber Ihre Organisation hat dieses nicht angegeben. Bitte setzen Sie sicht mit dem Rechenzentrum Ihrer Organisation in Verbindung, um dieses Attribut an TextGrid zu &uuml;bermitteln. Siehe dazu <a href=\"http://textgrid.de/registrierungdownload/registrierung\">http://textgrid.de/registrierungdownload/registrierung</a>.
 
 authn_succeeded_heading = Authentifizierung erfolgreich
 
@@ -70,7 +70,7 @@ login_label_password = Passwort:
 
 login_button_shib = Anmelden &uuml;ber DFN-AAI
 
-login_shib_explanation = Wenn Ihre Institution nicht in der Liste der Organisationen auf der DFN-AAI-Webseite gef&uuml;hrt wird, oder wenn Sie w&auml;hrend des Anmeldevorgangs auf ein Problem sto&szlig;en, k&ouml;nnen Sie gerne &uuml;ber das Webformular einen <a href="http://www.textgrid.de/1-0/registrierung.html"><b>TextGrid-Account beantragen</b></a>.
+login_shib_explanation = Wenn Ihre Institution nicht in der Liste der Organisationen auf der DFN-AAI-Webseite gef&uuml;hrt wird, oder wenn Sie w&auml;hrend des Anmeldevorgangs auf ein Problem sto&szlig;en, k&ouml;nnen Sie gerne &uuml;ber das Webformular einen <a href="http://textgrid.de/registrierungdownload/registrierung"><b>DARIAH-Account beantragen</b></a>.
 
 attr_givenname = Vorname
 
@@ -122,7 +122,7 @@ attr_citizenship_description = Ihre Nationalit&auml;t
 
 attr_interest = Interessengebiet
 
-attr_interest_description = Optionale Spezifizierung Ihrer Forschungsinteressen in Verbindung mit TextGrid
+attr_interest_description = Optionale Spezifizierung Ihrer Forschungsinteressen in Verbindung mit DARIAH
 
 attr_personid = Personen-ID
 
diff --git a/info.textgrid.middleware.tgauth.webauth/locale/en/lang_main.inc b/info.textgrid.middleware.tgauth.webauth/locale/en/lang_main.inc
index 059dd43..08e39a0 100644
--- a/info.textgrid.middleware.tgauth.webauth/locale/en/lang_main.inc
+++ b/info.textgrid.middleware.tgauth.webauth/locale/en/lang_main.inc
@@ -1,4 +1,4 @@
-authn_error_status = TextGrid could not authenticate you.
+authn_error_status = DARIAH could not authenticate you.
 
 further_information = Further Information
 
@@ -24,7 +24,7 @@ no_tgauth_instance_heading = No TgAuth Instance provided
 
 no_tgauth_instance_detail = Please provide a valid string in the authZinstance variable.
 
-authn_failure_heading = Failure authenticating at TextGrid Community Account Server
+authn_failure_heading = Failure authenticating at DARIAH Community Account Server
 
 authn_failure_detail_id_missing = Could not authenticate, no login ID provided. In case you forgot your password, please click the button below.
 
@@ -38,7 +38,7 @@ sid_create_failure_heading = Failure Creating Session in RBAC
 
 shib_login_failure_heading = Shibboleth Login via DFN-AAI failed
 
-shib_login_failure_detail = No identifier provided. TextGrid needs the attribute <b>eduPersonPrincipalName</b> to identify you, but your organisation did not provide it. Please inquire with your organisation's computing centre to release this attribute to TextGrid. See <a href=\"http://www.textgrid.de/1-0/registrierung.html\">http://www.textgrid.de/1-0/registrierung.html</a>.
+shib_login_failure_detail = No identifier provided. TextGrid needs the attribute <b>eduPersonPrincipalName</b> to identify you, but your organisation did not provide it. Please inquire with your organisation's computing centre to release this attribute to TextGrid. See <a href=\"http://textgrid.de/registrierungdownload/registrierung\">http://textgrid.de/registrierungdownload/registrierung</a>.
 
 authn_succeeded_heading = Authentication succeeded
 
@@ -70,7 +70,7 @@ login_label_password = Password:
 
 login_button_shib = log in via DFN-AAI
 
-login_shib_explanation = If your school is not listed among the organizations on the DFN-AAI page, or if you encounter problems during log-in, you are welcome to <a href="http://www.textgrid.de/en/1-0/registrierung.html"><b>request a TextGrid account</b></a> using the form.
+login_shib_explanation = If your school is not listed among the organizations on the DFN-AAI page, or if you encounter problems during log-in, you are welcome to <a href="http://textgrid.de/registrierungdownload/registrierung"><b>request a DARIAH account</b></a> using the form.
 
 attr_givenname = First Name
 
@@ -122,7 +122,7 @@ attr_citizenship_description = Your Country of Citizenship
 
 attr_interest = Field of Interest
 
-attr_interest_description = Optional specification of fields of research interests in conjuction with TextGrid
+attr_interest_description = Optional specification of fields of research interests in conjuction with DARIAH
 
 attr_personid = Person ID
 
diff --git a/info.textgrid.middleware.tgauth.webauth/tglib/LDAP.class.php b/info.textgrid.middleware.tgauth.webauth/tglib/LDAP.class.php
index dc64336..d6d9206 100644
--- a/info.textgrid.middleware.tgauth.webauth/tglib/LDAP.class.php
+++ b/info.textgrid.middleware.tgauth.webauth/tglib/LDAP.class.php
@@ -21,10 +21,20 @@ class LDAP {
   protected $LDAPname;
   public $availableAttributes = array("o", "sn", "givenName", "cn", "mail");
   public $AttributeMap = Array ('surname' => 'sn',
-				'organisation' => 'o',
+// StefanS will 'o' nicht User-Modifizierbar; daher wird 
+// es nur in RBAC und nicht in DARIAH LDAP geschrieben
+//				'organisation' => 'o',
 				'givenname' => 'givenName',
 				'displayname' => 'cn',
-				'mail' => 'mail'); 
+				'mail' => 'mail',
+				'orgunit' => 'ou',
+				'street' => 'street',
+				'plz' => 'postalCode',
+				'city' => 'l',
+				'tel' => 'telephoneNumber',
+				'interest' => 'dariahResearchInterests',
+				'personid' => 'dariahResearcherId'
+				); 
   
   public function __construct( $configfilepath ) {
     $config = new DOMDocument();
@@ -42,6 +52,7 @@ class LDAP {
     $this->setAttributesDN = $xpath->query("/c:conf/c:authn[@type='community']/c:key[@name='setAttributesDN']")->item(0)->nodeValue;
     $this->setAttributesPW = $xpath->query("/c:conf/c:authn[@type='community']/c:key[@name='setAttributesPW']")->item(0)->nodeValue;
 
+    $this->IDattribute = explode ( ";", $this->IDattribute );
   }
 
   public function authenticate ($login, $password) {
@@ -65,7 +76,14 @@ class LDAP {
 
       $this->UserAttributes = ldap_get_attributes ($ldapconn , $entry);
 
-      $TGID = $this->UserAttributes[$this->IDattribute][0];
+      foreach ( $this->IDattribute as $idattr ) {
+      	   if ( isset ( $this->UserAttributes[$idattr] ) ) {
+	      	$TGID = $this->UserAttributes[$idattr][0];
+		break;
+	   }     
+      }
+
+//      $TGID = $this->UserAttributes[$this->IDattribute][0];
 
       return array("success" => TRUE, "TGID" => $TGID, "LDAPname" => $this->LDAPname);
     }
@@ -85,6 +103,7 @@ class LDAP {
     return $rethash;
   }
 
+// Users will be modified via DARIAH SelfService at a later stage
   public function setUserAttributes ($attrHash, $remote_user) {
 
     $arrModify = Array();
@@ -119,7 +138,13 @@ class LDAP {
       return array("success" => FALSE, 
 		   "detail" => "Authentication failed, reason: " . ldap_error ($ldapconn));
     } else {
-      $filter = "(". $this->IDattribute."=".$remote_user.")";
+
+      $filter = "(|";
+      foreach ( $this->IDattribute as $idattr ) {
+      	 $filter .= "(". $idattr."=".$remote_user.")";
+      }
+      $filter .= ")";
+
       $result = ldap_search( $ldapconn, $this->basedn, $filter);
       if ($result === FALSE ) {
 	return array("success" => FALSE, 
diff --git a/info.textgrid.middleware.tgauth.webauth/tglib/RBAC.class.php b/info.textgrid.middleware.tgauth.webauth/tglib/RBAC.class.php
index cf01567..a551fec 100644
--- a/info.textgrid.middleware.tgauth.webauth/tglib/RBAC.class.php
+++ b/info.textgrid.middleware.tgauth.webauth/tglib/RBAC.class.php
@@ -235,7 +235,7 @@ class RBAC {
     } catch (Soapfault $f) {
       return array("success" => FALSE,
 		   "rbachash" => $rbachash,
-		   "detail" => "SOAP FAULT (authorizedRoles)!: " . $f->faultcode . " / " . $f->faultstring . " / " . $f->detail );
+		   "detail" => "SOAP FAULT (authorizedRoles)!: " . $f->faultcode . " / " . $f->faultstring . " / " . $f->getTraceAsString());
       exit;
     }
     if (!isset($roleResponse->role)) {
-- 
GitLab