當前位置: 首頁>>代碼示例>>Java>>正文


Java SaslClient類代碼示例

本文整理匯總了Java中javax.security.sasl.SaslClient的典型用法代碼示例。如果您正苦於以下問題:Java SaslClient類的具體用法?Java SaslClient怎麽用?Java SaslClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SaslClient類屬於javax.security.sasl包,在下文中一共展示了SaslClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createSaslClient

import javax.security.sasl.SaslClient; //導入依賴的package包/類
public SaslClient createSaslClient(String[] mechanisms,
                                   String authorizationId,
                                   String protocol,
                                   String serverName,
                                   Map<String, ?> props,
                                   CallbackHandler callbackHandler) {
  boolean matchedMechanism = false;
  for (int i = 0; i < mechanisms.length; ++i) {
    if ("XOAUTH2".equalsIgnoreCase(mechanisms[i])) {
      matchedMechanism = true;
      break;
    }
  }
  if (!matchedMechanism) {
    logger.info("Failed to match any mechanisms");
    return null;
  }
  return new OAuth2SaslClient((String) props.get(OAUTH_TOKEN_PROP),
                              callbackHandler);
}
 
開發者ID:google,項目名稱:gmail-oauth2-tools,代碼行數:21,代碼來源:OAuth2SaslClientFactory.java

示例2: SaslOutputStream

import javax.security.sasl.SaslClient; //導入依賴的package包/類
SaslOutputStream(SaslClient sc, OutputStream out) throws SaslException {
    super(out);
    this.sc = sc;

    if (debug) {
        System.err.println("SaslOutputStream: " + out);
    }

    String str = (String) sc.getNegotiatedProperty(Sasl.RAW_SEND_SIZE);
    if (str != null) {
        try {
            rawSendSize = Integer.parseInt(str);
        } catch (NumberFormatException e) {
            throw new SaslException(Sasl.RAW_SEND_SIZE +
                " property must be numeric string: " + str);
        }
    }
}
 
開發者ID:aducode,項目名稱:openjdk-source-code-learn,代碼行數:19,代碼來源:SaslOutputStream.java

示例3: SaslInputStream

import javax.security.sasl.SaslClient; //導入依賴的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];
}
 
開發者ID:aducode,項目名稱:openjdk-source-code-learn,代碼行數:17,代碼來源:SaslInputStream.java

示例4: createSaslClient

import javax.security.sasl.SaslClient; //導入依賴的package包/類
static SaslClient createSaslClient(final String user, final String password) throws SaslException {
    return Sasl.createSaslClient(new String[]{"PLAIN"}, user, null, null, null,
            new CallbackHandler() {
                @Override
                public void handle(final Callback[] callbacks)
                        throws IOException, UnsupportedCallbackException {
                    for (final Callback callback : callbacks) {
                        if (callback instanceof PasswordCallback) {
                            ((PasswordCallback) callback).setPassword(password.toCharArray());
                        } else if (callback instanceof NameCallback) {
                            ((NameCallback) callback).setName(user);
                        }
                    }
                }
            });
}
 
開發者ID:mongodb,項目名稱:mongosql-auth-java,代碼行數:17,代碼來源:Plain.java

示例5: runNegotiation

import javax.security.sasl.SaslClient; //導入依賴的package包/類
private void runNegotiation(CallbackHandler clientCbh,
                            CallbackHandler serverCbh)
                                throws SaslException {
  String mechanism = AuthMethod.PLAIN.getMechanismName();

  SaslClient saslClient = Sasl.createSaslClient(
      new String[]{ mechanism }, null, null, null, null, clientCbh);
  assertNotNull(saslClient);

  SaslServer saslServer = Sasl.createSaslServer(
      mechanism, null, "localhost", null, serverCbh);
  assertNotNull("failed to find PLAIN server", saslServer);
  
  byte[] response = saslClient.evaluateChallenge(new byte[0]);
  assertNotNull(response);
  assertTrue(saslClient.isComplete());

  response = saslServer.evaluateResponse(response);
  assertNull(response);
  assertTrue(saslServer.isComplete());
  assertNotNull(saslServer.getAuthorizationID());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:TestSaslRPC.java

示例6: createSaslClient

import javax.security.sasl.SaslClient; //導入依賴的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);
    }
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:25,代碼來源:ScramSaslClient.java

示例7: channelRead0

