/* * Copyright (c) 2003, 2021, 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.
*/
publicstaticvoid main(String[] args) throws Exception { if (args.length == 0) {
namesfile = null;
auto = true;
} else { int i = 0; if (args[i].equals("-m")) {
i++;
auto = false;
} if (args.length > i) {
namesfile = args[i++]; if (args.length > i) {
proxyfile = args[i];
}
} else {
namesfile = null;
}
}
CallbackHandler clntCbh = null; final CallbackHandler srvCbh = new PropertiesFileCallbackHandler( null, namesfile, proxyfile);
Subject clntSubj = doLogin("client");
Subject srvSubj = doLogin("server"); final HashMap clntprops = new HashMap(); final HashMap srvprops = new HashMap();
final SaslClient clnt = (SaslClient)
Subject.callAs(clntSubj, new Callable<>() { public Object call() throws Exception { return Sasl.createSaslClient( new String[]{MECH}, null, PROTOCOL, SERVER_FQDN,
clntprops, null);
}
});
if (verbose) {
System.out.println(clntSubj);
System.out.println(srvSubj);
} final SaslServer srv = (SaslServer)
Subject.callAs(srvSubj, new Callable<Object>() { public Object call() throws Exception { return Sasl.createSaslServer(MECH, PROTOCOL, SERVER_FQDN,
srvprops, srvCbh);
}
});
if (clnt == null) { thrownew IllegalStateException( "Unable to find client impl for " + MECH);
} if (srv == null) { thrownew IllegalStateException( "Unable to find server impl for " + MECH);
}
if (clnt.isComplete() && srv.isComplete()) { if (verbose) {
System.out.println("SUCCESS");
System.out.println("authzid is " + srv.getAuthorizationID());
}
} else { thrownew IllegalStateException("FAILURE: mismatched state:" + " client complete? " + clnt.isComplete() + " server complete? " + srv.isComplete());
}
}
privatestatic Subject doLogin(String msg) throws LoginException {
LoginContext lc = null; if (verbose) {
System.out.println(msg);
} try {
lc = new LoginContext(msg, new TextCallbackHandler());
// Attempt authentication // You might want to do this in a "for" loop to give // user more than one chance to enter correct username/password
lc.login();
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.