author | martin |
Tue, 15 Sep 2015 21:56:04 -0700 | |
changeset 32649 | 2ee9017c7597 |
parent 25859 | 3317bb8137f4 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
15276
diff
changeset
|
2 |
* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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 |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
4157
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
2
diff
changeset
|
26 |
package sun.net.www.protocol.http.ntlm; |
2 | 27 |
|
28 |
import java.io.IOException; |
|
15276
bbddb82e66ce
8006568: HTTP protocol handler NLTM Authentication should use Base64 API
msheppar
parents:
14681
diff
changeset
|
29 |
import java.util.Base64; |
2 | 30 |
|
31 |
/* |
|
32 |
* Hooks into Windows implementation of NTLM. |
|
33 |
* This class will be replaced if a cross-platform version of NTLM |
|
34 |
* is implemented in the future. |
|
35 |
*/ |
|
36 |
||
37 |
public class NTLMAuthSequence { |
|
38 |
||
39 |
private String username; |
|
40 |
private String password; |
|
41 |
private String ntdomain; |
|
42 |
private int state; |
|
43 |
private long crdHandle; |
|
44 |
private long ctxHandle; |
|
45 |
||
46 |
static { |
|
14681
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
47 |
initFirst(Status.class); |
2 | 48 |
} |
49 |
||
14681
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
50 |
// Used by native code to indicate when a particular protocol sequence is completed |
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
51 |
// and must not be re-used. |
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
52 |
|
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
53 |
class Status { |
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
54 |
boolean sequenceComplete; |
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
55 |
} |
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
56 |
|
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
57 |
Status status; |
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
58 |
|
2 | 59 |
NTLMAuthSequence (String username, String password, String ntdomain) |
60 |
throws IOException |
|
61 |
{ |
|
62 |
this.username = username; |
|
63 |
this.password = password; |
|
64 |
this.ntdomain = ntdomain; |
|
14681
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
65 |
this.status = new Status(); |
2 | 66 |
state = 0; |
67 |
crdHandle = getCredentialsHandle (username, ntdomain, password); |
|
68 |
if (crdHandle == 0) { |
|
69 |
throw new IOException ("could not get credentials handle"); |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
public String getAuthHeader (String token) throws IOException { |
|
74 |
byte[] input = null; |
|
14681
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
75 |
|
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
76 |
assert !status.sequenceComplete; |
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
77 |
|
2 | 78 |
if (token != null) |
15276
bbddb82e66ce
8006568: HTTP protocol handler NLTM Authentication should use Base64 API
msheppar
parents:
14681
diff
changeset
|
79 |
input = Base64.getDecoder().decode(token); |
14681
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
80 |
byte[] b = getNextToken (crdHandle, input, status); |
2 | 81 |
if (b == null) |
82 |
throw new IOException ("Internal authentication error"); |
|
15276
bbddb82e66ce
8006568: HTTP protocol handler NLTM Authentication should use Base64 API
msheppar
parents:
14681
diff
changeset
|
83 |
return Base64.getEncoder().encodeToString(b); |
2 | 84 |
} |
85 |
||
14681
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
86 |
public boolean isComplete() { |
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
87 |
return status.sequenceComplete; |
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
88 |
} |
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
89 |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
25859
diff
changeset
|
90 |
private static native void initFirst (Class<NTLMAuthSequence.Status> clazz); |
2 | 91 |
|
92 |
private native long getCredentialsHandle (String user, String domain, String password); |
|
93 |
||
14681
523a842a7ac1
7200720: crash in net.dll during NTLM authentication
michaelm
parents:
5506
diff
changeset
|
94 |
private native byte[] getNextToken (long crdHandle, byte[] lastToken, Status returned); |
2 | 95 |
} |
96 |