/* * Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * 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.
*/
staticvoid checkVersions() throws Exception { // Server accepts all version
checkVersion(null, null);
checkVersion("LM/NTLM", null);
checkVersion("LM", null);
checkVersion("NTLM", null);
checkVersion("NTLM2", null);
checkVersion("LMv2/NTLMv2", null);
checkVersion("LMv2", null);
checkVersion("NTLMv2", null);
// Client's default version is LMv2
checkVersion(null, "LMv2");
// Also works if they specified identical versions
checkVersion("LM/NTLM", "LM");
checkVersion("LM", "LM");
checkVersion("NTLM", "LM");
checkVersion("NTLM2", "NTLM2");
checkVersion("LMv2/NTLMv2", "LMv2");
checkVersion("LMv2", "LMv2");
checkVersion("NTLMv2", "LMv2");
// But should not work if different try {
checkVersion("LM/NTLM", "LMv2"); thrownew Exception("Should not succeed");
} catch (SaslException se) { // OK
} try {
checkVersion("LMv2/NTLMv2", "LM"); thrownew Exception("Should not succeed");
} catch (SaslException se) { // OK
}
}
/** * A test on version matching * @param vc ntlm version specified for client * @param vs ntlm version specified for server * @throws Exception
*/ privatestaticvoid checkVersion(String vc, String vs) throws Exception {
Map<String,Object> pc = new HashMap<>();
pc.put("com.sun.security.sasl.ntlm.version", vc);
Map<String,Object> ps = new HashMap<>();
ps.put("com.sun.security.sasl.ntlm.version", vs);
SaslClient clnt = Sasl.createSaslClient( new String[]{MECH}, USER1, PROTOCOL, REALM, pc, new CallbackHandler() { publicvoid handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback cb: callbacks) { if (cb instanceof PasswordCallback) {
((PasswordCallback)cb).setPassword(PASS1);
}
}
}
});
handshake(clnt, srv); if (!"this.is.com".equals(
srv.getNegotiatedProperty("com.sun.security.sasl.ntlm.hostname"))) { thrownew Exception("Hostname not trasmitted to server");
}
}
/** * Client realm override, but finally overridden by server response
*/ privatestaticvoid checkClientDomainOverride() throws Exception {
SaslClient clnt = Sasl.createSaslClient( new String[]{MECH}, USER1, PROTOCOL, "ANOTHERREALM", null, new CallbackHandler() { publicvoid handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback cb: callbacks) { if (cb instanceof RealmCallback) {
((RealmCallback)cb).setText(REALM);
} elseif (cb instanceof PasswordCallback) {
((PasswordCallback)cb).setPassword(PASS1);
}
}
}
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.