Package javax.security.sasl

Examples of javax.security.sasl.SaslException


    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;
  }
View Full Code Here


          token = saslClient.unwrap(token, 0, token.length);
          unwrappedRpcBuffer = ByteBuffer.wrap(token);
        }
      }
      if (!isWrapped) {
        throw new SaslException("Server sent non-wrapped response");
      }
    }
View Full Code Here

      ByteBuffer frame = readFrame();
      switch (status) {
      case COMPLETE:
        break;
      case FAIL:
        throw new SaslException("Fail: "+toString(frame));
      default:
        throw new IOException("Unexpected SASL status: "+status);
      }
    }
    return super.transceive(request);
View Full Code Here

      case START:
        String mechanism = toString(frame);
        frame = readFrame();
        if (!mechanism.equalsIgnoreCase(sasl.getMechanismName())) {
          write(Status.FAIL, "Wrong mechanism: "+mechanism);
          throw new SaslException("Wrong mechanism: "+mechanism);
        }
      case CONTINUE:
        byte[] response;
        try {
          response = sasl.evaluate(frame.array());
          status = sasl.isComplete() ? Status.COMPLETE : Status.CONTINUE;
        } catch (SaslException e) {
          response = e.toString().getBytes("UTF-8");
          status = Status.FAIL;
        }
        write(status, response!=null ? ByteBuffer.wrap(response) : EMPTY);
        break;
      case COMPLETE:
        sasl.evaluate(frame.array());
        if (!sasl.isComplete())
          throw new SaslException("Expected completion!");
        break;
      case FAIL:
        throw new SaslException("Fail: "+toString(frame));
      default:
        throw new IOException("Unexpected SASL status: "+status);
      }
    }
    LOG.debug("SASL opened");
View Full Code Here

    public boolean hasInitialResponse() { return true; }
    public byte[] evaluateChallenge(byte[] challenge) throws SaslException {
      try {
        return System.getProperty("user.name").getBytes("UTF-8");
      } catch (IOException e) {
        throw new SaslException(e.toString());
      }
    }
View Full Code Here

    return true;
  }

  public byte[] evaluateChallenge(byte[] challenge) throws SaslException {
    if (challenge.length > 0) {
      throw new SaslException("Unexpected server challenge");
    }

    NameCallback nameCallback = new NameCallback("Enter name");
    Callback[] callbacks = new Callback[] { nameCallback };
    try {
      callbackHandler.handle(callbacks);
    } catch (UnsupportedCallbackException e) {
      throw new SaslException("Unsupported callback: " + e);
    } catch (IOException e) {
      throw new SaslException("Failed to execute callback: " + e);
    }
    String email = nameCallback.getName();

    XoauthSaslResponseBuilder responseBuilder = new XoauthSaslResponseBuilder();
    Exception caughtException = null;
    try {
      byte[] rv = responseBuilder.buildResponse(email,
                                                protocol,
                                                oauthToken,
                                                oauthTokenSecret,
                                                consumer);
      isComplete = true;
      return rv;
    } catch (IOException e) {
      caughtException = e;
    } catch (OAuthException e) {
      caughtException = e;
    } catch (URISyntaxException e) {
      caughtException = e;
    }
    throw new SaslException("Threw an exception building XOAUTH string: " +
                            caughtException);
  }
View Full Code Here

        public byte[] evaluateResponse(byte[] response) throws SaslException
        {
            if (_throwSaslException)
            {
                throw new SaslException("Mocked exception");
            }
            return null;
        }
View Full Code Here

     */

    public SaslServer createSaslServer(String mechanism, String protocol, String serverName, Map<String, ?> props, CallbackHandler cbh) throws SaslException {
        if (mechanism.equals(myMechs[PLAIN]) && PolicyUtils.checkPolicy(mechPolicies[PLAIN], props)) {
            if (cbh == null) {
                throw new SaslException("CallbackHandler with support for Password, Name, and AuthorizeCallback required");
            }
            return new SaslServerPlainImpl(protocol, serverName, props, cbh);
        }
        else if (mechanism.equals(myMechs[CLEARSPACE]) && PolicyUtils.checkPolicy(mechPolicies[CLEARSPACE], props)) {
            if (cbh == null) {
                throw new SaslException("CallbackHandler with support for AuthorizeCallback required");
            }
            return new ClearspaceSaslServer();
        }
        return null;
    }
View Full Code Here

            if ("true".equals(WSUtils.getReturn(resultElement))) {
                completed = true;
            }
            else {
                // Failed to authenticate the user so throw an error so SASL failure is returned
                throw new SaslException("SASL CLEARSPACE: user not authorized: " + jid);
            }
        } catch (SaslException e) {
            // rethrow exception
            throw e;
        } catch (Exception e) {
            Log.error("Failed communicating with Clearspace", e);
            throw new SaslException("SASL CLEARSPACE: user not authorized due to an error: " + jid);
        }

        return null;
    }
View Full Code Here

      ByteBuffer frame = readFrame();
      switch (status) {
      case COMPLETE:
        break;
      case FAIL:
        throw new SaslException("Fail: "+toString(frame));
      default:
        throw new IOException("Unexpected SASL status: "+status);
      }
    }
    return super.transceive(request);
View Full Code Here

TOP

Related Classes of javax.security.sasl.SaslException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.