1:
37:
38:
39: package ;
40:
41: import ;
42:
43: import ;
44: import ;
45:
46: import ;
47: import ;
48: import ;
49: import ;
50:
51:
54: public abstract class ClientMechanism
55: implements SaslClient
56: {
57:
58: protected String mechanism;
59:
60: protected String authorizationID;
61:
62: protected String protocol;
63:
64: protected String serverName;
65:
66: protected Map properties;
67:
68: protected CallbackHandler handler;
69:
70: protected byte[] channelBinding;
71:
72: protected boolean complete = false;
73:
74: protected int state = -1;
75:
76: protected ClientMechanism(final String mechanism)
77: {
78: super();
79:
80: this.mechanism = mechanism;
81: this.state = -1;
82: }
83:
84: protected abstract void initMechanism() throws SaslException;
85:
86: protected abstract void resetMechanism() throws SaslException;
87:
88: public abstract byte[] evaluateChallenge(byte[] challenge)
89: throws SaslException;
90:
91: public abstract boolean hasInitialResponse();
92:
93: public boolean isComplete()
94: {
95: return complete;
96: }
97:
98: public byte[] unwrap(final byte[] incoming, final int offset, final int len)
99: throws SaslException
100: {
101: if (! isComplete())
102: throw new IllegalMechanismStateException();
103: return this.engineUnwrap(incoming, offset, len);
104: }
105:
106: public byte[] wrap(final byte[] outgoing, final int offset, final int len)
107: throws SaslException
108: {
109: if (! isComplete())
110: throw new IllegalMechanismStateException();
111: return this.engineWrap(outgoing, offset, len);
112: }
113:
114: public String getMechanismName()
115: {
116: return mechanism;
117: }
118:
119: public Object getNegotiatedProperty(final String propName)
120: {
121: if (! isComplete())
122: throw new IllegalStateException();
123: if (Sasl.QOP.equals(propName))
124: return getNegotiatedQOP();
125: if (Sasl.STRENGTH.equals(propName))
126: return getNegotiatedStrength();
127: if (Sasl.SERVER_AUTH.equals(propName))
128: return getNegotiatedServerAuth();
129: if (Sasl.MAX_BUFFER.equals(propName))
130: return getNegotiatedMaxBuffer();
131: if (Sasl.RAW_SEND_SIZE.equals(propName))
132: return getNegotiatedRawSendSize();
133: if (Sasl.POLICY_NOPLAINTEXT.equals(propName))
134: return getNegotiatedPolicyNoPlainText();
135: if (Sasl.POLICY_NOACTIVE.equals(propName))
136: return getNegotiatedPolicyNoActive();
137: if (Sasl.POLICY_NODICTIONARY.equals(propName))
138: return getNegotiatedPolicyNoDictionary();
139: if (Sasl.POLICY_NOANONYMOUS.equals(propName))
140: return getNegotiatedPolicyNoAnonymous();
141: if (Sasl.POLICY_FORWARD_SECRECY.equals(propName))
142: return getNegotiatedPolicyForwardSecrecy();
143: if (Sasl.POLICY_PASS_CREDENTIALS.equals(propName))
144: return getNegotiatedPolicyPassCredentials();
145: if (Sasl.REUSE.equals(propName))
146: return getReuse();
147: return null;
148: }
149:
150: public void dispose() throws SaslException
151: {
152: }
153:
154: public String getAuthorizationID()
155: {
156: return authorizationID;
157: }
158:
159: protected String getNegotiatedQOP()
160: {
161: return Registry.QOP_AUTH;
162: }
163:
164: protected String getNegotiatedStrength()
165: {
166: return Registry.STRENGTH_LOW;
167: }
168:
169: protected String getNegotiatedServerAuth()
170: {
171: return Registry.SERVER_AUTH_FALSE;
172: }
173:
174: protected String getNegotiatedMaxBuffer()
175: {
176: return null;
177: }
178:
179: protected String getNegotiatedRawSendSize()
180: {
181: return String.valueOf(Registry.SASL_BUFFER_MAX_LIMIT);
182: }
183:
184: protected String getNegotiatedPolicyNoPlainText()
185: {
186: return null;
187: }
188:
189: protected String getNegotiatedPolicyNoActive()
190: {
191: return null;
192: }
193:
194: protected String getNegotiatedPolicyNoDictionary()
195: {
196: return null;
197: }
198:
199: protected String getNegotiatedPolicyNoAnonymous()
200: {
201: return null;
202: }
203:
204: protected String getNegotiatedPolicyForwardSecrecy()
205: {
206: return null;
207: }
208:
209: protected String getNegotiatedPolicyPassCredentials()
210: {
211: return null;
212: }
213:
214: protected String getReuse()
215: {
216: return Registry.REUSE_FALSE;
217: }
218:
219: protected byte[] engineUnwrap(final byte[] incoming, final int offset,
220: final int len) throws SaslException
221: {
222: final byte[] result = new byte[len];
223: System.arraycopy(incoming, offset, result, 0, len);
224: return result;
225: }
226:
227: protected byte[] engineWrap(final byte[] outgoing, final int offset,
228: final int len) throws SaslException
229: {
230: final byte[] result = new byte[len];
231: System.arraycopy(outgoing, offset, result, 0, len);
232: return result;
233: }
234:
235:
245: public void init(final Map attributes) throws SaslException
246: {
247: if (state != -1)
248: throw new IllegalMechanismStateException("init()");
249: if (properties == null)
250: properties = new HashMap();
251: else
252: properties.clear();
253: if (attributes != null)
254: {
255: authorizationID = (String) attributes.get(Registry.SASL_AUTHORISATION_ID);
256: protocol = (String) attributes.get(Registry.SASL_PROTOCOL);
257: serverName = (String) attributes.get(Registry.SASL_SERVER_NAME);
258: handler = (CallbackHandler) attributes.get(Registry.SASL_CALLBACK_HANDLER);
259: channelBinding = (byte[]) attributes.get(Registry.SASL_CHANNEL_BINDING);
260: properties.putAll(attributes);
261: }
262: else
263: handler = null;
264:
265: if (authorizationID == null)
266: authorizationID = "";
267: if (protocol == null)
268: protocol = "";
269: if (serverName == null)
270: serverName = "";
271: if (channelBinding == null)
272: channelBinding = new byte[0];
273: initMechanism();
274: complete = false;
275: state = 0;
276: }
277:
278:
284: public void reset() throws SaslException
285: {
286: resetMechanism();
287: properties.clear();
288: authorizationID = protocol = serverName = null;
289: channelBinding = null;
290: complete = false;
291: state = -1;
292: }
293: }