Java Doc for SaslClient.java in  » 6.0-JDK-Core » security » javax » security » sasl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » security » javax.security.sasl 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


javax.security.sasl.SaslClient

SaslClient
abstract public interface SaslClient (Code)
Performs SASL authentication as a client.

A protocol library such as one for LDAP gets an instance of this class in order to perform authentication defined by a specific SASL mechanism. Invoking methods on the SaslClient instance process challenges and create responses according to the SASL mechanism implemented by the SaslClient. As the authentication proceeds, the instance encapsulates the state of a SASL client's authentication exchange.

Here's an example of how an LDAP library might use a SaslClient. It first gets an instance of a SaslClient:

 SaslClient sc = Sasl.createSaslClient(mechanisms,
 authorizationId, protocol, serverName, props, callbackHandler);
 
It can then proceed to use the client for authentication. For example, an LDAP library might use the client as follows:
 // Get initial response and send to server
 byte[] response = (sc.hasInitialResponse() ? sc.evaluateChallenge(new byte[0]) :
 null);
 LdapResult res = ldap.sendBindRequest(dn, sc.getName(), response);
 while (!sc.isComplete() && 
 (res.status == SASL_BIND_IN_PROGRESS || res.status == SUCCESS)) {
 response = sc.evaluateChallenge(res.getBytes());
 if (res.status == SUCCESS) {
 // we're done; don't expect to send another BIND
 if (response != null) {
 throw new SaslException(
 "Protocol error: attempting to send response after completion");
 }
 break;
 }
 res = ldap.sendBindRequest(dn, sc.getName(), response);
 }
 if (sc.isComplete() && res.status == SUCCESS) {
 String qop = (String) sc.getNegotiatedProperty(Sasl.QOP);
 if (qop != null 
 && (qop.equalsIgnoreCase("auth-int") 
 || qop.equalsIgnoreCase("auth-conf"))) {
 // Use SaslClient.wrap() and SaslClient.unwrap() for future
 // communication with server
 ldap.in = new SecureInputStream(sc, ldap.in);
 ldap.out = new SecureOutputStream(sc, ldap.out);
 }
 }
 
If the mechanism has an initial response, the library invokes evaluateChallenge() with an empty challenge and to get initial response. Protocols such as IMAP4, which do not include an initial response with their first authentication command to the server, initiates the authentication without first calling hasInitialResponse() or evaluateChallenge(). When the server responds to the command, it sends an initial challenge. For a SASL mechanism in which the client sends data first, the server should have issued a challenge with no data. This will then result in a call (on the client) to evaluateChallenge() with an empty challenge.
since:
   1.5
See Also:   Sasl
See Also:   SaslClientFactory
author:
   Rosanna Lee
author:
   Rob Weltman




Method Summary
abstract public  voiddispose()
     Disposes of any system resources or security-sensitive information the SaslClient might be using.
abstract public  byte[]evaluateChallenge(byte[] challenge)
     Evaluates the challenge data and generates a response. If a challenge is received from the server during the authentication process, this method is called to prepare an appropriate next response to submit to the server.
Parameters:
  challenge - The non-null challenge sent from the server.The challenge array may have zero length.
