/*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6578647 6829283
* @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 {
// Two realm, web server in one, proxy server in another
// user principals
// web page content
// For 6829283, count how many times the Authenticator is called.
// URLs for web test, proxy test. The proxy server is not a real proxy
// since it fakes the same content for any URL. :)
/**
* This Authenticator checks everything:
* scheme, protocol, requestor type, host, port, and url
*/
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() != proxyPort) {
throw new RuntimeException("Bad port");
}
throw new RuntimeException("Bad url");
}
return new PasswordAuthentication(
} else {
throw new RuntimeException("Bad requster type");
}
}
}
/**
* This Authenticator knows nothing
*/
return null;
}
}
throws Exception {
"default_keytab_name = " + KRB5_TAB,
"[domain_realm]",
"",
".web.domain="+REALM_WEB,
".proxy.domain="+REALM_PROXY);
// Write a customized JAAS conf file, so that any kinit cache
// will be ignored.
"com.sun.security.jgss.krb5.initiate {\n" +
" com.sun.security.auth.module.Krb5LoginModule required;\n};\n"
).getBytes());
f.deleteOnExit();
try {
try {
test6578647();
} catch (Exception e) {
e1 = e;
e.printStackTrace();
}
try {
test6829283();
} catch (Exception e) {
e2 = e;
e.printStackTrace();
}
throw new RuntimeException("Test error");
}
} finally {
// Must stop. Seems there's no HttpServer.startAsDaemon()
}
}
throw new RuntimeException("Bad content");
}
.getInputStream()));
throw new RuntimeException("Bad content");
}
}
try {
new BufferedReader(new InputStreamReader(
} catch (IOException ioe) {
// Will fail since no username and password is provided.
}
if (count > 1) {
throw new RuntimeException("Authenticator called twice");
}
}
/**
* 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;
}
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);
}
}
}
}