0N/A/*
2362N/A * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.security.sasl.digest;
0N/A
0N/Aimport java.util.Map;
0N/A
0N/Aimport javax.security.sasl.*;
0N/Aimport javax.security.auth.callback.CallbackHandler;
0N/A
0N/Aimport com.sun.security.sasl.util.PolicyUtils;
0N/A
0N/A
0N/A/**
0N/A * Client and server factory for DIGEST-MD5 SASL client/server mechanisms.
0N/A * See DigestMD5Client and DigestMD5Server for input requirements.
0N/A *
0N/A * @author Jonathan Bruce
0N/A * @author Rosanna Lee
0N/A */
0N/A
0N/Apublic final class FactoryImpl implements SaslClientFactory,
0N/ASaslServerFactory{
0N/A
0N/A private static final String myMechs[] = { "DIGEST-MD5" };
0N/A private static final int DIGEST_MD5 = 0;
0N/A private static final int mechPolicies[] = {
0N/A PolicyUtils.NOPLAINTEXT|PolicyUtils.NOANONYMOUS};
0N/A
0N/A /**
0N/A * Empty constructor.
0N/A */
0N/A public FactoryImpl() {
0N/A }
0N/A
0N/A /**
0N/A * Returns a new instance of the DIGEST-MD5 SASL client mechanism.
0N/A *
0N/A * @throws SaslException If there is an error creating the DigestMD5
0N/A * SASL client.
0N/A * @returns a new SaslClient ; otherwise null if unsuccessful.
0N/A */
0N/A public SaslClient createSaslClient(String[] mechs,
0N/A String authorizationId, String protocol, String serverName,
0N/A Map<String,?> props, CallbackHandler cbh)
0N/A throws SaslException {
0N/A
0N/A for (int i=0; i<mechs.length; i++) {
0N/A if (mechs[i].equals(myMechs[DIGEST_MD5]) &&
0N/A PolicyUtils.checkPolicy(mechPolicies[DIGEST_MD5], props)) {
0N/A
0N/A if (cbh == null) {
0N/A throw new SaslException(
0N/A "Callback handler with support for RealmChoiceCallback, " +
0N/A "RealmCallback, NameCallback, and PasswordCallback " +
0N/A "required");
0N/A }
0N/A
0N/A return new DigestMD5Client(authorizationId,
0N/A protocol, serverName, props, cbh);
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns a new instance of the DIGEST-MD5 SASL server mechanism.
0N/A *
0N/A * @throws SaslException If there is an error creating the DigestMD5
0N/A * SASL server.
0N/A * @returns a new SaslServer ; otherwise null if unsuccessful.
0N/A */
0N/A public SaslServer createSaslServer(String mech,
0N/A String protocol, String serverName, Map<String,?> props, CallbackHandler cbh)
0N/A throws SaslException {
0N/A
0N/A if (mech.equals(myMechs[DIGEST_MD5]) &&
0N/A PolicyUtils.checkPolicy(mechPolicies[DIGEST_MD5], props)) {
0N/A
0N/A if (cbh == null) {
0N/A throw new SaslException(
0N/A "Callback handler with support for AuthorizeCallback, "+
0N/A "RealmCallback, NameCallback, and PasswordCallback " +
0N/A "required");
0N/A }
0N/A
0N/A return new DigestMD5Server(protocol, serverName, props, cbh);
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the authentication mechanisms that this factory can produce.
0N/A *
0N/A * @returns String[] {"DigestMD5"} if policies in env match those of this
0N/A * factory.
0N/A */
0N/A public String[] getMechanismNames(Map<String,?> env) {
0N/A return PolicyUtils.filterMechs(myMechs, mechPolicies, env);
0N/A }
0N/A}