equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
25 |
25 |
26 package com.sun.security.sasl; |
26 package com.sun.security.sasl; |
27 |
27 |
28 import javax.security.sasl.*; |
28 import javax.security.sasl.*; |
29 |
29 |
|
30 import static java.nio.charset.StandardCharsets.UTF_8; |
|
31 |
30 /** |
32 /** |
31 * Implements the EXTERNAL SASL client mechanism. |
33 * Implements the EXTERNAL SASL client mechanism. |
32 * (<A HREF="http://www.ietf.org/rfc/rfc2222.txt">RFC 2222</A>). |
34 * (<A HREF="http://www.ietf.org/rfc/rfc2222.txt">RFC 2222</A>). |
33 * The EXTERNAL mechanism returns the optional authorization ID as |
35 * The EXTERNAL mechanism returns the optional authorization ID as |
34 * the initial response. It processes no challenges. |
36 * the initial response. It processes no challenges. |
41 |
43 |
42 /** |
44 /** |
43 * Constructs an External mechanism with optional authorization ID. |
45 * Constructs an External mechanism with optional authorization ID. |
44 * |
46 * |
45 * @param authorizationID If non-null, used to specify authorization ID. |
47 * @param authorizationID If non-null, used to specify authorization ID. |
46 * @throws SaslException if cannot convert authorizationID into UTF-8 |
|
47 * representation. |
|
48 */ |
48 */ |
49 ExternalClient(String authorizationID) throws SaslException { |
49 ExternalClient(String authorizationID) { |
50 if (authorizationID != null) { |
50 if (authorizationID != null) { |
51 try { |
51 username = authorizationID.getBytes(UTF_8); |
52 username = authorizationID.getBytes("UTF8"); |
|
53 } catch (java.io.UnsupportedEncodingException e) { |
|
54 throw new SaslException("Cannot convert " + authorizationID + |
|
55 " into UTF-8", e); |
|
56 } |
|
57 } else { |
52 } else { |
58 username = new byte[0]; |
53 username = new byte[0]; |
59 } |
54 } |
60 } |
55 } |
61 |
56 |
86 * This is the optional information that is sent along with the SASL command. |
81 * This is the optional information that is sent along with the SASL command. |
87 * After this method is called, isComplete() returns true. |
82 * After this method is called, isComplete() returns true. |
88 * |
83 * |
89 * @param challengeData Ignored. |
84 * @param challengeData Ignored. |
90 * @return The possible empty initial response. |
85 * @return The possible empty initial response. |
91 * @throws SaslException If authentication has already been called. |
86 * @throws IllegalStateException If authentication has already been called. |
92 */ |
87 */ |
93 public byte[] evaluateChallenge(byte[] challengeData) |
88 public byte[] evaluateChallenge(byte[] challengeData) { |
94 throws SaslException { |
|
95 if (completed) { |
89 if (completed) { |
96 throw new IllegalStateException( |
90 throw new IllegalStateException( |
97 "EXTERNAL authentication already completed"); |
91 "EXTERNAL authentication already completed"); |
98 } |
92 } |
99 completed = true; |
93 completed = true; |