[icinga-checkins] icinga.org: icinga-web/jmosshammer/default: * fixes #723 cookie for login credntials

git at icinga.org git at icinga.org
Fri Aug 5 09:13:16 CEST 2011


Module: icinga-web
Branch: jmosshammer/default
Commit: 2d4765aa53ad2ff608e3f359be1de138e655d061
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=2d4765aa53ad2ff608e3f359be1de138e655d061

Author: Marius Hein <marius.hein at netways.de>
Date:   Wed Aug  3 12:37:03 2011 +0200

* fixes #723 cookie for login credntials

---

 .../AppKit/actions/Login/AjaxLoginAction.class.php |    8 +++---
 app/modules/AppKit/config/auth.xml                 |    6 +++++
 .../AppKit/models/Auth/DispatchModel.class.php     |   24 +++++++++++++++----
 .../AppKit/templates/Login/AjaxLoginSuccess.php    |    7 +++--
 app/modules/AppKit/validate/Login/AjaxLogin.xml    |    6 ++++-
 app/modules/AppKit/validate/Login/SilentAuth.xml   |    2 +-
 .../views/Login/AjaxLoginSuccessView.class.php     |    8 +++++-
 .../views/Login/SilentAuthSuccessView.class.php    |    2 +-
 8 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/app/modules/AppKit/actions/Login/AjaxLoginAction.class.php b/app/modules/AppKit/actions/Login/AjaxLoginAction.class.php
index ea749e8..be43caf 100644
--- a/app/modules/AppKit/actions/Login/AjaxLoginAction.class.php
+++ b/app/modules/AppKit/actions/Login/AjaxLoginAction.class.php
@@ -46,9 +46,9 @@ class AppKit_Login_AjaxLoginAction extends AppKitBaseAction {
         return $this->getDefaultViewName();
     }
 
-    public function handleError(AgaviRequestDataHolder $rd) {
-        return $this->getDefaultViewName();
-    }
+     public function handleError(AgaviRequestDataHolder $rd) {
+         return $this->getDefaultViewName();
+     }
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/app/modules/AppKit/config/auth.xml b/app/modules/AppKit/config/auth.xml
index 1ab20aa..5b9cf28 100755
--- a/app/modules/AppKit/config/auth.xml
+++ b/app/modules/AppKit/config/auth.xml
@@ -24,6 +24,12 @@
 	    * Are both settings enabled, the dialog will be displayed as fallback
 	-->
 	<setting name="behaviour.enable_dialog">true</setting>
+	
+	<!--
+		Enable store of login name into cookie and provide
+		this as default username for the login mask
+	-->
+	<setting name="behaviour.store_loginname">true</setting>
 
 	<!-- Provider default settings -->
 	<setting name="defaults">
diff --git a/app/modules/AppKit/models/Auth/DispatchModel.class.php b/app/modules/AppKit/models/Auth/DispatchModel.class.php
index 020965c..bbfa5c4 100644
--- a/app/modules/AppKit/models/Auth/DispatchModel.class.php
+++ b/app/modules/AppKit/models/Auth/DispatchModel.class.php
@@ -106,15 +106,17 @@ class AppKit_Auth_DispatchModel extends AppKitBaseModel implements AgaviISinglet
     }
 
     public function doAuthenticate($username, $password) {
-
+        
         /**
          * 1. Find the user
          * 2. If not found, try to import
          * 3. If the user is there, try to auth
          */
-
+        
         $this->log('Auth.Dispatch: Starting authenticate (username=%s)', $username, AgaviLogger::DEBUG);
-
+        
+        $success = false;
+        
         $user = $this->findUser($username);
         $import = false;
 
@@ -148,7 +150,7 @@ class AppKit_Auth_DispatchModel extends AppKitBaseModel implements AgaviISinglet
                     // Check password
                     if ($provider->isAuthoritative() && $provider->doAuthenticate($user, $password, $username, $authid)) {
                         $this->log('Auth.Dispatch: Successfull authentication (provder=%s)', $provider->getProviderName(), AgaviLogger::DEBUG);
-                        return $user;
+                        $success = true;
                     }
 
                 }
@@ -156,11 +158,23 @@ class AppKit_Auth_DispatchModel extends AppKitBaseModel implements AgaviISinglet
                 // Let others try authentification
                 if ($provider->resumeAuthentification()) {
                     if ($this->authentificateOthers($user, $provider->getProviderName(), $password) == true) {
-                        return $user;
+                        $success = true;
                     }
                 }
 
             }
+            
+            if ($success === true) {
+                
+                // We can use it later if we want login again (#723)
+                if (AgaviConfig::get('modules.appkit.auth.behaviour.store_loginname', false) === true) {
+                    $response = $this->context->getController()->getGlobalResponse();
+                    $response->setCookie('icinga-web-loginname', $user->user_name);
+                }
+                
+                return $user;
+            }
+            
         }
 
         $this->log('Auth.Dispatch: User cound not authorized (username=%s)', $username, AgaviLogger::DEBUG);