import javax.security.sasl.SaslClient; //導入依賴的package包/類
@Override
protected void channelRead0(final ChannelHandlerContext channelHandlerContext, final ResponseMessage response) throws Exception {
    // We are only interested in AUTHENTICATE responses here. Everything else can
    // get passed down the pipeline
    if (response.getStatus().getCode() == ResponseStatusCode.AUTHENTICATE) {
        final Attribute<SaslClient> saslClient = channelHandlerContext.attr(saslClientKey);
        final Attribute<Subject> subject = channelHandlerContext.attr(subjectKey);
        RequestMessage.Builder messageBuilder = RequestMessage.build(Tokens.OPS_AUTHENTICATION);
        // First time through we don't have a sasl client
        if (saslClient.get() == null) {
            subject.set(login());
            saslClient.set(saslClient(getHostName(channelHandlerContext)));
            messageBuilder.addArg(Tokens.ARGS_SASL_MECHANISM, getMechanism());
            messageBuilder.addArg(Tokens.ARGS_SASL, saslClient.get().hasInitialResponse() ?
                                                        evaluateChallenge(subject, saslClient, NULL_CHALLENGE) : null);
        } else {
            messageBuilder.addArg(Tokens.ARGS_SASL, evaluateChallenge(subject, saslClient, (byte[])response.getResult().getData()));
        }
        channelHandlerContext.writeAndFlush(messageBuilder.create());
    } else {
        channelHandlerContext.fireChannelRead(response);
    }
}
 
開發者ID:PKUSilvester,項目名稱:LiteGraph,代碼行數:24,代碼來源:Handler.java

示例8: setSaslClient

