Browse Source

mark javascript form option settings as deprecated

Jason Rivard 7 years ago
parent
commit
ee96833a81

+ 64 - 1
server/src/main/java/password/pwm/health/ConfigurationChecker.java

@@ -30,6 +30,7 @@ import password.pwm.bean.SessionLabel;
 import password.pwm.config.Configuration;
 import password.pwm.config.PwmSetting;
 import password.pwm.config.PwmSettingSyntax;
+import password.pwm.config.StoredValue;
 import password.pwm.config.option.DataStorageMethod;
 import password.pwm.config.option.MessageSendMethod;
 import password.pwm.config.profile.ForgottenPasswordProfile;
@@ -37,11 +38,13 @@ import password.pwm.config.profile.HelpdeskProfile;
 import password.pwm.config.profile.LdapProfile;
 import password.pwm.config.profile.NewUserProfile;
 import password.pwm.config.profile.PwmPasswordPolicy;
+import password.pwm.config.value.data.FormConfiguration;
 import password.pwm.error.PwmException;
 import password.pwm.error.PwmUnrecoverableException;
 import password.pwm.i18n.Config;
 import password.pwm.util.LocaleHelper;
 import password.pwm.util.PasswordData;
+import password.pwm.util.java.StringUtil;
 import password.pwm.util.logging.PwmLogger;
 import password.pwm.util.operations.PasswordUtility;
 
@@ -273,7 +276,8 @@ public class ConfigurationChecker implements HealthChecker
             VerifyPasswordPolicyConfigs.class,
             VerifyResponseLdapAttribute.class,
             VerifyDbConfiguredIfNeeded.class,
-            VerifyIfDeprecatedSendMethodValuesUsed.class
+            VerifyIfDeprecatedSendMethodValuesUsed.class,
+            VerifyIfDeprecatedJsFormOptionUsed.class
     ) );
 
     static class VerifyResponseLdapAttribute implements ConfigHealthCheck
@@ -365,6 +369,65 @@ public class ConfigurationChecker implements HealthChecker
         }
     }
 
