Skip to content

Commit f816d2f

Browse files
committed
Skip password verification for PAM users
This commit changes how PAM users password verification works. Instead of relying on additional variable, which was not correctly set, always rely on user PAM settings. Also use PAM settings only in the actual password set routine in order not to hide some potentional future errors.
1 parent 6df89eb commit f816d2f

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

java/code/src/com/redhat/rhn/frontend/action/user/CreateUserAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2009--2014 Red Hat, Inc.
3+
* Copyright (c) 2025 SUSE LLC
34
*
45
* This software is licensed to you under the GNU General Public License,
56
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -46,7 +47,7 @@ public class CreateUserAction extends RhnAction {
4647
public static final String FAILURE = "failure";
4748
public static final String SUCCESS_INTO_ORG = "existorgsuccess";
4849

49-
private ActionErrors populateCommand(DynaActionForm form, CreateUserCommand command, boolean validatePassword) {
50+
private ActionErrors populateCommand(DynaActionForm form, CreateUserCommand command) {
5051
ActionErrors errors = new ActionErrors();
5152

5253
command.setEmail(form.getString("email"));
@@ -67,7 +68,7 @@ private ActionErrors populateCommand(DynaActionForm form, CreateUserCommand comm
6768
String passwd = (String)form.get(UserActionHelper.DESIRED_PASS);
6869
String passwdConfirm = (String)form.get(UserActionHelper.DESIRED_PASS_CONFIRM);
6970
if (passwd.equals(passwdConfirm)) {
70-
command.setPassword(passwd, validatePassword);
71+
command.setPassword(passwd);
7172
}
7273
else {
7374
errors.add(ActionMessages.GLOBAL_MESSAGE,
@@ -122,7 +123,6 @@ public ActionForward execute(ActionMapping mapping,
122123
* in the db (even though it won't be used), we'll just validate it like a regular
123124
* password and allow it.
124125
*/
125-
boolean validatePassword = true;
126126
if (form.get("usepam") != null && (Boolean) form.get("usepam")) {
127127
String fakePassword = CryptHelper.getRandomPasswordForPamAuth();
128128
if (form.get(UserActionHelper.DESIRED_PASS) == null ||
@@ -144,7 +144,7 @@ public ActionForward execute(ActionMapping mapping,
144144

145145
// Create the user and do some more validation
146146
CreateUserCommand command = getCommand();
147-
ActionErrors errors = populateCommand(form, command, validatePassword);
147+
ActionErrors errors = populateCommand(form, command);
148148
if (!errors.isEmpty()) {
149149
return returnError(mapping, request, errors);
150150
}

java/code/src/com/redhat/rhn/frontend/action/user/test/CreateUserActionTest.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2009--2014 Red Hat, Inc.
3+
* Copyright (c) 2025 SUSE LLC
34
*
45
* This software is licensed to you under the GNU General Public License,
56
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -18,6 +19,8 @@
1819
import static org.junit.jupiter.api.Assertions.assertTrue;
1920

2021
import com.redhat.rhn.common.messaging.MessageQueue;
22+
import com.redhat.rhn.domain.common.RhnConfiguration;
23+
import com.redhat.rhn.domain.common.RhnConfigurationFactory;
2124
import com.redhat.rhn.frontend.action.user.UserActionHelper;
2225
import com.redhat.rhn.testing.RhnMockDynaActionForm;
2326
import com.redhat.rhn.testing.RhnPostMockStrutsTestCase;
@@ -54,10 +57,23 @@ public void testMessageQueueRegistration() {
5457

5558
@Test
5659
public void testNewUserIntoOrgSatellite() {
60+
setRequestPathInfo("/newlogin/CreateUserSubmit");
61+
RhnMockDynaActionForm form = fillOutForm("userCreateForm", false);
62+
setActionForm(form);
63+
actionPerform();
64+
String forwardPath = getActualForward();
65+
assertNotNull(forwardPath);
66+
assertTrue(forwardPath.startsWith("/users/ActiveList.do?uid="));
67+
}
5768

69+
@Test
70+
public void testPasswordNotValidatedOnPAM() {
71+
// setup strict password policy requiring special character
72+
RhnConfigurationFactory factory = RhnConfigurationFactory.getSingleton();
73+
factory.updateConfigurationValue(RhnConfiguration.KEYS.PSW_CHECK_SPECIAL_CHAR_FLAG, true);
5874

5975
setRequestPathInfo("/newlogin/CreateUserSubmit");
60-
RhnMockDynaActionForm form = fillOutForm("userCreateForm");
76+
RhnMockDynaActionForm form = fillOutForm("userCreateForm", true);
6177
setActionForm(form);
6278
actionPerform();
6379
String forwardPath = getActualForward();
@@ -68,7 +84,7 @@ public void testNewUserIntoOrgSatellite() {
6884
/**
6985
* @return Properly filled out user creation form.
7086
*/
71-
private RhnMockDynaActionForm fillOutForm(String formName) {
87+
private RhnMockDynaActionForm fillOutForm(String formName, boolean usePAM) {
7288
RhnMockDynaActionForm f = new RhnMockDynaActionForm(formName);
7389
f.set("login", "testUser" + TestUtils.randomString());
7490
f.set("address1", "123 somewhere ln");
@@ -83,15 +99,20 @@ private RhnMockDynaActionForm fillOutForm(String formName) {
8399
f.set("fax", "");
84100
f.set("firstNames", "CreateUserActionTest fname");
85101
f.set("lastName", "CreateUserActionTest lname");
86-
f.set(UserActionHelper.DESIRED_PASS, "password");
87-
f.set(UserActionHelper.DESIRED_PASS_CONFIRM, "password");
88102
f.set("phone", "123-123-1234");
89103
f.set("prefix", "Mr.");
90104
f.set("state", "OH");
91105
f.set("title", "Heavyweight");
92106
f.set("zip", "45241");
93107
f.set("timezone", 7010);
94108
f.set("preferredLocale", "en_US");
109+
if (usePAM) {
110+
f.set("usepam", Boolean.TRUE);
111+
}
112+
else {
113+
f.set(UserActionHelper.DESIRED_PASS, "password");
114+
f.set(UserActionHelper.DESIRED_PASS_CONFIRM, "password");
115+
}
95116
return f;
96117
}
97118
}

java/code/src/com/redhat/rhn/manager/user/CreateUserCommand.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2009--2015 Red Hat, Inc.
3+
* Copyright (c) 2025 SUSE LLC
34
*
45
* This software is licensed to you under the GNU General Public License,
56
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -85,7 +86,7 @@ public CreateUserCommand() {
8586
public ValidatorError[] validate() {
8687
errors = new ArrayList<>(); //clear validation errors
8788

88-
if (passwordErrors != null && !user.getUsePamAuthentication()) {
89+
if (passwordErrors != null) {
8990
errors.addAll(passwordErrors); //add any password validation errors
9091
}
9192
validateEmail();
@@ -305,11 +306,13 @@ public void setRawPassword(String passwordIn) {
305306
}
306307

307308
/**
309+
* Set password to the user if passed validation.
310+
*
311+
* PAM enabled users will skip verification of the password
308312
* @param passwordIn The password to set
309-
* @param validate if password requirements should be validated
310313
*/
311-
public void setPassword(String passwordIn, boolean validate) {
312-
if (!validate) {
314+
public void setPassword(String passwordIn) {
315+
if (user.getUsePamAuthentication()) {
313316
user.setPassword(passwordIn);
314317
}
315318
else {
@@ -322,13 +325,6 @@ public void setPassword(String passwordIn, boolean validate) {
322325
}
323326
}
324327

325-
/**
326-
* @param passwordIn The password to set
327-
*/
328-
public void setPassword(String passwordIn) {
329-
setPassword(passwordIn, true);
330-
}
331-
332328
/**
333329
* @param prefixIn The prefix to set
334330
*/
@@ -365,6 +361,8 @@ public void setFax(String faxIn) {
365361
}
366362

367363
/**
364+
* PAM enabled user
365+
* Setting this to true will skip password policy verification
368366
* @param val Should this user use pam authentication?
369367
*/
370368
public void setUsePamAuthentication(boolean val) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Do not validate random password when using PAM
2+
(bsc#1245398)

0 commit comments

Comments
 (0)