001/** 002 * 003 * Copyright 2014 Florian Schmaus 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.provided; 018 019import javax.security.auth.callback.CallbackHandler; 020 021import org.jivesoftware.smack.SmackException; 022import org.jivesoftware.smack.sasl.SASLMechanism; 023import org.jivesoftware.smack.util.ByteUtils; 024 025public class SASLPlainMechanism extends SASLMechanism { 026 027 public static final String NAME = PLAIN; 028 029 @Override 030 protected void authenticateInternal(CallbackHandler cbh) throws SmackException { 031 throw new UnsupportedOperationException("CallbackHandler not (yet) supported"); 032 } 033 034 @Override 035 protected byte[] getAuthenticationText() throws SmackException { 036 // concatenate and encode username (authcid) and password 037 byte[] authcid = toBytes('\u0000' + authenticationId); 038 byte[] passw = toBytes('\u0000' + password); 039 040 return ByteUtils.concact(authcid, passw); 041 } 042 043 @Override 044 public String getName() { 045 return NAME; 046 } 047 048 @Override 049 public int getPriority() { 050 return 410; 051 } 052 053 @Override 054 public SASLPlainMechanism newInstance() { 055 return new SASLPlainMechanism(); 056 } 057 058 @Override 059 public void checkIfSuccessfulOrThrow() throws SmackException { 060 // No check performed 061 } 062}