diff --git a/app/modules/AppKit/templates/Login/AjaxLoginSuccess.php b/app/modules/AppKit/templates/Login/AjaxLoginSuccess.php
index f5a7ead..fee2050 100755
--- a/app/modules/AppKit/templates/Login/AjaxLoginSuccess.php
+++ b/app/modules/AppKit/templates/Login/AjaxLoginSuccess.php
@@ -1,9 +1,9 @@
 <?php
 	$message = $t['message'];
+	$username = isset($t['username']) ? $t['username'] : '';
 ?>
-<script type="text/javascript">
+<script pe="text/javascript">
 Ext.onReady(function() {
-
 	var bAuthenticated = false;
 	
 	<?php if ($us->isAuthenticated() == true) { ?>
@@ -36,7 +36,7 @@ Ext.onReady(function() {
 				fieldLabel: '<?php echo $tm->_("User"); ?>',
 				name: 'username',
 				id: 'username',
-				allowBlank: false
+				allowBlank: false 
 			}, {
 				fieldLabel: '<?php echo $tm->_("Password"); ?>',
 				inputType: 'password',
@@ -48,6 +48,7 @@ Ext.onReady(function() {
 			listeners: {
 				afterrender: function(p) {
 					pub.resetForm(true);
+					oFormPanel.getForm().findField('username').setValue('<?php echo $username; ?>');
 				}
 			},
 			
diff --git a/app/modules/AppKit/validate/Login/AjaxLogin.xml b/app/modules/AppKit/validate/Login/AjaxLogin.xml
index 862df41..0c7e37e 100755
--- a/app/modules/AppKit/validate/Login/AjaxLogin.xml
+++ b/app/modules/AppKit/validate/Login/AjaxLogin.xml
@@ -8,7 +8,7 @@
 		
 		<validators method="write">
 		
-			<validator class="string" name="username_length" required="true">
+			<validator class="string" name="username_length" required="false">
 					<arguments>
 						<argument>username</argument>
 					</arguments>
@@ -44,6 +44,10 @@
 						<error>Validation of login start failed</error>
 					</errors>
 			</validator>
+			
+			<validator class="string" name="icinga-web-loginname" required="false" source="cookies">
+				<argument>icinga-web-loginname</argument>
+			</validator>
 		
 		</validators>
 		
diff --git a/app/modules/AppKit/validate/Login/SilentAuth.xml b/app/modules/AppKit/validate/Login/SilentAuth.xml
index 1b17168..0aafb4b 100644
--- a/app/modules/AppKit/validate/Login/SilentAuth.xml
+++ b/app/modules/AppKit/validate/Login/SilentAuth.xml
@@ -10,7 +10,7 @@
 			<validator class="string" source="headers" required="false">
 				<argument>PHP_AUTH_USER</argument>
 			</validator>
-
+			
 		</validators>
 	</ae:configuration>
 </ae:configurations>
diff --git a/app/modules/AppKit/views/Login/AjaxLoginSuccessView.class.php b/app/modules/AppKit/views/Login/AjaxLoginSuccessView.class.php
index 7c71152..2a04de1 100644
--- a/app/modules/AppKit/views/Login/AjaxLoginSuccessView.class.php
+++ b/app/modules/AppKit/views/Login/AjaxLoginSuccessView.class.php
@@ -7,10 +7,14 @@ class AppKit_Login_AjaxLoginSuccessView extends AppKitBaseView {
         if ($this->getContext()->getUser()->isAuthenticated() !== true) {
             $this->getResponse()->setHttpStatusCode('403');
         }
-
+        
         $this->setAttribute('message', false);
         $message = AgaviConfig::get('modules.appkit.auth.message', false);
-
+        
+        if ($rd->has('cookies', 'icinga-web-loginname') && AgaviConfig::get('modules.appkit.auth.behaviour.store_loginname', false)===true) {
+            $this->setAttribute('username', $rd->get('cookies', 'icinga-web-loginname'));
+        }
+        
         if ($message !== false && is_array($message)) {
             if (isset($message['show']) && $message['show']==true) {
 
diff --git a/app/modules/AppKit/views/Login/SilentAuthSuccessView.class.php b/app/modules/AppKit/views/Login/SilentAuthSuccessView.class.php
index 4984f59..d3dd7b0 100644
--- a/app/modules/AppKit/views/Login/SilentAuthSuccessView.class.php
+++ b/app/modules/AppKit/views/Login/SilentAuthSuccessView.class.php
@@ -26,7 +26,7 @@ class AppKit_Login_SilentAuthSuccessView extends AppKitBaseView {
 
         } else {
             if (AgaviConfig::get('modules.appkit.auth.behaviour.enable_dialog', false) == true) {
-                return $this->createForwardContainer('AppKit', 'Login.AjaxLogin', null, null, 'read');
+                return $this->createForwardContainer('AppKit', 'Login.AjaxLogin', null, null, 'write');
             }
         }
 





More information about the icinga-checkins mailing list