Debian Codegraph @

proton-j/src/main/java/org/apache/qpid/proton/engine/Sasl.java

raw
1 package org.apache.qpid.proton.engine;
2 /*
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 *
21 */
22
23
24 public interface Sasl
25 {
26 public enum SaslState
27 {
28 /** Pending configuration by application */
29 PN_SASL_CONF,
30 /** Pending SASL Init */
31 PN_SASL_IDLE,
32 /** negotiation in progress */
33 PN_SASL_STEP,
34 /** negotiation completed successfully */
35 PN_SASL_PASS,
36 /** negotiation failed */
37 PN_SASL_FAIL
38 }
39
40 public enum SaslOutcome
41 {
42 /** negotiation not completed */
43 PN_SASL_NONE((byte)-1),
44 /** authentication succeeded */
45 PN_SASL_OK((byte)0),
46 /** failed due to bad credentials */
47 PN_SASL_AUTH((byte)1),
48 /** failed due to a system error */
49 PN_SASL_SYS((byte)2),
50 /** failed due to unrecoverable error */
51 PN_SASL_PERM((byte)3),
52 PN_SASL_TEMP((byte)4),
53 PN_SASL_SKIPPED((byte)5);
54
55 private final byte _code;
56
57 /** failed due to transient error */
58
59 SaslOutcome(byte code)
60 {
61 _code = code;
62 }
63
64 public byte getCode()
65 {
66 return _code;
67 }
68 }
69
70 public static SaslOutcome PN_SASL_NONE = SaslOutcome.PN_SASL_NONE;
71 public static SaslOutcome PN_SASL_OK = SaslOutcome.PN_SASL_OK;
72 public static SaslOutcome PN_SASL_AUTH = SaslOutcome.PN_SASL_AUTH;
73 public static SaslOutcome PN_SASL_SYS = SaslOutcome.PN_SASL_SYS;
74 public static SaslOutcome PN_SASL_PERM = SaslOutcome.PN_SASL_PERM;
75 public static SaslOutcome PN_SASL_TEMP = SaslOutcome.PN_SASL_TEMP;
76 public static SaslOutcome PN_SASL_SKIPPED = SaslOutcome.PN_SASL_SKIPPED;
77
78 /**
79 * Access the current state of the layer.
80 *
81 * @return The state of the sasl layer.
82 */
83 SaslState getState();
84
85 /**
86 * Set the acceptable SASL mechanisms for the layer.
87 *
88 * @param mechanisms a list of acceptable SASL mechanisms
89 */
90 void setMechanisms(String... mechanisms);
91
92 /**
93 * Retrieve the list of SASL mechanisms provided by the remote.
94 *
95 * @return the SASL mechanisms advertised by the remote
96 */
97 String[] getRemoteMechanisms();
98
99 /**
100 * Set the remote hostname to indicate the host being connected to when
101 * sending a SaslInit to the server.
102 */
103 void setRemoteHostname(String hostname);
104
105 /**
106 * Retrieve the hostname indicated by the client when sending its SaslInit.
107 *
108 * @return the hostname indicated by the remote client, or null if none specified.
109 */
110 String getHostname();
111
112 /**
113 * Determine the size of the bytes available via recv().
114 *
115 * Returns the size in bytes available via recv().
116 *
117 * @return The number of bytes available, zero if no available data.
118 */
119 int pending();
120
121 /**
122 * Read challenge/response/additional data sent from the peer.
123 *
124 * Use pending to determine the size of the data.
125 *
126 * @param bytes written with up to size bytes of inbound data.
127 * @param offset the offset in the array to begin writing at
128 * @param size maximum number of bytes that bytes can accept.
129 * @return The number of bytes written to bytes, or an error code if {@literal < 0}.
130 */
131 int recv(byte[] bytes, int offset, int size);
132
133 /**
134 * Send challenge/response/additional data to the peer.
135 *
136 * @param bytes The challenge/response data.
137 * @param offset the point within the array at which the data starts at
138 * @param size The number of data octets in bytes.
139 * @return The number of octets read from bytes, or an error code if {@literal < 0}
140 */
141 int send(byte[] bytes, int offset, int size);
142
143
144 /**
145 * Set the outcome of SASL negotiation
146 *
147 * Used by the server to set the result of the negotiation process.
148 *
149 * @param outcome the outcome of the SASL negotiation
150 */
151 void done(SaslOutcome outcome);
152
153
154 /**
155 * Configure the SASL layer to use the "PLAIN" mechanism.
156 *
157 * A utility function to configure a simple client SASL layer using
158 * PLAIN authentication.
159 *
160 * @param username credential for the PLAIN authentication
161 * mechanism
162 * @param password credential for the PLAIN authentication
163 * mechanism
164 */
165 void plain(String username, String password);
166
167 /**
168 * Retrieve the outcome of SASL negotiation.
169 */
170 SaslOutcome getOutcome();
171
172 void client();
173 void server();
174
175 /**
176 * Set whether servers may accept incoming connections
177 * that skip the SASL layer negotiation.
178 */
179 void allowSkip(boolean allowSkip);
180
181 /**
182 * Adds a listener to receive notice of frames having arrived.
183 */
184 void setListener(SaslListener saslListener);
185 }