Here you can find the source of createBasicAuthenticationProperty(final String username, final String password)
Parameter | Description |
---|---|
username | a parameter |
password | a parameter |
public static Map<String, String> createBasicAuthenticationProperty(final String username, final String password)
//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; } }