codelipenghui commented on code in PR #16526:
URL: https://github.com/apache/pulsar/pull/16526#discussion_r919639074


##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderBasic.java:
##########
@@ -48,14 +51,28 @@ public void close() throws IOException {
 
     @Override
     public void initialize(ServiceConfiguration config) throws IOException {
-        File confFile = new File(System.getProperty(CONF_SYSTEM_PROPERTY_KEY));
-        if (!confFile.exists()) {
-            throw new IOException("The password auth conf file does not 
exist");
-        } else if (!confFile.isFile()) {
-            throw new IOException("The path is not a file");
+        String data = 
config.getProperties().getProperty(CONF_PULSAR_PROPERTY_KEY);
+        if (StringUtils.isEmpty(data)) {
+            data = System.getProperty(CONF_SYSTEM_PROPERTY_KEY);
+        }
+        if (StringUtils.isEmpty(data)) {
+            throw new IOException("No basic authentication config provided");
+        }
+
+        @Cleanup BufferedReader reader = null;
+        if (org.apache.commons.codec.binary.Base64.isBase64(data)) {
+            reader = new BufferedReader(new StringReader(new 
String(Base64.getDecoder().decode(data),
+                    StandardCharsets.UTF_8)));
+        } else {

Review Comment:
   I think we can use 2 different config/property names instead of checking 
isBase64, the isBase64(path) maybe return true?



##########
conf/broker.conf:
##########
@@ -751,6 +751,13 @@ athenzDomainNames=
 # When this parameter is not empty, unauthenticated users perform as 
anonymousUserRole
 anonymousUserRole=
 
+## Configure the datasource of basic authenticate, supports the file and 
Base64 format.
+# file:
+# basicAuthConf=/path/my/.htpasswd
+# use Base64 to encode the contents of .htpasswd:
+# basicAuthConf=YOUR-BASE64-DATA
+basicAuthConf=

Review Comment:
   ```suggestion
   basicAuthInBase64=
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to