浏览代码

configguide fixes and improvements

Jason Rivard 4 年之前
父节点
当前提交
026598c3d9

+ 6 - 7
server/src/main/java/password/pwm/http/servlet/configguide/ConfigGuideForm.java

@@ -51,7 +51,6 @@ import java.util.Map;
 
 
 public class ConfigGuideForm
 public class ConfigGuideForm
 {
 {
-
     private static final PwmLogger LOGGER = PwmLogger.forClass( ConfigGuideForm.class );
     private static final PwmLogger LOGGER = PwmLogger.forClass( ConfigGuideForm.class );
 
 
     public static Map<ConfigGuideFormField, String> defaultForm( )
     public static Map<ConfigGuideFormField, String> defaultForm( )
@@ -66,11 +65,6 @@ public class ConfigGuideForm
         defaultLdapForm.put( ConfigGuideFormField.PARAM_LDAP_SECURE, "true" );
         defaultLdapForm.put( ConfigGuideFormField.PARAM_LDAP_SECURE, "true" );
         defaultLdapForm.remove( ConfigGuideFormField.CHALLENGE_RESPONSE_DATA );
         defaultLdapForm.remove( ConfigGuideFormField.CHALLENGE_RESPONSE_DATA );
 
 
-        defaultLdapForm.put( ConfigGuideFormField.PARAM_LDAP_HOST, "172.17.2.91" );
-        defaultLdapForm.put( ConfigGuideFormField.PARAM_LDAP_CONTEXT, "ou=users,o=data" );
-        defaultLdapForm.put( ConfigGuideFormField.PARAM_LDAP_PROXY_DN, "cn=pwm-proxy,ou=sa,o=system" );
-        defaultLdapForm.put( ConfigGuideFormField.PARAM_LDAP_PROXY_PW, "gcms1234" );
-
         return Collections.unmodifiableMap( defaultLdapForm );
         return Collections.unmodifiableMap( defaultLdapForm );
     }
     }
 
 
@@ -238,7 +232,7 @@ public class ConfigGuideForm
     {
     {
         final String ldapServerIP = ldapForm.get( ConfigGuideFormField.PARAM_LDAP_HOST );
         final String ldapServerIP = ldapForm.get( ConfigGuideFormField.PARAM_LDAP_HOST );
         final String ldapServerPort = ldapForm.get( ConfigGuideFormField.PARAM_LDAP_PORT );
         final String ldapServerPort = ldapForm.get( ConfigGuideFormField.PARAM_LDAP_PORT );
-        final boolean ldapServerSecure = "true".equalsIgnoreCase( ldapForm.get( ConfigGuideFormField.PARAM_LDAP_SECURE ) );
+        final boolean ldapServerSecure = readCheckedFormField( ldapForm.get( ConfigGuideFormField.PARAM_LDAP_SECURE ) );
 
 
         return "ldap" + ( ldapServerSecure ? "s" : "" ) + "://" + ldapServerIP + ":" + ldapServerPort;
         return "ldap" + ( ldapServerSecure ? "s" : "" ) + "://" + ldapServerIP + ":" + ldapServerPort;
     }
     }
@@ -258,4 +252,9 @@ public class ConfigGuideForm
         }
         }
         return "ldap.example.com";
         return "ldap.example.com";
     }
     }
+
+    public static boolean readCheckedFormField( final String value )
+    {
+        return "on".equalsIgnoreCase( value ) || "true".equalsIgnoreCase( value );
+    }
 }
 }

+ 1 - 1
server/src/main/java/password/pwm/http/servlet/configguide/ConfigGuideUtils.java

