当前位置: 首页>>代码示例>>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;未经允许,请勿转载。