Selaa lähdekoodia

setting for new user reg password prompt

Jason Rivard 8 vuotta sitten
vanhempi
commit
fd31d7b760

+ 2 - 0
src/main/java/password/pwm/config/PwmSetting.java

@@ -798,6 +798,8 @@ public enum PwmSetting {
             "newUser.profile.displayName", PwmSettingSyntax.LOCALIZED_STRING, PwmSettingCategory.NEWUSER_PROFILE),
     NEWUSER_REDIRECT_URL(
             "newUser.redirectUrl", PwmSettingSyntax.STRING, PwmSettingCategory.NEWUSER_PROFILE),
+    NEWUSER_PROMPT_FOR_PASSWORD(
+            "newUser.promptForPassword", PwmSettingSyntax.BOOLEAN, PwmSettingCategory.NEWUSER_PROFILE),
 
     // guest settings
     GUEST_ENABLE(

+ 43 - 12
src/main/java/password/pwm/http/servlet/newuser/NewUserFormUtils.java

@@ -27,6 +27,7 @@ import password.pwm.config.FormConfiguration;
 import password.pwm.config.FormUtility;
 import password.pwm.config.PwmSetting;
 import password.pwm.config.profile.NewUserProfile;
+import password.pwm.config.profile.PwmPasswordPolicy;
 import password.pwm.error.PwmDataValidationException;
 import password.pwm.error.PwmError;
 import password.pwm.error.PwmOperationalException;
@@ -35,6 +36,7 @@ import password.pwm.http.PwmRequest;
 import password.pwm.http.bean.NewUserBean;
 import password.pwm.svc.token.TokenPayload;
 import password.pwm.util.PasswordData;
+import password.pwm.util.RandomPasswordGenerator;
 import password.pwm.util.java.StringUtil;
 import password.pwm.util.logging.PwmLogger;
 
@@ -49,34 +51,63 @@ class NewUserFormUtils {
     private static final PwmLogger LOGGER = PwmLogger.forClass(NewUserFormUtils.class);
 
 
-    static NewUserBean.NewUserForm readFromRequest(final PwmRequest pwmRequest)
+    static NewUserBean.NewUserForm readFromRequest(
+            final PwmRequest pwmRequest
+    )
             throws PwmDataValidationException, PwmUnrecoverableException
     {
+        final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
+        final boolean promptForPassword = newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_PROMPT_FOR_PASSWORD);
+
         final Locale userLocale = pwmRequest.getLocale();
         final List<FormConfiguration> newUserForm = NewUserServlet.getFormDefinition(pwmRequest);
         final Map<FormConfiguration, String> userFormValues = FormUtility.readFormValuesFromRequest(pwmRequest,
                 newUserForm, userLocale);
-        final PasswordData passwordData1 = pwmRequest.readParameterAsPassword(NewUserServlet.FIELD_PASSWORD1);
-        final PasswordData passwordData2 = pwmRequest.readParameterAsPassword(NewUserServlet.FIELD_PASSWORD2);
+        final PasswordData passwordData1;
+        final PasswordData passwordData2;
+        if (promptForPassword) {
+            passwordData1 = pwmRequest.readParameterAsPassword(NewUserServlet.FIELD_PASSWORD1);
+            passwordData2 = pwmRequest.readParameterAsPassword(NewUserServlet.FIELD_PASSWORD2);
+        } else {
+            final PwmPasswordPolicy pwmPasswordPolicy = newUserProfile.getNewUserPasswordPolicy(pwmRequest.getPwmApplication(), pwmRequest.getLocale());
+            final PasswordData password = RandomPasswordGenerator.createRandomPassword(pwmRequest.getSessionLabel(), pwmPasswordPolicy, pwmRequest.getPwmApplication());
+            passwordData1 = password;
+            passwordData2 = password;
+        }
         return new NewUserBean.NewUserForm(FormUtility.asStringMap(userFormValues), passwordData1, passwordData2);
     }
 
-    static NewUserBean.NewUserForm readFromJsonRequest(final PwmRequest pwmRequest)
+    static NewUserBean.NewUserForm readFromJsonRequest(
+            final PwmRequest pwmRequest
+    )
             throws IOException, PwmUnrecoverableException, PwmDataValidationException
     {
+        final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
+        final boolean promptForPassword = newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_PROMPT_FOR_PASSWORD);
+
         final Locale userLocale = pwmRequest.getLocale();
         final List<FormConfiguration> newUserForm = NewUserServlet.getFormDefinition(pwmRequest);
         final Map<String, String> jsonBodyMap = pwmRequest.readBodyAsJsonStringMap();
         final Map<FormConfiguration, String> userFormValues = FormUtility.readFormValuesFromMap(jsonBodyMap,
                 newUserForm, userLocale);
-        final PasswordData passwordData1 = jsonBodyMap.containsKey(NewUserServlet.FIELD_PASSWORD1) && !jsonBodyMap.get(
-                NewUserServlet.FIELD_PASSWORD1).isEmpty()
-                ? new PasswordData(jsonBodyMap.get(NewUserServlet.FIELD_PASSWORD1))
-                : null;
-        final PasswordData passwordData2 = jsonBodyMap.containsKey(NewUserServlet.FIELD_PASSWORD2) && !jsonBodyMap.get(
-                NewUserServlet.FIELD_PASSWORD2).isEmpty()
-                ? new PasswordData(jsonBodyMap.get(NewUserServlet.FIELD_PASSWORD2))
-                : null;
+
+        final PasswordData passwordData1;
+        final PasswordData passwordData2;
+        if (promptForPassword) {
+            passwordData1 = jsonBodyMap.containsKey(NewUserServlet.FIELD_PASSWORD1) && !jsonBodyMap.get(
+                    NewUserServlet.FIELD_PASSWORD1).isEmpty()
+                    ? new PasswordData(jsonBodyMap.get(NewUserServlet.FIELD_PASSWORD1))
+                    : null;
+            passwordData2 = jsonBodyMap.containsKey(NewUserServlet.FIELD_PASSWORD2) && !jsonBodyMap.get(
+                    NewUserServlet.FIELD_PASSWORD2).isEmpty()
+                    ? new PasswordData(jsonBodyMap.get(NewUserServlet.FIELD_PASSWORD2))
+                    : null;
+        } else {
+            final PwmPasswordPolicy pwmPasswordPolicy = newUserProfile.getNewUserPasswordPolicy(pwmRequest.getPwmApplication(), pwmRequest.getLocale());
+            final PasswordData password = RandomPasswordGenerator.createRandomPassword(pwmRequest.getSessionLabel(), pwmPasswordPolicy, pwmRequest.getPwmApplication());
+            passwordData1 = password;
+            passwordData2 = password;
+        }
         return new NewUserBean.NewUserForm(FormUtility.asStringMap(userFormValues), passwordData1, passwordData2);
     }
 