+    static class VerifyIfDeprecatedJsFormOptionUsed implements ConfigHealthCheck
+    {
+        @Override
+        public List<HealthRecord> healthCheck( final Configuration config, final Locale locale )
+        {
+            final List<HealthRecord> records = new ArrayList<>();
+
+            for ( final PwmSetting loopSetting : PwmSetting.values() )
+            {
+                if ( loopSetting.getSyntax() == PwmSettingSyntax.FORM )
+                {
+                    if ( loopSetting.getCategory().hasProfiles() )
+                    {
+                        try
+                        {
+                            final List<String> profiles = config.getStoredConfiguration().profilesForSetting( loopSetting );
+                            for ( final String profile : profiles )
+                            {
+                                final StoredValue storedValue = config.getStoredConfiguration().readSetting( loopSetting, profile );
+                                final List<FormConfiguration> forms = (List<FormConfiguration>) storedValue.toNativeObject();
+                                for ( final FormConfiguration form : forms )
+                                {
+                                    if ( !StringUtil.isEmpty( form.getJavascript() ) )
+                                    {
+                                        records.add( HealthRecord.forMessage(
+                                                HealthMessage.Config_DeprecatedJSForm,
+                                                loopSetting.toMenuLocationDebug( profile, locale ),
+                                                PwmSetting.DISPLAY_CUSTOM_JAVASCRIPT.toMenuLocationDebug( null, locale )
+                                        ) );
+                                    }
+                                }
+                            }
+                        }
+                        catch ( PwmUnrecoverableException e )
+                        {
+                            LOGGER.error( "unexpected error examining profiles for deprecated form  js option check: " + e.getMessage() );
+                        }
+                    }
+                    else
+                    {
+                        final List<FormConfiguration> forms = config.readSettingAsForm( loopSetting );
+                        for ( final FormConfiguration form : forms )
+                        {
+                            if ( !StringUtil.isEmpty( form.getJavascript() ) )
+                            {
+                                records.add( HealthRecord.forMessage(
+                                        HealthMessage.Config_DeprecatedJSForm,
+                                        loopSetting.toMenuLocationDebug( null, locale ),
+                                        PwmSetting.DISPLAY_CUSTOM_JAVASCRIPT.toMenuLocationDebug( null, locale )
+                                ) );
+                            }
+                        }
+                    }
+                }
+            }
+            return records;
+        }
+    }
+
     static class VerifyIfDeprecatedSendMethodValuesUsed implements ConfigHealthCheck
     {
         @Override

+ 1 - 0
server/src/main/java/password/pwm/health/HealthMessage.java

@@ -69,6 +69,7 @@ public enum HealthMessage
     Config_NoRecoveryEnabled( HealthStatus.CAUTION, HealthTopic.Configuration ),
     Config_Certificate( HealthStatus.WARN, HealthTopic.Configuration ),
     Config_InvalidSendMethod( HealthStatus.CAUTION, HealthTopic.Configuration ),
+    Config_DeprecatedJSForm( HealthStatus.CONFIG, HealthTopic.Configuration ),
     LDAP_VendorsNotSame( HealthStatus.CONFIG, HealthTopic.LDAP ),
     LDAP_OK( HealthStatus.GOOD, HealthTopic.LDAP ),
     LDAP_RecentlyUnreachable( HealthStatus.CAUTION, HealthTopic.LDAP ),

+ 1 - 1
server/src/main/resources/password/pwm/i18n/Config.properties

@@ -161,7 +161,7 @@ Tooltip_FormOptions_LinkLabel=Label to be displayed that tells where the link wi
 Tooltip_FormOptions_LinkURL=Full url that you want to go to when the link is selected.
 Tooltip_Form_ShowInNewWindow=Choose if the link will e opened in a new browser window
 Tooltip_FormOptions_Placeholder=Placeholder text to display in the form field with the field is not populated with a value.
-Tooltip_FormOptions_Javascript=Javascript to be added to the browser.
+Tooltip_FormOptions_Javascript=Javascript to be added to the browser.  This option is depreciated.  Use 'Settings -> User Interface -> Look & Feel -> Embedded JavaScript' instead.
 Tooltip_FormOptions_MultiValue=Display multiple values of the attribute.
 VerificationMethodDetail_PREVIOUS_AUTH=This method is passed when a user has previously authenticated using their browser.  There is no user interaction or display associated with this method.
 VerificationMethodDetail_ATTRIBUTES=User will be prompted for LDAP attribute values defined by the setting @PwmSettingReference:challenge.requiredAttributes@.

+ 1 - 0
server/src/main/resources/password/pwm/i18n/Health.properties

@@ -58,6 +58,7 @@ HealthMessage_Config_UserPermissionValidity=User Permission configuration for se
 HealthMessage_Config_DNValueValidity=LDAP DN configuration setting %1% issue: %2%.  This may cause unexpected issues.
 HealthMessage_Config_Certificate=Certificate for setting %1% issue: %2%
 HealthMessage_Config_InvalidSendMethod=The send method '%1%' is no longer available for setting %2%.  Please modify the configuration to use an alternate value.
+HealthMessage_Config_DeprecatedJSForm=The javascript form option in the form setting %1% has been deprecated and will be removed in a future version.  Use the setting %2% instead.
 HealthMessage_LDAP_VendorsNotSame=LDAP directories of different vendor types are in use.  This configuration may cause undesirable side effects and is not supported.  %1%
 HealthMessage_LDAP_Ad_History_Asn_Missing=%1% is enabled, but the server at %2% does not support this feature.  Check to be sure it is upgraded to Windows Server 2008 R2 SP1 or greater.  Password changes against this server may fail until this is resolved.
 HealthMessage_LDAP_RecentlyUnreachable=LDAP profile %1% was recently unavailable (%2% ago at %3%): %4%

+ 1 - 1
server/src/main/webapp/public/resources/js/configeditor-settings.js

@@ -862,7 +862,7 @@ FormTableHandler.showOptionsDialog = function(keyName, iteration) {
         }
         bodyText += '<td id="' + inputID + '-label-placeholder" class="key" title="' + PWM_CONFIG.showString('Tooltip_FormOptions_Placeholder') + '">Placeholder</td><td><input type="text" class="configStringInput" style="width:300px" id="' + inputID + 'placeholder' + '"/></td>';
         bodyText += '</tr><tr>';
-        bodyText += '<td id="' + inputID + '-label-js" class="key" title="' + PWM_CONFIG.showString('Tooltip_FormOptions_Javascript') + '">JavaScript</td><td><input type="text" class="configStringInput" style="width:300px" id="' + inputID + 'javascript' + '"/></td>';
+        bodyText += '<td id="' + inputID + '-label-js" class="key" title="' + PWM_CONFIG.showString('Tooltip_FormOptions_Javascript') + '">JavaScript (Depreciated)</td><td><input type="text" class="configStringInput" style="width:300px" id="' + inputID + 'javascript' + '"/></td>';
         bodyText += '</tr><tr>';
         if (currentValue['type'] === 'select') {
             bodyText += '<td class="key">Select Options</td><td><button id="' + inputID + 'editOptionsButton"><span class="btn-icon pwm-icon pwm-icon-list-ul"/> Edit</button></td>';