001/**
002 *
003 * Copyright the original author or authors
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smack.sasl;
018
019import org.jivesoftware.smack.SASLAuthentication;
020import org.jivesoftware.smack.SmackException.NotConnectedException;
021
022import java.io.IOException;
023
024import javax.security.auth.callback.CallbackHandler;
025
026/**
027 * Implementation of the SASL ANONYMOUS mechanism
028 *
029 * @author Jay Kline
030 */
031public class SASLAnonymous extends SASLMechanism {
032
033    public SASLAnonymous(SASLAuthentication saslAuthentication) {
034        super(saslAuthentication);
035    }
036
037    protected String getName() {
038        return "ANONYMOUS";
039    }
040
041    public void authenticate(String username, String host, CallbackHandler cbh) throws IOException, NotConnectedException {
042        authenticate();
043    }
044
045    public void authenticate(String username, String host, String password) throws IOException, NotConnectedException {
046        authenticate();
047    }
048
049    protected void authenticate() throws IOException, NotConnectedException {
050        // Send the authentication to the server
051        getSASLAuthentication().send(new AuthMechanism(getName(), null));
052    }
053
054    public void challengeReceived(String challenge) throws IOException, NotConnectedException {
055        // Build the challenge response stanza encoding the response text
056        // and send the authentication to the server
057        getSASLAuthentication().send(new Response());
058    }
059
060
061}