本文整理匯總了Java中javax.security.sasl.SaslException類的典型用法代碼示例。如果您正苦於以下問題:Java SaslException類的具體用法?Java SaslException怎麽用?Java SaslException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SaslException類屬於javax.security.sasl包,在下文中一共展示了SaslException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: saslReadAndProcess
import javax.security.sasl.SaslException; //導入依賴的package包/類
private void saslReadAndProcess(DataInputStream dis) throws
WrappedRpcServerException, IOException, InterruptedException {
final RpcSaslProto saslMessage =
decodeProtobufFromStream(RpcSaslProto.newBuilder(), dis);
switch (saslMessage.getState()) {
case WRAP: {
if (!saslContextEstablished || !useWrap) {
throw new WrappedRpcServerException(
RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
new SaslException("Server is not wrapping data"));
}
// loops over decoded data and calls processOneRpc
unwrapPacketAndProcessRpcs(saslMessage.getToken().toByteArray());
break;
}
default:
saslProcess(saslMessage);
}
}
示例2: saslEvaluateToken
import javax.security.sasl.SaslException; //導入依賴的package包/類
/**
* Evaluate the server provided challenge. The server must send a token
* if it's not done. If the server is done, the challenge token is
* optional because not all mechanisms send a final token for the client to
* update its internal state. The client must also be done after
* evaluating the optional token to ensure a malicious server doesn't
* prematurely end the negotiation with a phony success.
*
* @param saslResponse - client response to challenge
* @param serverIsDone - server negotiation state
* @throws SaslException - any problems with negotiation
*/
private byte[] saslEvaluateToken(RpcSaslProto saslResponse,
boolean serverIsDone) throws SaslException {
byte[] saslToken = null;
if (saslResponse.hasToken()) {
saslToken = saslResponse.getToken().toByteArray();
saslToken = saslClient.evaluateChallenge(saslToken);
} else if (!serverIsDone) {
// the server may only omit a token when it's done
throw new SaslException("Server challenge contains no token");
}
if (serverIsDone) {
// server tried to report success before our client completed
if (!saslClient.isComplete()) {
throw new SaslException("Client is out of sync with server");
}
// a client cannot generate a response to a success message
if (saslToken != null) {
throw new SaslException("Client generated spurious response");
}
}
return saslToken;
}
示例3: buildSaslNegotiateResponse
import javax.security.sasl.SaslException; //導入依賴的package包/類
/**
* Process the Sasl's Negotiate request, including the optimization of
* accelerating token negotiation.
* @return the response to Negotiate request - the list of enabled
* authMethods and challenge if the TOKENS are supported.
* @throws SaslException - if attempt to generate challenge fails.
* @throws IOException - if it fails to create the SASL server for Tokens
*/
private RpcSaslProto buildSaslNegotiateResponse()
throws InterruptedException, SaslException, IOException {
RpcSaslProto negotiateMessage = negotiateResponse;
// accelerate token negotiation by sending initial challenge
// in the negotiation response
if (enabledAuthMethods.contains(AuthMethod.TOKEN)) {
saslServer = createSaslServer(AuthMethod.TOKEN);
byte[] challenge = saslServer.evaluateResponse(new byte[0]);
RpcSaslProto.Builder negotiateBuilder =
RpcSaslProto.newBuilder(negotiateResponse);
negotiateBuilder.getAuthsBuilder(0) // TOKEN is always first
.setChallenge(ByteString.copyFrom(challenge));
negotiateMessage = negotiateBuilder.build();
}
sentNegotiate = true;
return negotiateMessage;
}
示例4: initialize
import javax.security.sasl.SaslException; //導入依賴的package包/類
public void initialize() throws SaslException {
// init quorum auth server & learner
if (isQuorumSaslAuthEnabled()) {
Set<String> authzHosts = new HashSet<String>();
for (QuorumServer qs : getView().values()) {
authzHosts.add(qs.hostname);
}
authServer = new SaslQuorumAuthServer(isQuorumServerSaslAuthRequired(),
quorumServerLoginContext, authzHosts);
authLearner = new SaslQuorumAuthLearner(isQuorumLearnerSaslAuthRequired(),
quorumServicePrincipal, quorumLearnerLoginContext);
authInitialized = true;
} else {
authServer = new NullQuorumAuthServer();
authLearner = new NullQuorumAuthLearner();
}
}
示例5: sendSaslPacket
import javax.security.sasl.SaslException; //導入依賴的package包/類
private void sendSaslPacket(byte[] saslToken, ClientCnxn cnxn)
throws SaslException{
if (LOG.isDebugEnabled()) {
LOG.debug("ClientCnxn:sendSaslPacket:length="+saslToken.length);
}
GetSASLRequest request = new GetSASLRequest();
request.setToken(saslToken);
SetSASLResponse response = new SetSASLResponse();
ServerSaslResponseCallback cb = new ServerSaslResponseCallback();
try {
cnxn.sendPacket(request,response,cb, ZooDefs.OpCode.sasl);
} catch (IOException e) {
throw new SaslException("Failed to send SASL packet to server.",
e);
}
}
示例6: createSaslClient
import javax.security.sasl.SaslException; //導入依賴的package包/類
@Override
public SaslClient createSaslClient(String[] mechanisms,
String authorizationId,
String protocol,
String serverName,
Map<String, ?> props,
CallbackHandler cbh) throws SaslException {
ScramMechanism mechanism = null;
for (String mech : mechanisms) {
mechanism = ScramMechanism.forMechanismName(mech);
if (mechanism != null)
break;
}
if (mechanism == null)
throw new SaslException(String.format("Requested mechanisms '%s' not supported. Supported mechanisms are '%s'.",
Arrays.asList(mechanisms), ScramMechanism.mechanismNames()));
try {
return new ScramSaslClient(mechanism, cbh);
} catch (NoSuchAlgorithmException e) {
throw new SaslException("Hash algorithm not supported for mechanism " + mechanism, e);
}
}
示例7: processConnection
import javax.security.sasl.SaslException; //導入依賴的package包/類
private void processConnection(SaslEndpoint endpoint)
throws SaslException, IOException, ClassNotFoundException {
System.out.println("process connection");
endpoint.send(SUPPORT_MECHS);
Object o = endpoint.receive();
if (!(o instanceof String)) {
throw new RuntimeException("Received unexpected object: " + o);
}
String mech = (String) o;
SaslServer saslServer = createSaslServer(mech);
Message msg = getMessage(endpoint.receive());
while (!saslServer.isComplete()) {
byte[] data = processData(msg.getData(), endpoint,
saslServer);
if (saslServer.isComplete()) {
System.out.println("server is complete");
endpoint.send(new Message(SaslStatus.SUCCESS, data));
} else {
System.out.println("server continues");
endpoint.send(new Message(SaslStatus.CONTINUE, data));
msg = getMessage(endpoint.receive());
}
}
}
示例8: SaslQuorumAuthServer
import javax.security.sasl.SaslException; //導入依賴的package包/類
public SaslQuorumAuthServer(boolean quorumRequireSasl, String loginContext, Set<String> authzHosts)
throws SaslException {
this.quorumRequireSasl = quorumRequireSasl;
try {
AppConfigurationEntry entries[] = Configuration.getConfiguration()
.getAppConfigurationEntry(loginContext);
if (entries == null || entries.length == 0) {
throw new LoginException("SASL-authentication failed"
+ " because the specified JAAS configuration "
+ "section '" + loginContext + "' could not be found.");
}
SaslQuorumServerCallbackHandler saslServerCallbackHandler = new SaslQuorumServerCallbackHandler(
Configuration.getConfiguration(), loginContext, authzHosts);
serverLogin = new Login(loginContext, saslServerCallbackHandler);
serverLogin.startThreadIfNeeded();
} catch (Throwable e) {
throw new SaslException(
"Failed to initialize authentication mechanism using SASL",
e);
}
}
示例9: SaslInputStream
import javax.security.sasl.SaslException; //導入依賴的package包/類
SaslInputStream(SaslClient sc, InputStream in) throws SaslException {
super();
this.in = in;
this.sc = sc;
String str = (String) sc.getNegotiatedProperty(Sasl.MAX_BUFFER);
if (str != null) {
try {
recvMaxBufSize = Integer.parseInt(str);
} catch (NumberFormatException e) {
throw new SaslException(Sasl.MAX_BUFFER +
" property must be numeric string: " + str);
}
}
saslBuffer = new byte[recvMaxBufSize];
}
示例10: testSaslQuorumAuthServerWithInvalidQuorumAuthPacket
import javax.security.sasl.SaslException; //導入依賴的package包/類
/**
* SaslQuorumAuthServer throws exception on receiving an invalid quorum
* auth packet.
*/
@Test(timeout = 30000)
public void testSaslQuorumAuthServerWithInvalidQuorumAuthPacket()
throws Exception {
Socket socket = getSocketPair();
DataOutputStream dout = new DataOutputStream(socket.getOutputStream());
BufferedOutputStream bufferedOutput = new BufferedOutputStream(dout);
BinaryOutputArchive boa = BinaryOutputArchive
.getArchive(bufferedOutput);
QuorumAuthPacket authPacket = QuorumAuth
.createPacket(QuorumAuth.Status.IN_PROGRESS, null);
authPacket.setMagic(Long.MAX_VALUE); // invalid magic number
boa.writeRecord(authPacket, null);
bufferedOutput.flush();
QuorumAuthServer authServer = new SaslQuorumAuthServer(true,
"QuorumServer", authzHosts);
BufferedInputStream is = new BufferedInputStream(
socket.getInputStream());
try {
authServer.authenticate(socket, new DataInputStream(is));
Assert.fail("Must throw exception as QuorumAuthPacket is invalid");
} catch (SaslException e) {
// expected
}
}
示例11: initialize
import javax.security.sasl.SaslException; //導入依賴的package包/類
public void initialize(ClientCnxn cnxn) throws SaslException {
if (saslClient == null) {
saslState = SaslState.FAILED;
throw new SaslException("saslClient failed to initialize properly: it's null.");
}
if (saslState == SaslState.INITIAL) {
if (saslClient.hasInitialResponse()) {
sendSaslPacket(cnxn);
}
else {
byte[] emptyToken = new byte[0];
sendSaslPacket(emptyToken, cnxn);
}
saslState = SaslState.INTERMEDIATE;
}
}
示例12: SampleServer
import javax.security.sasl.SaslException; //導入依賴的package包/類
public SampleServer(String supportedQOPs) throws SaslException {
Map<String,String> properties = new HashMap<String,String>();
if (supportedQOPs != null) {
properties.put(Sasl.QOP, supportedQOPs);
}
saslServer = Sasl.createSaslServer(DIGEST_MD5, "local", "127.0.0.1",
properties, new SampleCallbackHandler());
}
示例13: dispose
import javax.security.sasl.SaslException; //導入依賴的package包/類
/** Release resources used by wrapped saslClient */
public void dispose() throws SaslException {
if (saslClient != null) {
saslClient.dispose();
saslClient = null;
}
}
示例14: disposeSasl
import javax.security.sasl.SaslException; //導入依賴的package包/類
/**
* Disposes of any system resources or security-sensitive information Sasl
* might be using.
*
* @exception SaslException
* if a SASL error occurs.
*/
private void disposeSasl() throws SaslException {
if (saslClient != null) {
saslClient.dispose();
}
if (saslServer != null) {
saslServer.dispose();
}
}
示例15: write
import javax.security.sasl.SaslException; //導入依賴的package包/類
/**
* Writes <code>len</code> bytes from the specified byte array starting at
* offset <code>off</code> to this output stream.
*
* @param inBuf
* the data.
* @param off
* the start offset in the data.
* @param len
* the number of bytes to write.
* @exception IOException
* if an I/O error occurs.
*/
@Override
public void write(byte[] inBuf, int off, int len) throws IOException {
if (!useWrap) {
outStream.write(inBuf, off, len);
return;
}
try {
if (saslServer != null) { // using saslServer
saslToken = saslServer.wrap(inBuf, off, len);
} else { // using saslClient
saslToken = saslClient.wrap(inBuf, off, len);
}
} catch (SaslException se) {
try {
disposeSasl();
} catch (SaslException ignored) {
}
throw se;
}
if (saslToken != null) {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
DataOutputStream dout = new DataOutputStream(byteOut);
dout.writeInt(saslToken.length);
outStream.write(byteOut.toByteArray());
outStream.write(saslToken, 0, saslToken.length);
saslToken = null;
}
}