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; 018 019import java.util.logging.Level; 020import java.util.logging.Logger; 021 022public enum SASLError { 023 024 aborted, 025 account_disabled, 026 credentials_expired, 027 encryption_required, 028 incorrect_encoding, 029 invalid_authzid, 030 invalid_mechanism, 031 malformed_request, 032 mechanism_too_weak, 033 not_authorized, 034 temporary_auth_failure; 035 036 private static final Logger LOGGER = Logger.getLogger(SASLError.class.getName()); 037 @Override 038 public String toString() { 039 return this.name().replace('_', '-'); 040 } 041 042 public static SASLError fromString(String string) { 043 string = string.replace('-', '_'); 044 SASLError saslError = null; 045 try { 046 saslError = SASLError.valueOf(string); 047 } catch (Exception e) { 048 LOGGER.log(Level.WARNING, "Could not transform string '" + string + "' to SASLError", e); 049 } 050 return saslError; 051 } 052}