import javax.security.sasl.SaslClient; //導入依賴的package包/類
@Override
public void setSaslClient(final SaslClient saslClient) {
  checkState(this.saslClient == null);
  this.saslClient = saslClient;

  // If encryption is enabled set the backend wrapper instance corresponding to this SaslClient in the connection
  // object. This is later used to do wrap/unwrap in handlers.
  if (isEncryptionEnabled()) {
    saslCodec = new SaslCodec() {
      @Override
      public byte[] wrap(byte[] data, int offset, int len) throws SaslException {
        assert saslClient != null;
        return saslClient.wrap(data, offset, len);
      }

      @Override
      public byte[] unwrap(byte[] data, int offset, int len) throws SaslException {
        assert saslClient != null;
        return saslClient.unwrap(data, offset, len);
      }
    };
  }
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:24,代碼來源:ControlConnection.java

示例9: setSaslClient

import javax.security.sasl.SaslClient; //導入依賴的package包/類
@Override
public void setSaslClient(final SaslClient saslClient) {
  checkState(this.saslClient == null);
  this.saslClient = saslClient;

  // If encryption is enabled set the backend wrapper instance corresponding to this SaslClient in the connection
  // object. This is later used to do wrap/unwrap in handlers.
  if (isEncryptionEnabled()) {
    saslCodec = new SaslCodec() {

      @Override
      public byte[] wrap(byte[] data, int offset, int len) throws SaslException {
        checkState(saslClient != null);
        return saslClient.wrap(data, offset, len);
      }

      @Override
      public byte[] unwrap(byte[] data, int offset, int len) throws SaslException {
        checkState(saslClient != null);
        return saslClient.unwrap(data, offset, len);
      }
    };
  }
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:25,代碼來源:AbstractClientConnection.java

示例10: initiate

import javax.security.sasl.SaslClient; //導入依賴的package包/類
public void initiate(final String mechanismName) {
  logger.trace("Initiating SASL exchange.");
  try {
    final ByteString responseData;
    final SaslClient saslClient = connection.getSaslClient();
    if (saslClient.hasInitialResponse()) {
      responseData = ByteString.copyFrom(evaluateChallenge(ugi, saslClient, new byte[0]));
    } else {
      responseData = ByteString.EMPTY;
    }
    client.send(new AuthenticationOutcomeListener<>(client, connection, saslRpcType, ugi, completionListener),
        connection,
        saslRpcType,
        SaslMessage.newBuilder()
            .setMechanism(mechanismName)
            .setStatus(SaslStatus.SASL_START)
            .setData(responseData)
            .build(),
        SaslMessage.class,
        true /* the connection will not be backed up at this point */);
    logger.trace("Initiated SASL exchange.");
  } catch (final Exception e) {
    completionListener.failed(RpcException.mapException(e));
  }
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:26,代碼來源:AuthenticationOutcomeListener.java

示例11: process

import javax.security.sasl.SaslClient; //導入依賴的package包/類
@Override
public <CC extends ClientConnection> SaslMessage process(SaslChallengeContext<CC> context) throws Exception {
  final SaslClient saslClient = context.connection.getSaslClient();

  if (saslClient.isComplete()) {
    handleSuccess(context);
    return null;
  } else {
    // server completed before client; so try once, fail otherwise
    evaluateChallenge(context.ugi, saslClient, context.challenge.getData().toByteArray()); // discard response

    if (saslClient.isComplete()) {
      handleSuccess(context);
      return null;
    } else {
      throw new SaslException("Server allegedly succeeded authentication, but client did not. Suspicious?");
    }
  }
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:20,代碼來源:AuthenticationOutcomeListener.java

示例12: createSaslClient

import javax.security.sasl.SaslClient; //導入依賴的package包/類
@Override
public SaslClient createSaslClient(final UserGroupInformation ugi, final Map<String, ?> properties)
    throws SaslException {
  final String userName = (String) properties.get(DrillProperties.USER);
  final String password = (String) properties.get(DrillProperties.PASSWORD);

  return FastSaslClientFactory.getInstance().createSaslClient(new String[]{SIMPLE_NAME},
      null /** authorization ID */, null, null, properties, new CallbackHandler() {
        @Override
        public void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException {
          for (final Callback callback : callbacks) {
            if (callback instanceof NameCallback) {
              NameCallback.class.cast(callback).setName(userName);
              continue;
            }
            if (callback instanceof PasswordCallback) {
              PasswordCallback.class.cast(callback).setPassword(password.toCharArray());
              continue;
            }
            throw new UnsupportedCallbackException(callback);
          }
        }
      });
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:25,代碼來源:PlainFactory.java

示例13: createSaslClient

import javax.security.sasl.SaslClient; //導入依賴的package包/類
@Override
public SaslClient createSaslClient(String[] mechanisms, String authorizationId, String protocol, String serverName,
                                   Map<String, ?> props, CallbackHandler cbh) throws SaslException {
  for (final String mechanism : mechanisms) {
    final List<SaslClientFactory> factories = clientFactories.get(mechanism);
    if (factories != null) {
      for (final SaslClientFactory factory : factories) {
        final SaslClient saslClient = factory.createSaslClient(new String[]{mechanism}, authorizationId, protocol,
            serverName, props, cbh);
        if (saslClient != null) {
          return saslClient;
        }
      }
    }
  }
  return null;
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:18,代碼來源:FastSaslClientFactory.java

示例14: SaslClientContext

import javax.security.sasl.SaslClient; //導入依賴的package包/類
public SaslClientContext(final SaslClientFactory saslClientFactory, final String mech, final String server_name, final CallbackHandler callback_handler, final Map<String, String> props, final Subject subject) throws SaslException {
    this.subject = subject;
    if (this.subject != null) {
        try {
            client = Subject.doAs(this.subject, new PrivilegedExceptionAction<SaslClient>() {

                @Override
                public SaslClient run() throws Exception {
                    return saslClientFactory.createSaslClient(new String[] { mech }, null, SASL.SASL_PROTOCOL_NAME, server_name, props, callback_handler);
                }
            });
        } catch (PrivilegedActionException e) {
            throw (SaslException)e.getCause(); // The createSaslServer will only throw this type of exception
        }
    } else {
        client = saslClientFactory.createSaslClient(new String[] { mech }, null, SASL.SASL_PROTOCOL_NAME, server_name, props, callback_handler);
    }
}
 
開發者ID:zjumty,項目名稱:jgroups-3.6.4-fixed,代碼行數:19,代碼來源:SaslClientContext.java

示例15: handleSaslStartMessage

import javax.security.sasl.SaslClient; //導入依賴的package包/類
/**
 * Performs the client side of the initial portion of the Thrift SASL
 * protocol. Generates and sends the initial response to the server, including
 * which mechanism this client wants to use.
 */
@Override
protected void handleSaslStartMessage() throws TTransportException, SaslException {
  SaslClient saslClient = getSaslClient();

  byte[] initialResponse = new byte[0];
  if (saslClient.hasInitialResponse())
    initialResponse = saslClient.evaluateChallenge(initialResponse);

  LOGGER.debug("Sending mechanism name {} and initial response of length {}", mechanism,
      initialResponse.length);

  byte[] mechanismBytes = mechanism.getBytes();
  sendSaslMessage(NegotiationStatus.START,
                  mechanismBytes);
  // Send initial response
  sendSaslMessage(saslClient.isComplete() ? NegotiationStatus.COMPLETE : NegotiationStatus.OK,
                  initialResponse);
  underlyingTransport.flush();
}
 
開發者ID:adityayadav76,項目名稱:internet_of_things_simulator,代碼行數:25,代碼來源:TSaslClientTransport.java


注:本文中的javax.security.sasl.SaslClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。