Hello,

I just fixed a bug in Spacewalk about the pam setting on the user page not 
saving,
it can be reproduced like this:

1. Configure pam on the server (e.g. echo "pam_auth_service = rhn-satellite" >> 
/etc/rhn/rhn.conf)
2. Restart the tomcat
3. Log into spacewalk as an org_admin
4. In the page header click on <username> to edit the user's settings
5. Check on/off the "use pam" checkbox
6. Click on update

Result: The pam setting is not saved and the checkbox on the resulting page is
therefore shown in the same state as before.

(Note that it works to set the pam option for a user via "Users" -> <username>)

Apply my attached patch for a fix, i.e. save the pam option using either
AdminUserEditAction.java or SelfUserEditAction.java.

Thanks,
Johannes

P.S.: I can also create a bugzilla entry if necessary, just tell me.

-- 
SUSE LINUX Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB 16746 (AG Nürnberg)
>From 4abfbdcaea3ea3ddc5d9bb6aa1d478f2975d5723 Mon Sep 17 00:00:00 2001
From: Johannes Renner <jren...@suse.de>
Date: Wed, 12 Oct 2011 13:23:01 +0200
Subject: [PATCH] Fixed pam setting on user page not saving

---
 .../frontend/action/user/AdminUserEditAction.java  |   24 +------------------
 .../rhn/frontend/action/user/SelfEditAction.java   |    3 ++
 .../frontend/action/user/UserEditActionHelper.java |   24 ++++++++++++++++++++
 3 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/java/code/src/com/redhat/rhn/frontend/action/user/AdminUserEditAction.java b/java/code/src/com/redhat/rhn/frontend/action/user/AdminUserEditAction.java
index e34b726..fdcd29d 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/user/AdminUserEditAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/user/AdminUserEditAction.java
@@ -14,8 +14,6 @@
  */
 package com.redhat.rhn.frontend.action.user;
 
-import com.redhat.rhn.common.conf.Config;
-import com.redhat.rhn.common.conf.ConfigDefaults;
 import com.redhat.rhn.common.security.PermissionException;
 import com.redhat.rhn.domain.org.Org;
 import com.redhat.rhn.domain.role.Role;
@@ -85,26 +83,8 @@ public class AdminUserEditAction extends UserEditActionHelper {
             return returnFailure(mapping, request, errors, targetUser.getId());
         }
 
-        /*
-         * Update PAM Authentication attribute
-         * If we're a satellite that is configured to use pam and the loggedIn user is an
-         * org_admin (and therefore the checkbox was displayed), we need to inspect the
-         * "usepam" field on the form and set the targetUser's pam auth attribute
-         * accordingly. (we don't want to set this field if it wasn't displayed or if the
-         * user doesn't have access to set this attribute)
-         */
-        String pamAuthService = Config.get().getString(ConfigDefaults.WEB_PAM_AUTH_SERVICE);
-        if (pamAuthService != null &&
-                pamAuthService.trim().length() > 0 &&
-                loggedInUser.hasRole(RoleFactory.ORG_ADMIN)) {
-            if (form.get("usepam") != null &&
-                    ((Boolean) form.get("usepam")).booleanValue()) {
-                targetUser.setUsePamAuthentication(true);
-            }
-            else {
-                targetUser.setUsePamAuthentication(false);
-            }
-        }
+        // Update PAM Authentication attribute
+        updatePamAttribute(loggedInUser, targetUser, form);
 
         //Create the user info updated success message
         createSuccessMessage(request, "message.userInfoUpdated", null);
diff --git a/java/code/src/com/redhat/rhn/frontend/action/user/SelfEditAction.java b/java/code/src/com/redhat/rhn/frontend/action/user/SelfEditAction.java
index d7f8dcc..cf3201b 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/user/SelfEditAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/user/SelfEditAction.java
@@ -48,6 +48,9 @@ public class SelfEditAction extends UserEditActionHelper {
 
         //If there are no errors, store the user and return the success mapping
         if (errors.isEmpty()) {
+            // Update the PAM Authentication attribute
+            updatePamAttribute(user, user, form);
+
             UserManager.storeUser(user);
 
             ActionMessages msgs = new ActionMessages();
diff --git a/java/code/src/com/redhat/rhn/frontend/action/user/UserEditActionHelper.java b/java/code/src/com/redhat/rhn/frontend/action/user/UserEditActionHelper.java
index c61fbc6..a9c1625 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/user/UserEditActionHelper.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/user/UserEditActionHelper.java
@@ -14,6 +14,9 @@
  */
 package com.redhat.rhn.frontend.action.user;
 
+import com.redhat.rhn.common.conf.Config;
+import com.redhat.rhn.common.conf.ConfigDefaults;
+import com.redhat.rhn.domain.role.RoleFactory;
 import com.redhat.rhn.domain.user.User;
 import com.redhat.rhn.frontend.struts.RhnAction;
 import com.redhat.rhn.frontend.struts.RhnValidationHelper;
@@ -67,4 +70,25 @@ public abstract class UserEditActionHelper extends RhnAction {
 
         return errors;
     }
+
+    /**
+     * If pam is configured and the loggedInUser is an org_admin (and therefore
+     * the checkbox was displayed), we need to inspect the "usepam" field on the
+     * form and set the targetUser's pam auth attribute accordingly.
+     * @param loggedInUser The user who is currently logged in
+     * @param targetUser The user that will be updated
+     * @param form The form containing the attribute value to use
+     */
+    protected void updatePamAttribute(User loggedInUser, User targetUser, DynaActionForm form) {
+        String pamAuthService = Config.get().getString(ConfigDefaults.WEB_PAM_AUTH_SERVICE);
+        if (pamAuthService != null && pamAuthService.trim().length() > 0
+                && loggedInUser.hasRole(RoleFactory.ORG_ADMIN)) {
+            if (form.get("usepam") != null
+                    && ((Boolean) form.get("usepam")).booleanValue()) {
+                targetUser.setUsePamAuthentication(true);
+            } else {
+                targetUser.setUsePamAuthentication(false);
+            }
+        }
+    }
 }
-- 
1.7.3.4

_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to