Java Security getDirectiveValue( HashMap directivesMap, String directive, boolean mandatory)

Here you can find the source of getDirectiveValue( HashMap directivesMap, String directive, boolean mandatory)

Description

A directive is a parameter of the digest authentication process.

License

Open Source License

Parameter

Parameter Description
directivesMap the directive's map
directive the name of the directive we want to retrieve
mandatory is the directive mandatory

Exception

Parameter Description
AuthenticationException if mandatory is true and if directivesMap.get(directive) == null

Return

the mandatory value as a String

Declaration

public static String getDirectiveValue(
        HashMap<String, String> directivesMap, String directive,
        boolean mandatory) throws AuthenticationException 

Method Source Code

//package com.java2s;
/**/*from w w w. ja  v  a  2 s  . c  o m*/
 * Copyright 2007-2016, Kaazing Corporation. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.HashMap;

import javax.security.sasl.AuthenticationException;

public class Main {
    /**
     * A directive is a parameter of the digest authentication process.
     * Returns the value of a directive from the map. If mandatory is true and the 
     * value is null, then it throws an {@link AuthenticationException}.
     *  
     * @param directivesMap the directive's map 
     * @param directive the name of the directive we want to retrieve
     * @param mandatory is the directive mandatory
     * @return the mandatory value as a String
     * @throws AuthenticationException if mandatory is true and if 
     * directivesMap.get(directive) == null
     */
    public static String getDirectiveValue(
            HashMap<String, String> directivesMap, String directive,
            boolean mandatory) throws AuthenticationException {
        String value = directivesMap.get(directive);
        if (value == null) {
            if (mandatory) {
                throw new AuthenticationException("\"" + directive
                        + "\" mandatory directive is missing");
            }

            return "";
        }

        return value;
    }
}

Related

  1. credsToTicket(Credentials serviceCreds)
  2. extractDirective(HashMap map, String key, String value)
  3. filterMechs(String[] mechs, int[] policies, Map props)
  4. get(Configuration configuration, String section, String key)
  5. getCommonName(String name)
  6. getEntries(Configuration configuration, String section)
  7. getPublicCredential(Class type, Subject subject)
  8. getRefreshTime(KerberosTicket ticket)
  9. getSaslProps()