Browse Source
Keep delegation token implementation internal without exposing implementation details to pluggable classes: 1. KafkaPrincipal#tokenAuthenticated must always be set by SaslServerAuthenticator so that custom PrincipalBuilders cannot override. 2. Replace o.a.k.c.security.scram.DelegationTokenAuthenticationCallback with a more generic ScramExtensionsCallback that can be used to add more extensions in future. 3. Separate out ScramCredentialCallback (KIP-86 makes this a public interface) from delegation token credential callback (which is internal). Reviewers: Jun Rao <junrao@gmail.com>, Manikumar Reddy <manikumar.reddy@gmail.com>pull/4543/head
Rajini Sivaram
7 years ago
committed by
GitHub
15 changed files with 193 additions and 104 deletions
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF 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.kafka.common.security.scram; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
public class ScramExtensions { |
||||
private final Map<String, String> extensionMap; |
||||
|
||||
public ScramExtensions() { |
||||
this(Collections.<String, String>emptyMap()); |
||||
} |
||||
|
||||
public ScramExtensions(String extensions) { |
||||
this(stringToMap(extensions)); |
||||
} |
||||
|
||||
public ScramExtensions(Map<String, String> extensionMap) { |
||||
this.extensionMap = extensionMap; |
||||
} |
||||
|
||||
public String extensionValue(String name) { |
||||
return extensionMap.get(name); |
||||
} |
||||
|
||||
public Set<String> extensionNames() { |
||||
return extensionMap.keySet(); |
||||
} |
||||
|
||||
public boolean tokenAuthenticated() { |
||||
return Boolean.parseBoolean(extensionMap.get(ScramLoginModule.TOKEN_AUTH_CONFIG)); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return mapToString(extensionMap); |
||||
} |
||||
|
||||
private static Map<String, String> stringToMap(String extensions) { |
||||
Map<String, String> extensionMap = new HashMap<>(); |
||||
|
||||
if (!extensions.isEmpty()) { |
||||
String[] attrvals = extensions.split(","); |
||||
for (String attrval : attrvals) { |
||||
String[] array = attrval.split("=", 2); |
||||
extensionMap.put(array[0], array[1]); |
||||
} |
||||
} |
||||
return extensionMap; |
||||
} |
||||
|
||||
private static String mapToString(Map<String, String> extensionMap) { |
||||
StringBuilder builder = new StringBuilder(); |
||||
for (Map.Entry<String, String> entry : extensionMap.entrySet()) { |
||||
builder.append(entry.getKey()); |
||||
builder.append('='); |
||||
builder.append(entry.getValue()); |
||||
} |
||||
return builder.toString(); |
||||
} |
||||
} |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
/* |
||||
* Licensed to the Apache Software Foundation (ASF) under one or more |
||||
* contributor license agreements. See the NOTICE file distributed with |
||||
* this work for additional information regarding copyright ownership. |
||||
* The ASF 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.kafka.common.security.token.delegation; |
||||
|
||||
import org.apache.kafka.common.security.scram.ScramCredentialCallback; |
||||
|
||||
public class DelegationTokenCredentialCallback extends ScramCredentialCallback { |
||||
private String tokenOwner; |
||||
|
||||
public void tokenOwner(String tokenOwner) { |
||||
this.tokenOwner = tokenOwner; |
||||
} |
||||
|
||||
public String tokenOwner() { |
||||
return tokenOwner; |
||||
} |
||||
} |
Loading…
Reference in new issue