1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
604 }
605 //}
606 }
607
608 private void initAuthUserInfo(HttpURLConnection conn, String userInfo) {
609 String user;
610 String password;
611 if (userInfo != null) { // get the user and password
612 //System.out.println("UserInfo= " + userInfo );
613 int delimiter = userInfo.indexOf(':');
614 if (delimiter == -1) {
615 user = ParseUtil.decode(userInfo);
616 password = null;
617 } else {
618 user = ParseUtil.decode(userInfo.substring(0, delimiter++));
619 password = ParseUtil.decode(userInfo.substring(delimiter));
620 }
621
622 String plain = user + ":";
623 byte[] nameBytes = plain.getBytes();
624 byte[] passwdBytes = password.getBytes();
625
626 // concatenate user name and password bytes and encode them
627 byte[] concat = new byte[nameBytes.length + passwdBytes.length];
628
629 System.arraycopy(nameBytes, 0, concat, 0, nameBytes.length);
630 System.arraycopy(
631 passwdBytes,
632 0,
633 concat,
634 nameBytes.length,
635 passwdBytes.length);
636 String auth = "Basic " + new String(Base64.encode(concat));
637 conn.setRequestProperty("Authorization", auth);
638 if (dL > 0)
639 d("Adding auth " + auth);
640 }
641 }
642
643 private static final int dL = 0;
644 private void d(String s) {
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
604 }
605 //}
606 }
607
608 private void initAuthUserInfo(HttpURLConnection conn, String userInfo) {
609 String user;
610 String password;
611 if (userInfo != null) { // get the user and password
612 //System.out.println("UserInfo= " + userInfo );
613 int delimiter = userInfo.indexOf(':');
614 if (delimiter == -1) {
615 user = ParseUtil.decode(userInfo);
616 password = null;
617 } else {
618 user = ParseUtil.decode(userInfo.substring(0, delimiter++));
619 password = ParseUtil.decode(userInfo.substring(delimiter));
620 }
621
622 String plain = user + ":";
623 byte[] nameBytes = plain.getBytes();
624 byte[] passwdBytes = (password == null ? new byte[0] : password
625 .getBytes());
626
627 // concatenate user name and password bytes and encode them
628 byte[] concat = new byte[nameBytes.length + passwdBytes.length];
629
630 System.arraycopy(nameBytes, 0, concat, 0, nameBytes.length);
631 System.arraycopy(
632 passwdBytes,
633 0,
634 concat,
635 nameBytes.length,
636 passwdBytes.length);
637 String auth = "Basic " + new String(Base64.encode(concat));
638 conn.setRequestProperty("Authorization", auth);
639 if (dL > 0)
640 d("Adding auth " + auth);
641 }
642 }
643
644 private static final int dL = 0;
645 private void d(String s) {
|