ソースを参照

sms setting enhancements

Jason Rivard 5 年 前
コミット
657ac25981

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

@@ -381,12 +381,12 @@ public enum PwmSetting
             "sms.gatewayURL", PwmSettingSyntax.STRING, PwmSettingCategory.SMS_GATEWAY ),
     SMS_GATEWAY_CERTIFICATES(
             "sms.gatewayCertificates", PwmSettingSyntax.X509CERT, PwmSettingCategory.SMS_GATEWAY ),
+    SMS_GATEWAY_METHOD(
+            "sms.gatewayMethod", PwmSettingSyntax.SELECT, PwmSettingCategory.SMS_GATEWAY ),
     SMS_GATEWAY_USER(
             "sms.gatewayUser", PwmSettingSyntax.STRING, PwmSettingCategory.SMS_GATEWAY ),
     SMS_GATEWAY_PASSWORD(
             "sms.gatewayPassword", PwmSettingSyntax.PASSWORD, PwmSettingCategory.SMS_GATEWAY ),
-    SMS_GATEWAY_METHOD(
-            "sms.gatewayMethod", PwmSettingSyntax.SELECT, PwmSettingCategory.SMS_GATEWAY ),
     SMS_GATEWAY_AUTHMETHOD(
             "sms.gatewayAuthMethod", PwmSettingSyntax.SELECT, PwmSettingCategory.SMS_GATEWAY ),
     SMS_REQUEST_DATA(

+ 29 - 14
server/src/main/java/password/pwm/util/queue/SmsQueueManager.java

@@ -539,31 +539,21 @@ public class SmsQueueManager implements PwmService
                 final String message
         )
         {
-            final String gatewayUser = config.readSettingAsString( PwmSetting.SMS_GATEWAY_USER );
-            final PasswordData gatewayPass = config.readSettingAsPassword( PwmSetting.SMS_GATEWAY_PASSWORD );
+
             final SmsDataEncoding encoding = config.readSettingAsEnum( PwmSetting.SMS_REQUEST_CONTENT_ENCODING, SmsDataEncoding.class );
 
             String requestData = config.readSettingAsString( PwmSetting.SMS_REQUEST_DATA );
 
+            requestData = applyUserPassTokens( requestData );
+
             // Replace strings in requestData
             {
                 final String senderId = config.readSettingAsString( PwmSetting.SMS_SENDER_ID );
-                requestData = requestData.replace( TOKEN_USER, smsDataEncode( gatewayUser, encoding ) );
                 requestData = requestData.replace( TOKEN_SENDERID, smsDataEncode( senderId, encoding ) );
                 requestData = requestData.replace( TOKEN_MESSAGE, smsDataEncode( message, encoding ) );
                 requestData = requestData.replace( TOKEN_TO, smsDataEncode( formatSmsNumber( config, to ), encoding ) );
             }
 
-            try
-            {
-                final String gatewayStrPass = gatewayPass == null ? null : gatewayPass.getStringValue();
-                requestData = requestData.replace( TOKEN_PASS, smsDataEncode( gatewayStrPass, encoding ) );
-            }
-            catch ( final PwmUnrecoverableException e )
-            {
-                LOGGER.error( "unable to read sms password while reading configuration" );
-            }
-
             if ( requestData.contains( TOKEN_REQUESTID ) )
             {
                 final PwmRandom pwmRandom = pwmApplication.getSecureService().pwmRandom();
@@ -576,6 +566,30 @@ public class SmsQueueManager implements PwmService
             return requestData;
         }
 
+        private String applyUserPassTokens( final String input )
+        {
+            final SmsDataEncoding encoding = config.readSettingAsEnum( PwmSetting.SMS_REQUEST_CONTENT_ENCODING, SmsDataEncoding.class );
+
+            final String gatewayUser = config.readSettingAsString( PwmSetting.SMS_GATEWAY_USER );
+            final PasswordData gatewayPass = config.readSettingAsPassword( PwmSetting.SMS_GATEWAY_PASSWORD );
+
+            String modifiableText = input;
+            modifiableText = modifiableText.replace( TOKEN_USER, smsDataEncode( gatewayUser, encoding ) );
+            modifiableText = modifiableText.replace( TOKEN_USER, smsDataEncode( gatewayUser, encoding ) );
+
+            try
+            {
+                final String gatewayStrPass = gatewayPass == null ? null : gatewayPass.getStringValue();
+                modifiableText = modifiableText.replace( TOKEN_PASS, smsDataEncode( gatewayStrPass, encoding ) );
+            }
+            catch ( final PwmUnrecoverableException e )
+            {
+                LOGGER.error( "unable to read sms password while reading configuration: " + e.getMessage() );
+            }
+
+            return modifiableText;
+        }
+
         private PwmHttpClientRequest makeRequest(
                 final String requestData
         )
@@ -617,7 +631,8 @@ public class SmsQueueManager implements PwmService
                         {
                             final String headerName = matcher.group( 1 );
                             final String headerValue = matcher.group( 2 );
-                            headers.put( headerName, headerValue );
+                            final String tokenizedValue = applyUserPassTokens( headerValue );
+                            headers.put( headerName, tokenizedValue );
                         }
                         else
                         {

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

@@ -980,9 +980,7 @@
         </properties>
     </setting>
     <setting hidden="false" key="sms.responseOkRegex" level="2">
-        <default>
-            <value />
-        </default>
+        <default/>
     </setting>
     <setting hidden="false" key="sms.senderID" level="1">
         <default>

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

@@ -1226,7 +1226,7 @@ Setting_Label_sms.gatewayAuthMethod=SMS Gateway Authentication Method
 Setting_Label_sms.gatewayCertificates=SMS Gateway Certificates
 Setting_Label_sms.gatewayMethod=HTTP(S) Method
 Setting_Label_sms.gatewayPassword=SMS Gateway Password
-Setting_Label_sms.gatewayURL=SMS Gateway
+Setting_Label_sms.gatewayURL=SMS Gateway URL
 Setting_Label_sms.gatewayUser=SMS Gateway User
 Setting_Label_sms.helpdesk.token.message=Help Desk Verification SMS Text
 Setting_Label_sms.httpRequestHeaders=SMS Gateway HTTP Request Headers