Back to home page

OSCL-LXR

 
 

    


0001 /**
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements.  See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership.  The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License.  You may obtain a copy of the License at
0009  *
0010  *     http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing, software
0013  * distributed under the License is distributed on an "AS IS" BASIS,
0014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015  * See the License for the specific language governing permissions and
0016  * limitations under the License.
0017  */
0018 
0019 package org.apache.hive.service.auth;
0020 
0021 import java.util.HashMap;
0022 import java.util.Locale;
0023 import java.util.Map;
0024 
0025 /**
0026  * Possible values of SASL quality-of-protection value.
0027  */
0028 public enum SaslQOP {
0029   // Authentication only.
0030   AUTH("auth"),
0031   // Authentication and integrity checking by using signatures.
0032   AUTH_INT("auth-int"),
0033   // Authentication, integrity and confidentiality checking by using signatures and encryption.
0034   AUTH_CONF("auth-conf");
0035 
0036   public final String saslQop;
0037 
0038   private static final Map<String, SaslQOP> STR_TO_ENUM = new HashMap<String, SaslQOP>();
0039 
0040   static {
0041     for (SaslQOP saslQop : values()) {
0042       STR_TO_ENUM.put(saslQop.toString(), saslQop);
0043     }
0044   }
0045 
0046   SaslQOP(String saslQop) {
0047     this.saslQop = saslQop;
0048   }
0049 
0050   public String toString() {
0051     return saslQop;
0052   }
0053 
0054   public static SaslQOP fromString(String str) {
0055     if (str != null) {
0056       str = str.toLowerCase(Locale.ROOT);
0057     }
0058     SaslQOP saslQOP = STR_TO_ENUM.get(str);
0059     if (saslQOP == null) {
0060       throw new IllegalArgumentException(
0061         "Unknown auth type: " + str + " Allowed values are: " + STR_TO_ENUM.keySet());
0062     }
0063     return saslQOP;
0064   }
0065 }