|
@@ -19,6 +19,8 @@ import org.ietf.jgss.GSSContext;
|
|
import org.ietf.jgss.GSSManager;
|
|
import org.ietf.jgss.GSSManager;
|
|
import org.ietf.jgss.GSSName;
|
|
import org.ietf.jgss.GSSName;
|
|
import org.ietf.jgss.Oid;
|
|
import org.ietf.jgss.Oid;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import javax.security.auth.Subject;
|
|
import javax.security.auth.Subject;
|
|
import javax.security.auth.login.AppConfigurationEntry;
|
|
import javax.security.auth.login.AppConfigurationEntry;
|
|
@@ -44,6 +46,9 @@ import java.util.Map;
|
|
* sequence.
|
|
* sequence.
|
|
*/
|
|
*/
|
|
public class KerberosAuthenticator implements Authenticator {
|
|
public class KerberosAuthenticator implements Authenticator {
|
|
|
|
+
|
|
|
|
+ private static Logger LOG = LoggerFactory.getLogger(
|
|
|
|
+ KerberosAuthenticator.class);
|
|
|
|
|
|
/**
|
|
/**
|
|
* HTTP header used by the SPNEGO server endpoint during an authentication sequence.
|
|
* HTTP header used by the SPNEGO server endpoint during an authentication sequence.
|
|
@@ -152,9 +157,18 @@ public class KerberosAuthenticator implements Authenticator {
|
|
}
|
|
}
|
|
conn.setRequestMethod(AUTH_HTTP_METHOD);
|
|
conn.setRequestMethod(AUTH_HTTP_METHOD);
|
|
conn.connect();
|
|
conn.connect();
|
|
- if (isNegotiate()) {
|
|
|
|
|
|
+
|
|
|
|
+ if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
|
|
|
+ LOG.debug("JDK performed authentication on our behalf.");
|
|
|
|
+ // If the JDK already did the SPNEGO back-and-forth for
|
|
|
|
+ // us, just pull out the token.
|
|
|
|
+ AuthenticatedURL.extractToken(conn, token);
|
|
|
|
+ return;
|
|
|
|
+ } else if (isNegotiate()) {
|
|
|
|
+ LOG.debug("Performing our own SPNEGO sequence.");
|
|
doSpnegoSequence(token);
|
|
doSpnegoSequence(token);
|
|
} else {
|
|
} else {
|
|
|
|
+ LOG.debug("Using fallback authenticator sequence.");
|
|
getFallBackAuthenticator().authenticate(url, token);
|
|
getFallBackAuthenticator().authenticate(url, token);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -168,7 +182,11 @@ public class KerberosAuthenticator implements Authenticator {
|
|
* @return the fallback {@link Authenticator}.
|
|
* @return the fallback {@link Authenticator}.
|
|
*/
|
|
*/
|
|
protected Authenticator getFallBackAuthenticator() {
|
|
protected Authenticator getFallBackAuthenticator() {
|
|
- return new PseudoAuthenticator();
|
|
|
|
|
|
+ Authenticator auth = new PseudoAuthenticator();
|
|
|
|
+ if (connConfigurator != null) {
|
|
|
|
+ auth.setConnectionConfigurator(connConfigurator);
|
|
|
|
+ }
|
|
|
|
+ return auth;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -197,11 +215,16 @@ public class KerberosAuthenticator implements Authenticator {
|
|
AccessControlContext context = AccessController.getContext();
|
|
AccessControlContext context = AccessController.getContext();
|
|
Subject subject = Subject.getSubject(context);
|
|
Subject subject = Subject.getSubject(context);
|
|
if (subject == null) {
|
|
if (subject == null) {
|
|
|
|
+ LOG.debug("No subject in context, logging in");
|
|
subject = new Subject();
|
|
subject = new Subject();
|
|
LoginContext login = new LoginContext("", subject,
|
|
LoginContext login = new LoginContext("", subject,
|
|
null, new KerberosConfiguration());
|
|
null, new KerberosConfiguration());
|
|
login.login();
|
|
login.login();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (LOG.isDebugEnabled()) {
|
|
|
|
+ LOG.debug("Using subject: " + subject);
|
|
|
|
+ }
|
|
Subject.doAs(subject, new PrivilegedExceptionAction<Void>() {
|
|
Subject.doAs(subject, new PrivilegedExceptionAction<Void>() {
|
|
|
|
|
|
@Override
|
|
@Override
|