Authentication.java

  1. /* Copyright 2002-2024 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  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.orekit.gnss.metric.ntrip;

  18. import java.util.HashMap;
  19. import java.util.Map;

  20. import org.orekit.errors.OrekitException;
  21. import org.orekit.errors.OrekitMessages;

  22. /** Enumerate for authentication method in {@link DataStreamRecord}.
  23.  * @author Luc Maisonobe
  24.  * @since 11.0
  25.  */
  26. public enum Authentication {

  27.     /** None. */
  28.     NONE("N"),

  29.     /** Basic. */
  30.     BASIC("B"),

  31.     /** Digest. */
  32.     DIGEST("D");

  33.     /** Keywords map. */
  34.     private static final Map<String, Authentication> KEYWORDS_MAP = new HashMap<String, Authentication>();
  35.     static {
  36.         for (final Authentication type : values()) {
  37.             KEYWORDS_MAP.put(type.getKeyword(), type);
  38.         }
  39.     }

  40.     /** Keyword. */
  41.     private final String keyword;

  42.     /** Simple constructor.
  43.      * @param keyword keyword in the sourcetable records
  44.      */
  45.     Authentication(final String keyword) {
  46.         this.keyword = keyword;
  47.     }

  48.     /** Get keyword.
  49.      * @return keyword
  50.      */
  51.     private String getKeyword() {
  52.         return keyword;
  53.     }

  54.     /** Get the authentication type corresponding to a keyword.
  55.      * @param keyword authentication keyword
  56.      * @return the authentication type corresponding to the keyword
  57.      */
  58.     public static Authentication getAuthentication(final String keyword) {
  59.         final Authentication authentication = KEYWORDS_MAP.get(keyword);
  60.         if (authentication == null) {
  61.             throw new OrekitException(OrekitMessages.UNKNOWN_AUTHENTICATION_METHOD, keyword);
  62.         }
  63.         return authentication;
  64.     }

  65. }