HttpNegotiateServer.java revision 1266
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6578647
* @summary Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
*/
/**
* party uses JAAS login to get subjects and executes JGSS calls using
* Subject.doAs.
*/
public class HttpNegotiateServer implements NameServiceDescriptor {
// Two realm, web server in one, proxy server in another
// user principals
final static int WEB_PORT = 17840;
final static int PROXY_PORT = 17841;
// web page content
// URLs for web test, proxy test. The proxy server is not a real proxy
// since it fakes the same content for any URL. :)
static {
try {
} catch (Exception e) {
}
}
/**
* This Authenticator checks everything:
* scheme, protocol, requestor type, host, port, and url
*/
public PasswordAuthentication getPasswordAuthentication () {
throw new RuntimeException("Bad scheme");
}
throw new RuntimeException("Bad protocol");
}
throw new RuntimeException("Bad host");
}
throw new RuntimeException("Bad port");
}
throw new RuntimeException("Bad url");
}
return new PasswordAuthentication(
throw new RuntimeException("Bad host");
}
if (this.getRequestingPort() != PROXY_PORT) {
throw new RuntimeException("Bad port");
}
throw new RuntimeException("Bad url");
}
return new PasswordAuthentication(
} else {
throw new RuntimeException("Bad requster type");
}
}
}
throws Exception {
"default_keytab_name = " + KRB5_TAB,
"[domain_realm]",
"",
".web.domain="+REALM_WEB,
".proxy.domain="+REALM_PROXY);
try {
throw new RuntimeException("Bad content");
}
.getInputStream()));
throw new RuntimeException("Bad content");
}
} finally {
// Must stop. Seems there's no HttpServer.startAsDaemon()
}
}
/**
* Creates and starts an HTTP or proxy server that requires
* Negotiate authentication.
* @param scheme "Negotiate" or "Kerberos"
* @param principal the krb5 service principal the server runs with
* @return the server
*/
MyHttpHandler h = new MyHttpHandler();
return server;
}
static class MyHttpHandler implements HttpHandler {
t.close();
}
}
static class MyServerAuthenticator
GSSManager m = null;
if (proxy) {
reqHdr = "Proxy-Authenticate";
respHdr = "Proxy-Authorization";
}
m = GSSManager.getInstance();
return m.createCredential(
null,
}
});
}
// The GSContext is stored in an HttpContext attribute named
// "GSSContext" and is created at the first request.
GSSContext c = null;
try {
return m.createContext(cred);
}
});
} else { // Later requests
if (c.isEstablished()) {
} else {
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
throws UnknownHostException {
// Everything is localhost
return new InetAddress[]{
};
}
throws UnknownHostException {
// No reverse lookup
throw new UnknownHostException();
}
};
return ns;
}
public String getProviderName() {
return "mock";
}
return "ns";
}
}