001/**
002 *
003 * Copyright 2014-2016 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;
018
019import java.util.logging.Level;
020import java.util.logging.Logger;
021
022/**
023 * The SASL error condition.
024 *
025 * @see <a href="https://tools.ietf.org/html/rfc6120#section-6.5">RFC 6120 ยง 6.5, SASL Errors</a>
026 */
027public enum SASLError {
028
029    aborted,
030    account_disabled,
031    credentials_expired,
032    encryption_required,
033    incorrect_encoding,
034    invalid_authzid,
035    invalid_mechanism,
036    malformed_request,
037    mechanism_too_weak,
038    not_authorized,
039    temporary_auth_failure;
040
041    private static final Logger LOGGER = Logger.getLogger(SASLError.class.getName());
042    @Override
043    public String toString() {
044        return this.name().replace('_', '-');
045    }
046
047    public static SASLError fromString(String string) {
048        string = string.replace('-', '_');
049        SASLError saslError = null;
050        try {
051            saslError = SASLError.valueOf(string);
052        } catch (Exception e) {
053            LOGGER.log(Level.WARNING, "Could not transform string '" + string + "' to SASLError", e);
054        }
055        return saslError;
056    }
057}