Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions extensions-core/druid-kerberos/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@
</dependency>

<!-- Tests -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.druid</groupId>
<artifactId>druid-processing</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.eclipse.jetty.client.Request;
import org.eclipse.jetty.http.HttpCookie;

import javax.annotation.Nullable;
import javax.security.auth.Subject;
import javax.security.auth.kerberos.KerberosPrincipal;
import javax.security.auth.login.AppConfigurationEntry;
Expand Down Expand Up @@ -188,11 +189,15 @@ protected AuthenticationToken getToken(HttpServletRequest request) throws Authen
for (Cookie cookie : cookies) {
if (cookie.getName().equals(AuthenticatedURL.AUTH_COOKIE)) {
tokenStr = cookie.getValue();
try {
tokenStr = mySigner.verifyAndExtract(tokenStr);
}
catch (SignerException ex) {
throw new AuthenticationException(ex);
if (tokenStr == null || tokenStr.isEmpty()) {
tokenStr = null;
} else {
try {
tokenStr = mySigner.verifyAndExtract(tokenStr);
}
catch (SignerException ex) {
throw new AuthenticationException(ex);
}
}
break;
}
Expand Down Expand Up @@ -266,7 +271,7 @@ private void doFilterSuper(ServletRequest request, ServletResponse response, Fil
}
token = getAuthenticationHandler().authenticate(httpRequest, httpResponse);
if (token != null && token.getExpires() != 0 &&
token != AuthenticationToken.ANONYMOUS) {
!AuthenticationToken.ANONYMOUS.equals(token)) {
token.setExpires(System.currentTimeMillis() + getValidity() * 1000);
}
newToken = true;
Expand All @@ -293,12 +298,13 @@ public String getRemoteUser()
}

@Override
@Nullable
public Principal getUserPrincipal()
{
return (authToken != AuthenticationToken.ANONYMOUS) ? authToken : null;
return (!AuthenticationToken.ANONYMOUS.equals(authToken)) ? authToken : null;
}
};
if (newToken && !token.isExpired() && token != AuthenticationToken.ANONYMOUS) {
if (newToken && !token.isExpired() && !AuthenticationToken.ANONYMOUS.equals(token)) {
String signedToken = mySigner.sign(token.toString());
tokenToAuthCookie(
httpResponse,
Expand Down Expand Up @@ -374,6 +380,7 @@ public Principal getUserPrincipal()
}

@Override
@Nullable
public Class<? extends Filter> getFilterClass()
{
return null;
Expand All @@ -398,6 +405,7 @@ public String getPath()
}

@Override
@Nullable
public EnumSet<DispatcherType> getDispatcherType()
{
return null;
Expand All @@ -423,9 +431,8 @@ public void decorateProxyRequest(
)
{
Object cookieToken = clientRequest.getAttribute(SIGNED_TOKEN_ATTRIBUTE);
if (cookieToken != null && cookieToken instanceof String) {
if (cookieToken instanceof String authResult) {
log.debug("Found cookie token will attache it to proxyRequest as cookie");
String authResult = (String) cookieToken;
proxyRequest.cookie(HttpCookie.from(SIGNED_TOKEN_ATTRIBUTE, authResult));
}
}
Expand All @@ -435,8 +442,8 @@ public void decorateProxyRequest(
*/
public static class DruidKerberosConfiguration extends Configuration
{
private String keytab;
private String principal;
private final String keytab;
private final String principal;

public DruidKerberosConfiguration(String keytab, String principal)
{
Expand Down Expand Up @@ -497,11 +504,11 @@ private void initializeKerberosLogin() throws ServletException
String keytab;

try {
if (serverPrincipal == null || serverPrincipal.trim().length() == 0) {
if (serverPrincipal == null || serverPrincipal.trim().isEmpty()) {
throw new ServletException("Principal not defined in configuration");
}
keytab = serverKeytab;
if (keytab == null || keytab.trim().length() == 0) {
if (keytab == null || keytab.trim().isEmpty()) {
throw new ServletException("Keytab not defined in configuration");
}
if (!new File(keytab).exists()) {
Expand Down Expand Up @@ -568,7 +575,7 @@ private static String tokenToCookieString(
{
StringBuilder sb = new StringBuilder(AuthenticatedURL.AUTH_COOKIE)
.append("=");
if (token != null && token.length() > 0) {
if (token != null && !token.isEmpty()) {
sb.append("\"").append(token).append("\"");
}

Expand All @@ -580,7 +587,9 @@ private static String tokenToCookieString(
sb.append("; Domain=").append(domain);
}

if (expires >= 0 && isCookiePersistent) {
if (expires == 0) {
sb.append("; Max-Age=0");
} else if (expires > 0 && isCookiePersistent) {
Date date = new Date(expires);
SimpleDateFormat df = new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss zzz", Locale.ENGLISH);
df.setTimeZone(TimeZone.getTimeZone("GMT"));
Expand Down
Loading
Loading