SASLAnonymous.java

  1. /**
  2.  *
  3.  * Copyright the original author or authors
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smack.sasl.core;

  18. import javax.security.auth.callback.CallbackHandler;

  19. import org.jivesoftware.smack.sasl.SASLMechanism;

  20. /**
  21.  * Implementation of the SASL ANONYMOUS mechanism.
  22.  *
  23.  * @author Jay Kline
  24.  */
  25. public class SASLAnonymous extends SASLMechanism {

  26.     public static final String NAME = "ANONYMOUS";

  27.     @Override
  28.     public String getName() {
  29.         return NAME;
  30.     }

  31.     @Override
  32.     public int getPriority() {
  33.         return 500;
  34.     }

  35.     @Override
  36.     protected void authenticateInternal(CallbackHandler cbh) {
  37.         // Nothing to do here
  38.     }

  39.     @Override
  40.     protected byte[] getAuthenticationText() {
  41.         // ANONYMOUS has no initial response, return null
  42.         return null;
  43.     }

  44.     @Override
  45.     public SASLAnonymous newInstance() {
  46.         return new SASLAnonymous();
  47.     }

  48.     @Override
  49.     public void checkIfSuccessfulOrThrow() {
  50.         // SASL Anonymous is always successful :)
  51.     }

  52.     @Override
  53.     public boolean requiresPassword() {
  54.         return false;
  55.     }
  56. }