Java XML Data Type Converter createBasicAuthenticationProperty(final String username, final String password)

Here you can find the source of createBasicAuthenticationProperty(final String username, final String password)

Description

Create HTTP Basic credentials to be used in HTTP get or post methods.

License

Apache License

Parameter

Parameter Description
username a parameter
password a parameter

Return

Map containing

Declaration

public static Map<String, String> createBasicAuthenticationProperty(final String username,
        final String password) 

Method Source Code

//package com.java2s;
/**/*  ww  w  .j  a v  a  2  s .  co m*/
 *  Copyright 2013 Sven Ewald
 *
 *  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.io.UnsupportedEncodingException;

import java.util.Map;

import java.util.TreeMap;
import javax.xml.bind.DatatypeConverter;

public class Main {
    /**
     * Create HTTP Basic credentials to be used in HTTP get or post methods.
     *
     * @param username
     * @param password
     * @return Map containing
     */
    public static Map<String, String> createBasicAuthenticationProperty(final String username,
            final String password) {
        Map<String, String> map = new TreeMap<String, String>();
        try {
            String base64Binary = DatatypeConverter
                    .printBase64Binary((username + ":" + password).getBytes("US-ASCII"));
            map.put("Authorization", "Basic " + base64Binary);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
        return map;
    }
}

Related

  1. compress(String string)
  2. convertBpmnVariableValueToXslParam(final Object bpmnVariableValue)
  3. convertToFourBytes(int numberToConvert)
  4. convertToPEM(PublicKey key)
  5. convertToTwoBytes(int numberToConvert)
  6. decode(final CharSequence _text)
  7. decode(String auth)
  8. decode(String source)
  9. decode(String string, boolean decode)