+ 5 - 2
src/main/java/password/pwm/http/servlet/newuser/NewUserServlet.java

@@ -48,6 +48,7 @@ import password.pwm.http.servlet.AbstractPwmServlet;
 import password.pwm.http.servlet.ControlledPwmServlet;
 import password.pwm.http.servlet.PwmServletDefinition;
 import password.pwm.i18n.Message;
+import password.pwm.ldap.UserInfo;
 import password.pwm.ldap.UserInfoBean;
 import password.pwm.svc.token.TokenPayload;
 import password.pwm.util.CaptchaUtility;
@@ -345,7 +346,7 @@ public class NewUserServlet extends ControlledPwmServlet {
                 Collections.emptyList(),
                 allowResultCaching
         );
-        final UserInfoBean uiBean = UserInfoBean.builder()
+        final UserInfo uiBean = UserInfoBean.builder()
                 .cachedPasswordRuleAttributes(FormUtility.asStringMap(formValueData))
                 .passwordPolicy(newUserProfile.getNewUserPasswordPolicy(pwmApplication, locale))
                 .build();
@@ -607,7 +608,9 @@ public class NewUserServlet extends ControlledPwmServlet {
             throws ServletException, PwmUnrecoverableException, IOException
     {
         final List<FormConfiguration> formConfiguration = getFormDefinition(pwmRequest);
-        pwmRequest.addFormInfoToRequestAttr(formConfiguration, null, false, true);
+        final NewUserProfile newUserProfile = getNewUserProfile(pwmRequest);
+        final boolean promptForPassword = newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_PROMPT_FOR_PASSWORD);
+        pwmRequest.addFormInfoToRequestAttr(formConfiguration, null, false, promptForPassword);
 
         {
             final boolean showBack = !newUserBean.isUrlSpecifiedProfile()

+ 2 - 2
src/main/java/password/pwm/http/servlet/newuser/NewUserUtils.java

@@ -37,8 +37,6 @@ import password.pwm.bean.LoginInfoBean;
 import password.pwm.bean.SessionLabel;
 import password.pwm.bean.TokenVerificationProgress;
 import password.pwm.bean.UserIdentity;
-import password.pwm.ldap.UserInfo;
-import password.pwm.ldap.UserInfoBean;
 import password.pwm.config.ActionConfiguration;
 import password.pwm.config.Configuration;
 import password.pwm.config.PwmSetting;
@@ -52,6 +50,8 @@ import password.pwm.error.PwmUnrecoverableException;
 import password.pwm.http.PwmRequest;
 import password.pwm.http.PwmSession;
 import password.pwm.http.bean.NewUserBean;
+import password.pwm.ldap.UserInfo;
+import password.pwm.ldap.UserInfoBean;
 import password.pwm.ldap.auth.PwmAuthenticationSource;
 import password.pwm.ldap.auth.SessionAuthenticator;
 import password.pwm.ldap.search.SearchConfiguration;

+ 7 - 1
src/main/resources/password/pwm/config/PwmSetting.xml

@@ -2593,8 +2593,14 @@
         </default>
     </setting>
     <setting hidden="false" key="newUser.redirectUrl" level="1">
+        <flag>MacroSupport</flag>
         <default>
-            <value></value>
+            <value/>
+        </default>
+    </setting>
+    <setting hidden="false" key="newUser.promptForPassword" level="1">
+        <default>
+            <value>true</value>
         </default>
     </setting>
     <setting hidden="false" key="guest.enable" level="1" required="true">

+ 2 - 0
src/main/resources/password/pwm/i18n/PwmSetting.properties

@@ -470,6 +470,7 @@ Setting_Description_newUser.minimumWaitTime=Specify a delay time during a new us
 Setting_Description_newUser.passwordPolicy.user=Specify the user @PwmAppName@ uses a template for the new user password policy. If the value is <i>TESTUSER</i>, @PwmAppName@ uses the configured test user's password policy.
 Setting_Description_newUser.profile.displayName=Specify the publicly viewable display name of this profile.
 Setting_Description_newUser.profile.list=List of New User profiles. When you configure multiple new user profiles, the user can select which profile to complete.  @PwmAppName@ shows the profile name to the users as the value of the setting <code>@PwmSettingReference\:newUser.profile.displayName@</code>.
+Setting_Description_newUser.promptForPassword=Prompt user for password during user registration.  If not enabled, a random password will be assigned to the user.  In most cases you will want this enabled.
 Setting_Description_newUser.redirectUrl=URL to redirect user to after new user registration process is completed.
 Setting_Description_newUser.sms.verification=Enable this option to have @PwmAppName@ send an SMS to the new user's mobile phone number before it creates the account. The NewUser must verify receipt of the SMS before @PwmAppName@ creates the account.
 Setting_Description_newUser.username.definition=<p>Specify the entry ID of the newly created LDAP entry. In some directories this is often used as the "user name", though many directories separate the concepts and values of entry ID and user name.</p><br/><br/><p>Values can (and usually do) include macros.  In case the first value already exists in the directory, @PwmAppName@ tries each successive value until it finds a free value.  Though @PwmAppName@ has not yet created the user when it evaluates the macros, the LDAP macros use the data provided on the new user form.  Other macros might not be useful as there no data yet available on the user.</p><br/><br/><p>If blank, the user name must be present in the form, defined as the LDAP naming attribute value.</p>
@@ -942,6 +943,7 @@ Setting_Label_newUser.minimumWaitTime=New User Minimum Wait Time
 Setting_Label_newUser.passwordPolicy.user=Password Policy Template
 Setting_Label_newUser.profile.displayName=Profile Display Name
 Setting_Label_newUser.profile.list=New User Profile
+Setting_Label_newUser.promptForPassword=Prompt User for Password
 Setting_Label_newUser.redirectUrl=After Registration Redirect URL
 Setting_Label_newUser.sms.verification=Enable New User SMS Verification
 Setting_Label_newUser.username.definition=LDAP Entry ID Definition