pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] jiazhai commented on a change in pull request #3658: kerberos authentication between client and broker
Date Sat, 23 Feb 2019 01:46:37 GMT
jiazhai commented on a change in pull request #3658: kerberos authentication between client
and broker
URL: https://github.com/apache/pulsar/pull/3658#discussion_r259559061
 
 

 ##########
 File path: pulsar-broker-auth-sasl/src/main/java/org/apache/pulsar/broker/authentication/PulsarSaslServer.java
 ##########
 @@ -0,0 +1,198 @@
+/*
+ Licensed to Diennea S.r.l. under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. Diennea S.r.l. licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+ */
+package org.apache.pulsar.broker.authentication;
+
+import java.io.IOException;
+import java.security.Principal;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.regex.Pattern;
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginException;
+import javax.security.sasl.AuthorizeCallback;
+import javax.security.sasl.Sasl;
+import javax.security.sasl.SaslException;
+import javax.security.sasl.SaslServer;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.common.sasl.KerberosName;
+import org.apache.pulsar.common.sasl.SaslConstants;
+
+
+/**
+ * Server side Sasl implementation.
+ */
+@Slf4j
+public class PulsarSaslServer {
+
+    private final SaslServer saslServer;
+    private final Pattern allowedIdsPattern;
+    private final Subject serverSubject;
+    static private final String GSSAPI = "GSSAPI";
+
+    public PulsarSaslServer(Subject subject, Pattern allowedIdsPattern)
+        throws IOException, LoginException {
+        this.serverSubject = subject;
+        this.allowedIdsPattern = allowedIdsPattern;
+        saslServer = createSaslServer(serverSubject);
+    }
+
+    private SaslServer createSaslServer(final Subject subject)
+        throws IOException {
+        SaslServerCallbackHandler callbackHandler = new SaslServerCallbackHandler(allowedIdsPattern);
+        if (subject.getPrincipals().size() > 0) {
+            try {
+                final Object[] principals = subject.getPrincipals().toArray();
+                final Principal servicePrincipal = (Principal) principals[0];
+                if (log.isDebugEnabled()) {
+                    log.debug("Authentication will use SASL/JAAS/Kerberos, servicePrincipal
is {}", servicePrincipal);
+                }
+
+                // e.g. servicePrincipalNameAndHostname := "broker/myhost.foo.com@EXAMPLE.COM"
+                final String servicePrincipalNameAndHostname = servicePrincipal.getName();
+                int indexOf = servicePrincipalNameAndHostname.indexOf("/");
+
+                // e.g. serviceHostnameAndKerbDomain := "myhost.foo.com@EXAMPLE.COM"
+                final String serviceHostnameAndKerbDomain = servicePrincipalNameAndHostname.substring(indexOf
+ 1,
+                    servicePrincipalNameAndHostname.length());
+                int indexOfAt = serviceHostnameAndKerbDomain.indexOf("@");
+
+                // Handle Kerberos Service as well as User Principal Names
+                final String servicePrincipalName, serviceHostname;
+                if (indexOf > 0) {
+                    // e.g. servicePrincipalName := "pulsar"
+                    servicePrincipalName = servicePrincipalNameAndHostname.substring(0, indexOf);
+                    // e.g. serviceHostname := "myhost.foo.com"
+                    serviceHostname = serviceHostnameAndKerbDomain.substring(0, indexOfAt);
+                } else {
+                    servicePrincipalName = servicePrincipalNameAndHostname.substring(0, indexOfAt);
+                    serviceHostname = null;
+                }
+
+                log.info("serviceHostname is '{}', servicePrincipalName is '{}', SASL mechanism(mech)
is '{}'.",
 
 Review comment:
   will change it into debug

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message