<?xml version="1.0"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Forum posts to 'Archive'</title>
		<link>http://www.silverstripe.org/archive/rss</link>
		<atom:link href="http://www.silverstripe.org/archive/rss" rel="self" type="application/rss+xml" />
		<description></description>

		
		<item>
			<title>auth_external bug? Auto Adding user to a group</title>
			<link>http://www.silverstripe.org/archive/show/241066#post241066</link>
			<description>&lt;p&gt;SilverStripe V 2.2.2&lt;br /&gt;auth_external V 0.2&lt;/p&gt;&lt;p&gt;We are using SilverStripe as part of our corporate intranet site but needed to authenticate against a proprietary application in which we have working.  The one piece I was not able to get working was the auto add feature and have come to realize an inconsistency in the use of &quot;autoadd&quot; setting.  I apologize if this has been resolved in a previous forum post or bug but I was unable to find this issue being documented.&lt;/p&gt;&lt;p&gt;If you look at the code in from ExternalAuthenticator.php starting at line 400&lt;br /&gt;&lt;div class=&quot;codesnippet&quot;&gt;&lt;p&gt;// But before we write ourselves to the database we must check if&lt;br /&gt;          // the group we are subscribing to exists&lt;br /&gt;          if (DataObject::get_one('Group','Group.Title = \'' . Convert::raw2sql(self::getAutoAdd($RAW_source)).'\'')) {&lt;br /&gt;              if (DataObject::get_one('Member','Email = \'' . $SQL_memberdata['Email'] .'\'')) {&lt;br /&gt;                  self::$authmessage = _t('ExternalAuthenticator.GroupExists','An account with your e-mail address already exists');&lt;br /&gt;                  $authsuccess = false;&lt;br /&gt;              } else {&lt;br /&gt;                  $member = new Member;&lt;/p&gt;&lt;p&gt;                  $member-&amp;gt;update($SQL_memberdata);&lt;br /&gt;                  $member-&amp;gt;ID = null;&lt;br /&gt;                  $member-&amp;gt;write();&lt;br /&gt;                  Group::addToGroupByName($member, Convert::raw2sql(self::getAutoAdd($RAW_source)));&lt;br /&gt;              }&lt;br /&gt;          } else {&lt;br /&gt;              self::$authmessage = _t('ExternalAuthenticator.GroupExists','Unable to find group');&lt;br /&gt;              $authsuccess = false;&lt;br /&gt;          }&lt;br /&gt;      }&lt;/p&gt;&lt;/div&gt;&lt;/p&gt;&lt;p&gt;One line 402 you will see &quot;...DataObject::get_one('Group','Group.Title = \'' . Convert::raw2sql(self::getAutoAdd($RAW_source))...&quot; where it's looking for Group.Title.&lt;/p&gt;&lt;p&gt;Later on it calls Group::addToGroupByName passing in &quot;autoadd&quot; parameter as well.&lt;/p&gt;&lt;p&gt;But if you look in Group.php&lt;/p&gt;&lt;p&gt;&lt;div class=&quot;codesnippet&quot;&gt;&lt;p&gt;/**&lt;br /&gt;         * Add a member to a group.&lt;br /&gt;         *&lt;br /&gt;         * @param DataObject $member&lt;br /&gt;         * @param string $groupcode&lt;br /&gt;         */&lt;br /&gt;        static function addToGroupByName($member, $groupcode) {&lt;br /&gt;                $group = DataObject::get_one('Group', &quot;Code = '&quot; . Convert::raw2sql($groupcode). &quot;'&quot;);&lt;br /&gt;                if($group) {&lt;br /&gt;                        $member-&amp;gt;Groups()-&amp;gt;add($group);&lt;br /&gt;                        $member-&amp;gt;write();&lt;br /&gt;                }&lt;br /&gt;        }&lt;/p&gt;&lt;/div&gt;&lt;/p&gt;&lt;p&gt;Notice the line &quot;$group = DataObject::get_one('Group', &quot;Code = '&quot; . Convert::raw2sql($groupcode). &quot;'&quot;);&quot;&lt;/p&gt;&lt;p&gt;Here the call to get_one is looking for &quot;Code&quot;, not &quot;Title&quot;.&lt;/p&gt;&lt;p&gt;So... my diff for ExternalAuthenticator.php for my solution looks like this...&lt;br /&gt;&lt;div class=&quot;codesnippet&quot;&gt;&lt;p&gt;--- ExternalAuthenticator.php.orig      2008-12-01 11:23:40.000000000 -0600&lt;br /&gt;+++ ExternalAuthenticator.php   2008-12-01 15:42:08.000000000 -0600&lt;br /&gt;@@ -399,7 +399,10 @@&lt;/p&gt;&lt;p&gt;           // But before we write ourselves to the database we must check if&lt;br /&gt;           // the group we are subscribing to exists&lt;br /&gt;-          if (DataObject::get_one('Group','Group.Title = \'' . Convert::raw2sql(self::getAutoAdd($RAW_source)).'\'')) {&lt;br /&gt;+         // 12/01/08 - Changed the following line to pull from Group by Code not Title as originally coded &lt;br /&gt;+         //    this is due to Group::addToGroupByName using Group.Title.  Also insured the &lt;br /&gt;+         //    ExternalAuthenticator::setAutoAdd from _config.php is using the desired Group.Code value&lt;br /&gt;+         if (DataObject::get_one('Group','Group.Code = \'' . Convert::raw2sql(self::getAutoAdd($RAW_source)).'\'')) {&lt;br /&gt;               if (DataObject::get_one('Member','Email = \'' . $SQL_memberdata['Email'] .'\'')) {&lt;br /&gt;                   self::$authmessage = _t('ExternalAuthenticator.GroupExists','An account with your e-mail address already exists');&lt;br /&gt;                   $authsuccess = false;&lt;br /&gt;@@ -409,10 +412,10 @@&lt;br /&gt;                   $member-&amp;gt;update($SQL_memberdata);&lt;br /&gt;                   $member-&amp;gt;ID = null;&lt;br /&gt;                   $member-&amp;gt;write();&lt;br /&gt;-              &lt;br /&gt;                   Group::addToGroupByName($member, Convert::raw2sql(self::getAutoAdd($RAW_source)));&lt;br /&gt;               }&lt;br /&gt;           } else {&lt;br /&gt;+             self::$authmessage = _t('ExternalAuthenticator.GroupExists','Unable to find group');&lt;br /&gt;               $authsuccess = false;&lt;br /&gt;           }&lt;br /&gt;       }&lt;/p&gt;&lt;/div&gt;&lt;/p&gt;&lt;p&gt;Also in _config.php I made sure the ExternalAuthenticator::setAutoAdd was set to the proper Group.Code value.&lt;/p&gt;&lt;p&gt;If there are better solutions or a patch that I could apply other than what I did above please point me the way.&lt;/p&gt;&lt;p&gt;Cheers,&lt;/p&gt;&lt;p&gt;Craig&lt;/p&gt;&lt;br&gt;&lt;br&gt;Posted to: auth_external bug? Auto Adding user to a group &lt;a href=&quot;http://www.silverstripe.org/archive/show/241066#post241066&quot;&gt;Show Thread&lt;/a&gt; | &lt;a href=&quot;http://www.silverstripe.org/archive/show/241066#post241066&quot;&gt;Post Reply&lt;/a&gt;</description>
			<pubDate>Tue, 02 Dec 2008 10:51:32 +1300</pubDate>
			<dc:creator>Craig</dc:creator>
			<guid>http://www.silverstripe.org/archive/show/241066#post241066</guid>
		</item>
		

	</channel>
</rss>