@@ -136,7 +136,7 @@ public class ConfigGuideUtils
     )
     )
     {
     {
         final Map<ConfigGuideFormField, String> form = configGuideBean.getFormData();
         final Map<ConfigGuideFormField, String> form = configGuideBean.getFormData();
-        final boolean ldapServerSecure = "true".equalsIgnoreCase( form.get( ConfigGuideFormField.PARAM_LDAP_SECURE ) );
+        final boolean ldapServerSecure = ConfigGuideForm.readCheckedFormField( form.get( ConfigGuideFormField.PARAM_LDAP_SECURE ) );
         final String ldapUrl = "ldap" + ( ldapServerSecure ? "s" : "" )
         final String ldapUrl = "ldap" + ( ldapServerSecure ? "s" : "" )
                 + "://"
                 + "://"
                 + form.get( ConfigGuideFormField.PARAM_LDAP_HOST )
                 + form.get( ConfigGuideFormField.PARAM_LDAP_HOST )

+ 1 - 1
webapp/pom.xml

@@ -96,7 +96,7 @@
                     <archiveClasses>false</archiveClasses>
                     <archiveClasses>false</archiveClasses>
                     <packagingExcludes>**/*.jsp</packagingExcludes>
                     <packagingExcludes>**/*.jsp</packagingExcludes>
                     <!-- remove/comment the next line to prevent pre-compiled JSPs from being used in the output WAR -->
                     <!-- remove/comment the next line to prevent pre-compiled JSPs from being used in the output WAR -->
-                    <webXml>${project.build.directory}/web.xml</webXml>
+                    <!--<webXml>${project.build.directory}/web.xml</webXml>-->
                     <archive>
                     <archive>
                         <manifestEntries>
                         <manifestEntries>
                             <Implementation-Archive-Name>${warArtifactID}</Implementation-Archive-Name>
                             <Implementation-Archive-Name>${warArtifactID}</Implementation-Archive-Name>

+ 1 - 1
webapp/src/main/webapp/WEB-INF/jsp/configguide-end.jsp

@@ -84,7 +84,7 @@
                         <td><b>Secure (SSL) Connection</b>
                         <td><b>Secure (SSL) Connection</b>
                         </td>
                         </td>
                         <td>
                         <td>
-                            <%if (Boolean.parseBoolean(configGuideBean.getFormData().get(ConfigGuideFormField.PARAM_LDAP_SECURE))) {%>
+                            <%if (ConfigGuideForm.readCheckedFormField(configGuideBean.getFormData().get(ConfigGuideFormField.PARAM_LDAP_SECURE))) {%>
                             <pwm:display key="Value_True"/>
                             <pwm:display key="Value_True"/>
                             <% } else { %>
                             <% } else { %>
                             <pwm:display key="Value_False"/>
                             <pwm:display key="Value_False"/>

+ 6 - 8
webapp/src/main/webapp/WEB-INF/jsp/configguide-ldap_server.jsp

@@ -81,10 +81,10 @@
                                 <input class="configNumericInput" type="number" min="0" max="65535" id="<%=ConfigGuideFormField.PARAM_LDAP_PORT%>" name="<%=ConfigGuideFormField.PARAM_LDAP_PORT%>" value="<%=configGuideBean.getFormData().get(ConfigGuideFormField.PARAM_LDAP_PORT)%>"/>
                                 <input class="configNumericInput" type="number" min="0" max="65535" id="<%=ConfigGuideFormField.PARAM_LDAP_PORT%>" name="<%=ConfigGuideFormField.PARAM_LDAP_PORT%>" value="<%=configGuideBean.getFormData().get(ConfigGuideFormField.PARAM_LDAP_PORT)%>"/>
                             </td>
                             </td>
                             <td>
                             <td>
-                                <% final boolean secureChecked = "true".equalsIgnoreCase(configGuideBean.getFormData().get(ConfigGuideFormField.PARAM_LDAP_SECURE));%>
+                                <% final boolean secureChecked = ConfigGuideForm.readCheckedFormField(configGuideBean.getFormData().get(ConfigGuideFormField.PARAM_LDAP_SECURE));%>
                                 <label class="checkboxWrapper">
                                 <label class="checkboxWrapper">
-                                    <input type="checkbox" id="widget_<%=ConfigGuideFormField.PARAM_LDAP_SECURE%>" name="nope" <%=secureChecked ? "checked" : ""%>/> Secure
-                                    <input type="hidden" id="<%=ConfigGuideFormField.PARAM_LDAP_SECURE%>" name="<%=ConfigGuideFormField.PARAM_LDAP_SECURE%>" value="uninitialized"/>
+                                    <input type="checkbox" id="<%=ConfigGuideFormField.PARAM_LDAP_SECURE%>" name="<%=ConfigGuideFormField.PARAM_LDAP_SECURE%>"
+                                            <%=secureChecked ? "checked" : ""%>/> Secure
                                 </label>
                                 </label>
                             </td>
                             </td>
                         </tr>
                         </tr>
@@ -108,8 +108,6 @@
 <pwm:script>
 <pwm:script>
     <script type="text/javascript">
     <script type="text/javascript">
         function handleFormActivity() {
         function handleFormActivity() {
-            PWM_MAIN.getObject('<%=ConfigGuideFormField.PARAM_LDAP_SECURE%>').value =
-                    PWM_MAIN.getObject('widget_<%=ConfigGuideFormField.PARAM_LDAP_SECURE%>').checked ? "true" : "false";
             PWM_GUIDE.updateForm();
             PWM_GUIDE.updateForm();
             clearHealthDiv();
             clearHealthDiv();
         }
         }
@@ -127,12 +125,12 @@
                 handleFormActivity();
                 handleFormActivity();
             });
             });
 
 
