Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.security.sasl/share/classes/com/sun/security/sasl/ExternalClient.java
41161 views
1
/*
2
* Copyright (c) 1999, 2020, 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
23
* questions.
24
*/
25
26
package com.sun.security.sasl;
27
28
import javax.security.sasl.*;
29
30
import static java.nio.charset.StandardCharsets.UTF_8;
31
32
/**
33
* Implements the EXTERNAL SASL client mechanism.
34
* (<A HREF="http://www.ietf.org/rfc/rfc2222.txt">RFC 2222</A>).
35
* The EXTERNAL mechanism returns the optional authorization ID as
36
* the initial response. It processes no challenges.
37
*
38
* @author Rosanna Lee
39
*/
40
final class ExternalClient implements SaslClient {
41
private byte[] username;
42
private boolean completed = false;
43
44
/**
45
* Constructs an External mechanism with optional authorization ID.
46
*
47
* @param authorizationID If non-null, used to specify authorization ID.
48
*/
49
ExternalClient(String authorizationID) {
50
if (authorizationID != null) {
51
username = authorizationID.getBytes(UTF_8);
52
} else {
53
username = new byte[0];
54
}
55
}
56
57
/**
58
* Retrieves this mechanism's name for initiating the "EXTERNAL" protocol
59
* exchange.
60
*
61
* @return The string "EXTERNAL".
62
*/
63
public String getMechanismName() {
64
return "EXTERNAL";
65
}
66
67
/**
68
* This mechanism has an initial response.
69
*/
70
public boolean hasInitialResponse() {
71
return true;
72
}
73
74
public void dispose() throws SaslException {
75
}
76
77
/**
78
* Processes the challenge data.
79
* It returns the EXTERNAL mechanism's initial response,
80
* which is the authorization id encoded in UTF-8.
81
* This is the optional information that is sent along with the SASL command.
82
* After this method is called, isComplete() returns true.
83
*
84
* @param challengeData Ignored.
85
* @return The possible empty initial response.
86
* @throws IllegalStateException If authentication has already been called.
87
*/
88
public byte[] evaluateChallenge(byte[] challengeData) {
89
if (completed) {
90
throw new IllegalStateException(
91
"EXTERNAL authentication already completed");
92
}
93
completed = true;
94
return username;
95
}
96
97
/**
98
* Returns whether this mechanism is complete.
99
* @return true if initial response has been sent; false otherwise.
100
*/
101
public boolean isComplete() {
102
return completed;
103
}
104
105
/**
106
* Unwraps the incoming buffer.
107
*
108
* @throws SaslException Not applicable to this mechanism.
109
*/
110
public byte[] unwrap(byte[] incoming, int offset, int len)
111
throws SaslException {
112
if (completed) {
113
throw new SaslException("EXTERNAL has no supported QOP");
114
} else {
115
throw new IllegalStateException(
116
"EXTERNAL authentication Not completed");
117
}
118
}
119
120
/**
121
* Wraps the outgoing buffer.
122
*
123
* @throws SaslException Not applicable to this mechanism.
124
*/
125
public byte[] wrap(byte[] outgoing, int offset, int len)
126
throws SaslException {
127
if (completed) {
128
throw new SaslException("EXTERNAL has no supported QOP");
129
} else {
130
throw new IllegalStateException(
131
"EXTERNAL authentication not completed");
132
}
133
}
134
135
/**
136
* Retrieves the negotiated property.
137
* This method can be called only after the authentication exchange has
138
* completed (i.e., when {@code isComplete()} returns true);
139
* otherwise, an {@code IllegalStateException} is thrown.
140
*
141
* @return null No property is applicable to this mechanism.
142
* @exception IllegalStateException if this authentication exchange
143
* has not completed
144
*/
145
public Object getNegotiatedProperty(String propName) {
146
if (completed) {
147
return null;
148
} else {
149
throw new IllegalStateException(
150
"EXTERNAL authentication not completed");
151
}
152
}
153
}
154
155