abstract public  StringgetMechanismName()
     Returns the IANA-registered mechanism name of this SASL client. (e.g.
abstract public  ObjectgetNegotiatedProperty(String propName)
     Retrieves the negotiated property. This method can be called only after the authentication exchange has completed (i.e., when isComplete() returns true); otherwise, an IllegalStateException is thrown.
Parameters:
  propName - The non-null property name.
abstract public  booleanhasInitialResponse()
     Determines whether this mechanism has an optional initial response.
abstract public  booleanisComplete()
     Determines whether the authentication exchange has completed. This method may be called at any time, but typically, it will not be called until the caller has received indication from the server (in a protocol-specific manner) that the exchange has completed.
abstract public  byte[]unwrap(byte[] incoming, int offset, int len)
     Unwraps a byte array received from the server. This method can be called only after the authentication exchange has completed (i.e., when isComplete() returns true) and only if the authentication exchange has negotiated integrity and/or privacy as the quality of protection; otherwise, an IllegalStateException is thrown.

incoming is the contents of the SASL buffer as defined in RFC 2222 without the leading four octet field that represents the length. offset and len specify the portion of incoming to use.
Parameters:
  incoming - A non-null byte array containing the encoded bytesfrom the server.
Parameters:
  offset - The starting position at incoming of the bytes to use.
Parameters:
  len - The number of bytes from incoming to use.

abstract public  byte[]wrap(byte[] outgoing, int offset, int len)
     Wraps a byte array to be sent to the server. This method can be called only after the authentication exchange has completed (i.e., when isComplete() returns true) and only if the authentication exchange has negotiated integrity and/or privacy as the quality of protection; otherwise, an IllegalStateException is thrown.

The result of this method will make up the contents of the SASL buffer as defined in RFC 2222 without the leading four octet field that represents the length. offset and len specify the portion of outgoing to use.
Parameters:
  outgoing - A non-null byte array containing the bytes to encode.
Parameters:
  offset - The starting position at outgoing of the bytes to use.
Parameters:
  len - The number of bytes from outgoing to use.




Method Detail
dispose
abstract public void dispose() throws SaslException(Code)
Disposes of any system resources or security-sensitive information the SaslClient might be using. Invoking this method invalidates the SaslClient instance. This method is idempotent.
throws:
  SaslException - If a problem was encountered while disposingthe resources.



evaluateChallenge
abstract public byte[] evaluateChallenge(byte[] challenge) throws SaslException(Code)
Evaluates the challenge data and generates a response. If a challenge is received from the server during the authentication process, this method is called to prepare an appropriate next response to submit to the server.
Parameters:
  challenge - The non-null challenge sent from the server.The challenge array may have zero length. The possibly null reponse to send to the server.It is null if the challenge accompanied a "SUCCESS" status and the challengeonly contains data for the client to update its state and no responseneeds to be sent to the server. The response is a zero-length byte array if the client is to send a response with no data.
exception:
  SaslException - If an error occurred while processingthe challenge or generating a response.



getMechanismName
abstract public String getMechanismName()(Code)
Returns the IANA-registered mechanism name of this SASL client. (e.g. "CRAM-MD5", "GSSAPI"). A non-null string representing the IANA-registered mechanism name.



getNegotiatedProperty
abstract public Object getNegotiatedProperty(String propName)(Code)
Retrieves the negotiated property. This method can be called only after the authentication exchange has completed (i.e., when isComplete() returns true); otherwise, an IllegalStateException is thrown.
Parameters:
  propName - The non-null property name. The value of the negotiated property. If null, the property wasnot negotiated or is not applicable to this mechanism.
exception:
  IllegalStateException - if this authentication exchange has not completed



hasInitialResponse
abstract public boolean hasInitialResponse()(Code)
Determines whether this mechanism has an optional initial response. If true, caller should call evaluateChallenge() with an empty array to get the initial response. true if this mechanism has an initial response.



isComplete
abstract public boolean isComplete()(Code)
Determines whether the authentication exchange has completed. This method may be called at any time, but typically, it will not be called until the caller has received indication from the server (in a protocol-specific manner) that the exchange has completed. true if the authentication exchange has completed; false otherwise.



unwrap
abstract public byte[] unwrap(byte[] incoming, int offset, int len) throws SaslException(Code)
Unwraps a byte array received from the server. This method can be called only after the authentication exchange has completed (i.e., when isComplete() returns true) and only if the authentication exchange has negotiated integrity and/or privacy as the quality of protection; otherwise, an IllegalStateException is thrown.

incoming is the contents of the SASL buffer as defined in RFC 2222 without the leading four octet field that represents the length. offset and len specify the portion of incoming to use.
Parameters:
  incoming - A non-null byte array containing the encoded bytesfrom the server.
Parameters:
  offset - The starting position at incoming of the bytes to use.
Parameters:
  len - The number of bytes from incoming to use. A non-null byte array containing the decoded bytes.
exception:
  SaslException - if incoming cannot be successfully unwrapped.
exception:
  IllegalStateException - if the authentication exchange has not completed, or if the negotiated quality of protection has neither integrity nor privacy.




wrap
abstract public byte[] wrap(byte[] outgoing, int offset, int len) throws SaslException(Code)
Wraps a byte array to be sent to the server. This method can be called only after the authentication exchange has completed (i.e., when isComplete() returns true) and only if the authentication exchange has negotiated integrity and/or privacy as the quality of protection; otherwise, an IllegalStateException is thrown.

The result of this method will make up the contents of the SASL buffer as defined in RFC 2222 without the leading four octet field that represents the length. offset and len specify the portion of outgoing to use.
Parameters:
  outgoing - A non-null byte array containing the bytes to encode.
Parameters:
  offset - The starting position at outgoing of the bytes to use.
Parameters:
  len - The number of bytes from outgoing to use. A non-null byte array containing the encoded bytes.
exception:
  SaslException - if outgoing cannot be successfully wrapped.
exception:
  IllegalStateException - if the authentication exchange has not completed, or if the negotiated quality of protection has neither integrity nor privacy.




www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.