-            PWM_MAIN.addEventHandler('widget_<%=ConfigGuideFormField.PARAM_LDAP_SECURE%>','change',function() {
-                if (!PWM_MAIN.getObject('widget_<%=ConfigGuideFormField.PARAM_LDAP_SECURE%>').checked) {
+            PWM_MAIN.addEventHandler('<%=ConfigGuideFormField.PARAM_LDAP_SECURE%>','change',function() {
+                if (!PWM_MAIN.getObject('<%=ConfigGuideFormField.PARAM_LDAP_SECURE%>').checked) {
                     PWM_MAIN.showConfirmDialog({
                     PWM_MAIN.showConfirmDialog({
                         text: PWM_CONFIG.showString('Confirm_SSLDisable'),
                         text: PWM_CONFIG.showString('Confirm_SSLDisable'),
                         cancelAction: function () {
                         cancelAction: function () {
-                            PWM_MAIN.getObject('widget_<%=ConfigGuideFormField.PARAM_LDAP_SECURE%>').checked=true;
+                            PWM_MAIN.getObject('<%=ConfigGuideFormField.PARAM_LDAP_SECURE%>').checked=true;
                             PWM_MAIN.closeWaitDialog();
                             PWM_MAIN.closeWaitDialog();
                             handleFormActivity();
                             handleFormActivity();
                         }
                         }

+ 66 - 81
webapp/src/main/webapp/public/resources/js/configguide.js

@@ -26,65 +26,50 @@ var PWM_GLOBAL = PWM_GLOBAL || {};
 
 
 PWM_GUIDE.selectTemplate = function(template) {
 PWM_GUIDE.selectTemplate = function(template) {
     PWM_MAIN.showWaitDialog({title:'Loading...',loadFunction:function() {
     PWM_MAIN.showWaitDialog({title:'Loading...',loadFunction:function() {
-        var url = PWM_MAIN.addParamToUrl(window.location.href,'processAction','selectTemplate');
-        url = PWM_MAIN.addParamToUrl(url, 'template', template);
-        PWM_MAIN.showDialog(url,function(result){
-            if (!result['error']) {
-                PWM_MAIN.getObject('button_next').disabled = template === "NOTSELECTED";
-                PWM_MAIN.closeWaitDialog();
-            } else {
-                PWM_MAIN.showError(result['errorDetail']);
-            }
+            var url = PWM_MAIN.addParamToUrl(window.location.href,'processAction','selectTemplate');
+            url = PWM_MAIN.addParamToUrl(url, 'template', template);
+            PWM_MAIN.showDialog(url,function(result){
+                if (!result['error']) {
+                    PWM_MAIN.getObject('button_next').disabled = template === "NOTSELECTED";
+                    PWM_MAIN.closeWaitDialog();
+                } else {
+                    PWM_MAIN.showError(result['errorDetail']);
+                }
 
 
-        },{method:'GET'});
-    }});
+            },{method:'GET'});
+        }});
 };
 };
 
 
 PWM_GUIDE.updateForm = function() {
 PWM_GUIDE.updateForm = function() {
-    require(["dojo"],function(dojo){
-        var formJson = dojo.formToJson('configForm');
-        var url = PWM_MAIN.addParamToUrl(window.location.href,'processAction','updateForm');
-        url = PWM_MAIN.addPwmFormIDtoURL(url);
-        dojo.xhrPost({
-            url: url,
-            postData: formJson,
-            headers: {"Accept":"application/json"},
-            contentType: "application/json;charset=utf-8",
-            encoding: "utf-8",
-            handleAs: "json",
-            dataType: "json",
-            preventCache: true,
-            error: function(errorObj) {
-                PWM_MAIN.showError("error reaching server: " + errorObj);
-            },
-            load: function(result) {
-                console.log("sent form params to server: " + formJson);
-            }
-        });
-    });
+    var formJson = PWM_MAIN.JSLibrary.formToValueMap('configForm');
+    var url = PWM_MAIN.addParamToUrl(window.location.href,'processAction','updateForm');
+    var loadFunction = function() {
+        PWM_MAIN.log("sent form params to server: " + formJson);
+    }
+    PWM_MAIN.ajaxRequest(url,loadFunction,{content:formJson});
 };
 };
 
 
 PWM_GUIDE.gotoStep = function(step) {
 PWM_GUIDE.gotoStep = function(step) {
     PWM_MAIN.showWaitDialog({loadFunction:function(){
     PWM_MAIN.showWaitDialog({loadFunction:function(){
-        //preload in case of server restart
-        PWM_MAIN.preloadAll(function(){
-            var url = PWM_MAIN.addParamToUrl(window.location.href,'processAction','gotoStep');
-            url = PWM_MAIN.addParamToUrl(url, 'step', step);
-            var loadFunction = function(result) {
-                if (result['error']) {
-                    PWM_MAIN.showErrorDialog(result);
-                    return;
-                } else if (result['data']) {
-                    if (result['data']['serverRestart']) {
-                        PWM_CONFIG.waitForRestart();
+            //preload in case of server restart
+            PWM_MAIN.preloadAll(function(){
+                var url = PWM_MAIN.addParamToUrl(window.location.href,'processAction','gotoStep');
+                url = PWM_MAIN.addParamToUrl(url, 'step', step);
+                var loadFunction = function(result) {
+                    if (result['error']) {
+                        PWM_MAIN.showErrorDialog(result);
                         return;
                         return;
+                    } else if (result['data']) {
+                        if (result['data']['serverRestart']) {
+                            PWM_CONFIG.waitForRestart();
+                            return;
+                        }
                     }
                     }
-                }
-                PWM_MAIN.gotoUrl('config-guide');
-            };
-            PWM_MAIN.ajaxRequest(url,loadFunction);
-        });
-    }});
+                    PWM_MAIN.gotoUrl('config-guide');
+                };
+                PWM_MAIN.ajaxRequest(url,loadFunction);
+            });
+        }});
 };
 };
 
 
 PWM_GUIDE.setUseConfiguredCerts = function(value) {
 PWM_GUIDE.setUseConfiguredCerts = function(value) {
@@ -100,45 +85,45 @@ PWM_GUIDE.setUseConfiguredCerts = function(value) {
 
 
 PWM_GUIDE.extendSchema = function() {
 PWM_GUIDE.extendSchema = function() {
     PWM_MAIN.showConfirmDialog({text:"Are you sure you want to extend the LDAP schema?",okAction:function(){
     PWM_MAIN.showConfirmDialog({text:"Are you sure you want to extend the LDAP schema?",okAction:function(){
-        PWM_MAIN.showWaitDialog({loadFunction:function() {
-            var url = PWM_MAIN.addParamToUrl(window.location.href,'processAction','extendSchema');
-            var loadFunction = function(result) {
-                if (result['error']) {
-                    PWM_MAIN.showError(result['errorDetail']);
-                } else {
-                    var output = '<pre>' + result['data'] + '</pre>';
-                    PWM_MAIN.showDialog({title:"Results",text:output,okAction:function(){
-                        window.location.reload();
-                    }});
-                }
-            };
-            PWM_MAIN.ajaxRequest(url,loadFunction);
+            PWM_MAIN.showWaitDialog({loadFunction:function() {
+                    var url = PWM_MAIN.addParamToUrl(window.location.href,'processAction','extendSchema');
+                    var loadFunction = function(result) {
+                        if (result['error']) {
+                            PWM_MAIN.showError(result['errorDetail']);
+                        } else {
+                            var output = '<pre>' + result['data'] + '</pre>';
+                            PWM_MAIN.showDialog({title:"Results",text:output,okAction:function(){
+                                    window.location.reload();
+                                }});
+                        }
+                    };
+                    PWM_MAIN.ajaxRequest(url,loadFunction);
+                }});
         }});
         }});
-    }});
 };
 };
 
 
 PWM_GUIDE.skipGuide = function() {
 PWM_GUIDE.skipGuide = function() {
     PWM_MAIN.preloadAll(function(){
     PWM_MAIN.preloadAll(function(){
         PWM_MAIN.showConfirmDialog({text:PWM_CONFIG.showString('Confirm_SkipGuide'),okAction:function() {
         PWM_MAIN.showConfirmDialog({text:PWM_CONFIG.showString('Confirm_SkipGuide'),okAction:function() {
-            
-            var skipGuideFunction = function(password) {
-                var contents = {};
-                contents['password'] = password;
-                var url = PWM_MAIN.addParamToUrl(window.location.href,'processAction','skipGuide');
-                var loadFunction = function(result) {
-                    if (result['error']) {
-                        PWM_MAIN.showError(result['errorDetail']);
-                    } else {
-                        PWM_MAIN.showWaitDialog({loadFunction:function(){
-                            PWM_CONFIG.waitForRestart();
-                        }});
-                    }
+
+                var skipGuideFunction = function(password) {
+                    var contents = {};
+                    contents['password'] = password;
+                    var url = PWM_MAIN.addParamToUrl(window.location.href,'processAction','skipGuide');
+                    var loadFunction = function(result) {
+                        if (result['error']) {
+                            PWM_MAIN.showError(result['errorDetail']);
+                        } else {
+                            PWM_MAIN.showWaitDialog({loadFunction:function(){
+                                    PWM_CONFIG.waitForRestart();
+                                }});
+                        }
+                    };
+                    PWM_MAIN.ajaxRequest(url,loadFunction,{content:contents});
                 };
                 };
-                PWM_MAIN.ajaxRequest(url,loadFunction,{content:contents});
-            };
 
 
-            var text = 'Set Configuration Password';
-            UILibrary.passwordDialogPopup({minimumLength:8, title:text, writeFunction:skipGuideFunction});
-        }});
+                var text = 'Set Configuration Password';
+                UILibrary.passwordDialogPopup({minimumLength:8, title:text, writeFunction:skipGuideFunction});
+            }});
     });
     });
 };
 };

+ 22 - 6
webapp/src/main/webapp/public/resources/js/main.js

@@ -1375,20 +1375,36 @@ PWM_MAIN.JSLibrary.setValueOfSelectElement = function(nodeID, value) {
     }
     }
 };
 };
 
 
+PWM_MAIN.JSLibrary.readValueOfRadioFormInput = function(name){
+    var value = '';
+    var query = "input[name='" + name + "'"
+    PWM_MAIN.doQuery(query, function(element){
+        if( element.checked ) {
+            value = element.value;
+        }
+    });
+    console.log('radioRead name=' + name + ' value=' + value);
+    return value;
+};
+
 PWM_MAIN.JSLibrary.formToValueMap = function(formElement) {
 PWM_MAIN.JSLibrary.formToValueMap = function(formElement) {
+    formElement = PWM_MAIN.getObject(formElement);
     var returnData = {};
     var returnData = {};
     if ( formElement.elements ) {
     if ( formElement.elements ) {
         var formElements = formElement.elements;
         var formElements = formElement.elements;
         for (var i = 0; i < formElements.length; i++) {
         for (var i = 0; i < formElements.length; i++) {
             var field = formElements[i];
             var field = formElements[i];
             if (field.disabled !== true) {
             if (field.disabled !== true) {
-                if (field.tagName && field.tagName.toLowerCase() === 'input') {
-                    var name = field.name;
-                    var value = field.value;
-                    returnData[name] = value;
+                var name = field.name;
+                var value = field.value;
+                if (field.tagName && field.tagName.toLowerCase() === 'input' && field.type === 'radio' ) {
+                    value = PWM_MAIN.JSLibrary.readValueOfRadioFormInput(name);
                 } else if (field.tagName && field.tagName.toLowerCase() === 'select') {
                 } else if (field.tagName && field.tagName.toLowerCase() === 'select') {
-                    var name = field.name;
-                    var value = PWM_MAIN.JSLibrary.readValueOfSelectElement(field);
+                    value = PWM_MAIN.JSLibrary.readValueOfSelectElement(field);
+                } else if (field.type === "checkbox") {
+                    value = field.checked.toString();
+                }
+                if ( name && value ) {
                     returnData[name] = value;
                     returnData[name] = value;
                 }
                 }
             }
             }