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


Java SaslServer類代碼示例

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


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

示例1: createSaslServer

import javax.security.sasl.SaslServer; //導入依賴的package包/類
@Override
public SaslServer createSaslServer(String mechanism, String protocol,
    String serverName, Map<String,?> props, CallbackHandler cbh)
    throws SaslException {
  SaslServer saslServer = null;
  List<SaslServerFactory> factories = factoryCache.get(mechanism);
  if (factories != null) {
    for (SaslServerFactory factory : factories) {
      saslServer = factory.createSaslServer(
          mechanism, protocol, serverName, props, cbh);
      if (saslServer != null) {
        break;
      }
    }
  }
  return saslServer;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:18,代碼來源:SaslRpcServer.java

示例2: handle

import javax.security.sasl.SaslServer; //導入依賴的package包/類
@Override
public void handle(ChannelHandlerContext ctx, AmqpConnectionHandler connectionHandler) {
    ctx.fireChannelRead((BlockingTask) () -> {
        try {
            SaslServer saslServer = connectionHandler.getSaslServer();
            if (saslServer != null) {
                byte[] challenge = saslServer.evaluateResponse(response.getBytes());
                if (saslServer.isComplete()) {
                    ctx.writeAndFlush(new ConnectionTune(256, 65535, 0));
                } else {
                    ctx.writeAndFlush(new ConnectionSecure(getChannel(), LongString.parse(challenge)));
                }
            } else {
                throw new SaslException("Sasl server hasn't been set during connection start");
            }
        } catch (SaslException e) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Exception occurred while authenticating incoming connection ", e);
            }
            String replyText = "Authentication Failed";
            ctx.writeAndFlush(new ConnectionClose(403, ShortString.parseString(replyText), 10, 21));
        }
    });
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:25,代碼來源:ConnectionSecureOk.java

示例3: runNegotiation

import javax.security.sasl.SaslServer; //導入依賴的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

示例4: createSaslServer

import javax.security.sasl.SaslServer; //導入依賴的package包/類
private void createSaslServer(String mechanism) throws IOException {
    this.saslMechanism = mechanism;
    if (!ScramMechanism.isScram(mechanism))
        callbackHandler = new SaslServerCallbackHandler(jaasContext, kerberosNamer);
    else
        callbackHandler = new ScramServerCallbackHandler(credentialCache.cache(mechanism, ScramCredential.class));
    callbackHandler.configure(configs, Mode.SERVER, subject, saslMechanism);
    if (mechanism.equals(SaslConfigs.GSSAPI_MECHANISM)) {
        saslServer = createSaslKerberosServer(callbackHandler, configs, subject);
    } else {
        try {
            saslServer = Subject.doAs(subject, new PrivilegedExceptionAction<SaslServer>() {
                public SaslServer run() throws SaslException {
                    // 調用createSaslServer
                    return Sasl.createSaslServer(saslMechanism, "kafka", host, configs, callbackHandler);
                }
            });
        } catch (PrivilegedActionException e) {
            throw new SaslException("Kafka Server failed to create a SaslServer to interact with a client during session authentication", e.getCause());
        }
    }
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:23,代碼來源:SaslServerAuthenticator.java

示例5: processConnection

import javax.security.sasl.SaslServer; //導入依賴的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());
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:25,代碼來源:ClientServerTest.java

示例6: createSaslServer

import javax.security.sasl.SaslServer; //導入依賴的package包/類
private void createSaslServer(String mechanism) throws IOException {
    this.saslMechanism = mechanism;
    callbackHandler = new SaslServerCallbackHandler(Configuration.getConfiguration(), kerberosNamer);
    callbackHandler.configure(configs, Mode.SERVER, subject, saslMechanism);
    if (mechanism.equals(SaslConfigs.GSSAPI_MECHANISM)) {
        if (subject.getPrincipals().isEmpty())
            throw new IllegalArgumentException("subject must have at least one principal");
        saslServer = createSaslKerberosServer(callbackHandler, configs);
    } else {
        try {
            saslServer = Subject.doAs(subject, new PrivilegedExceptionAction<SaslServer>() {
                public SaslServer run() throws SaslException {
                    return Sasl.createSaslServer(saslMechanism, "kafka", host, configs, callbackHandler);
                }
            });
        } catch (PrivilegedActionException e) {
            throw new SaslException("Kafka Server failed to create a SaslServer to interact with a client during session authentication", e.getCause());
        }
    }
}
 
開發者ID:txazo,項目名稱:kafka,代碼行數:21,代碼來源:SaslServerAuthenticator.java

示例7: createSaslServer

import javax.security.sasl.SaslServer; //導入依賴的package包/類
public SaslServer createSaslServer(String mechanism, String protocol,
                                   String serverName, Map props,
                                   CallbackHandler cbh) throws SaslException
{
  ServerMechanism result = getInstance(mechanism);
  if (result != null)
    {
      HashMap attributes = new HashMap();
      if (props != null)
        attributes.putAll(props);
      attributes.put(Registry.SASL_PROTOCOL, protocol);
      attributes.put(Registry.SASL_SERVER_NAME, serverName);
      attributes.put(Registry.SASL_CALLBACK_HANDLER, cbh);
      result.init(attributes);
    }
  return result;
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:18,代碼來源:ServerFactory.java

示例8: process

import javax.security.sasl.SaslServer; //導入依賴的package包/類
@Override
public <S extends ServerConnection<S>, T extends EnumLite>
void process(SaslResponseContext<S, T> context) throws Exception {
  final SaslMessage.Builder challenge = SaslMessage.newBuilder();
  final SaslServer saslServer = context.connection.getSaslServer();

  final byte[] challengeBytes = evaluateResponse(saslServer, context.saslResponse.getData().toByteArray());

  if (saslServer.isComplete()) {
    challenge.setStatus(SaslStatus.SASL_SUCCESS);
    if (challengeBytes != null) {
      challenge.setData(ByteString.copyFrom(challengeBytes));
    }

    handleSuccess(context, challenge, saslServer);
  } else {
    challenge.setStatus(SaslStatus.SASL_IN_PROGRESS)
        .setData(ByteString.copyFrom(challengeBytes));
    context.sender.send(new Response(context.saslResponseType, challenge.build()));
  }
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:22,代碼來源:ServerAuthenticationHandler.java

示例9: SaslServerContext

import javax.security.sasl.SaslServer; //導入依賴的package包/類
public SaslServerContext(final SaslServerFactory saslServerFactory, final String mech, final String serverName, final CallbackHandler callback_handler, final Map<String, String> props, final Subject subject) throws SaslException {
    this.subject = subject;
    if (this.subject != null) {
        try {
            server = Subject.doAs(this.subject, new PrivilegedExceptionAction<SaslServer>() {
                @Override
                public SaslServer run() throws Exception {
                    return saslServerFactory.createSaslServer(mech, SASL.SASL_PROTOCOL_NAME, serverName, props, callback_handler);
                }
            });
        } catch (PrivilegedActionException e) {
            throw (SaslException)e.getCause(); // The createSaslServer will only throw this type of exception
        }
    } else {
        server = saslServerFactory.createSaslServer(mech, SASL.SASL_PROTOCOL_NAME, serverName, props, callback_handler);
    }
}
 
開發者ID:zjumty,項目名稱:jgroups-3.6.4-fixed,代碼行數:18,代碼來源:SaslServerContext.java

示例10: process

import javax.security.sasl.SaslServer; //導入依賴的package包/類
@Override
public boolean process(final TProtocol inProt, final TProtocol outProt)
		throws TException {
	// populating request context
	ReqContext req_context = ReqContext.context();

	TTransport trans = inProt.getTransport();
	// Sasl transport
	TSaslServerTransport saslTrans = (TSaslServerTransport) trans;

	// remote address
	TSocket tsocket = (TSocket) saslTrans.getUnderlyingTransport();
	Socket socket = tsocket.getSocket();
	req_context.setRemoteAddress(socket.getInetAddress());

	// remote subject
	SaslServer saslServer = saslTrans.getSaslServer();
	String authId = saslServer.getAuthorizationID();
	Subject remoteUser = new Subject();
	remoteUser.getPrincipals().add(new User(authId));
	req_context.setSubject(remoteUser);

	// invoke service handler
	return wrapped.process(inProt, outProt);
}
 
開發者ID:zhangjunfang,項目名稱:jstorm-0.9.6.3-,代碼行數:26,代碼來源:SaslTransportPlugin.java

示例11: process

import javax.security.sasl.SaslServer; //導入依賴的package包/類
public boolean process(final TProtocol inProt, final TProtocol outProt)
		throws TException {
	// populating request context
	ReqContext req_context = ReqContext.context();

	TTransport trans = inProt.getTransport();
	// Sasl transport
	TSaslServerTransport saslTrans = (TSaslServerTransport) trans;

	// remote address
	TSocket tsocket = (TSocket) saslTrans.getUnderlyingTransport();
	Socket socket = tsocket.getSocket();
	req_context.setRemoteAddress(socket.getInetAddress());

	// remote subject
	SaslServer saslServer = saslTrans.getSaslServer();
	String authId = saslServer.getAuthorizationID();
	Subject remoteUser = new Subject();
	remoteUser.getPrincipals().add(new User(authId));
	req_context.setSubject(remoteUser);

	// invoke service handler
	return wrapped.process(inProt, outProt);
}
 
開發者ID:songtk,項目名稱:learn_jstorm,代碼行數:25,代碼來源:SaslTransportPlugin.java

示例12: handleSaslStartMessage

import javax.security.sasl.SaslServer; //導入依賴的package包/類
/**
 * Performs the server side of the initial portion of the Thrift SASL protocol.
 * Receives the initial response from the client, creates a SASL server using
 * the mechanism requested by the client (if this server supports it), and
 * sends the first challenge back to the client.
 */
@Override
protected void handleSaslStartMessage() throws TTransportException, SaslException {
  SaslResponse message = receiveSaslMessage();

  LOGGER.debug("Received start message with status {}", message.status);
  if (message.status != NegotiationStatus.START) {
    throw sendAndThrowMessage(NegotiationStatus.ERROR, "Expecting START status, received " + message.status);
  }

  // Get the mechanism name.
  String mechanismName = new String(message.payload);
  TSaslServerDefinition serverDefinition = serverDefinitionMap.get(mechanismName);
  LOGGER.debug("Received mechanism name '{}'", mechanismName);

  if (serverDefinition == null) {
    throw sendAndThrowMessage(NegotiationStatus.BAD, "Unsupported mechanism type " + mechanismName);
  }
  SaslServer saslServer = Sasl.createSaslServer(serverDefinition.mechanism,
      serverDefinition.protocol, serverDefinition.serverName, serverDefinition.props,
      serverDefinition.cbh);
  setSaslServer(saslServer);
}
 
開發者ID:adityayadav76,項目名稱:internet_of_things_simulator,代碼行數:29,代碼來源:TSaslServerTransport.java

示例13: process

import javax.security.sasl.SaslServer; //導入依賴的package包/類
public boolean process(final TProtocol inProt, final TProtocol outProt) throws TException {
    // populating request context
    ReqContext req_context = ReqContext.context();

    TTransport trans = inProt.getTransport();
    // Sasl transport
    TSaslServerTransport saslTrans = (TSaslServerTransport) trans;
    // remote address
    TSocket tsocket = (TSocket) saslTrans.getUnderlyingTransport();
    Socket socket = tsocket.getSocket();
    req_context.setRemoteAddress(socket.getInetAddress());

    // remote subject
    SaslServer saslServer = saslTrans.getSaslServer();
    String authId = saslServer.getAuthorizationID();
    Subject remoteUser = new Subject();
    remoteUser.getPrincipals().add(new User(authId));
    req_context.setSubject(remoteUser);

    // invoke service handler
    return wrapped.process(inProt, outProt);
}
 
開發者ID:kkllwww007,項目名稱:jstrom,代碼行數:23,代碼來源:SaslTransportPlugin.java

示例14: process

import javax.security.sasl.SaslServer; //導入依賴的package包/類
public boolean process(final TProtocol inProt, final TProtocol outProt) throws TException {
    //populating request context 
    ReqContext req_context = ReqContext.context();

    TTransport trans = inProt.getTransport();
    //Sasl transport
    TSaslServerTransport saslTrans = (TSaslServerTransport)trans;

    //remote address
    TSocket tsocket = (TSocket)saslTrans.getUnderlyingTransport();
    Socket socket = tsocket.getSocket();
    req_context.setRemoteAddress(socket.getInetAddress());

    //remote subject 
    SaslServer saslServer = saslTrans.getSaslServer();
    String authId = saslServer.getAuthorizationID();
    Subject remoteUser = new Subject();
    remoteUser.getPrincipals().add(new User(authId));
    req_context.setSubject(remoteUser);
    
    //invoke service handler
    return wrapped.process(inProt, outProt);
}
 
開發者ID:metamx,項目名稱:incubator-storm,代碼行數:24,代碼來源:SaslTransportPlugin.java

示例15: testCreateServer04

import javax.security.sasl.SaslServer; //導入依賴的package包/類
/**
 * Test for <code>createSaslServer(String mechanism, 
 *      String protocol, String serverName,
 *      Map prop, CallbackHandler cbh))</code> method
 *  
 * Assertions: 
 * returns SaslServer;
 * throws SaslServer for MECH-1 mechanism
 * 
 * All providers are previously removed and 
 * 1 new provider was added.
 */
public void testCreateServer04() throws SaslException {
    mProv = new Provider[] { (new SpiEngUtils()).new MyProvider(
            "MySaslServerProvider1",
            "Testing provider SaslServerFactory - 1", SRVSSRV
                    .concat("MECH-1"), fServerClass) };
    mProv[0].put(SRVSSRV.concat("MECH-2"), fServerClass);
    addProviders();
    CallbackHandler cbH = new Sasl3Test.cbHandN();
    SaslServer saslS = Sasl.createSaslServer("MECH-2", "protocol", null,
            null, cbH);
    assertNotNull("Null result for MECH-2", saslS);
    assertFalse("Incorrect isComplete() result", saslS.isComplete());
    // try to create Server for wrong mechanism
    try {
        saslS = Sasl
                .createSaslServer("MECH-1", "protocol", null, null, cbH);
        fail("SaslException sould be thrown");
    } catch (SaslException e) {
    }
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:33,代碼來源:Sasl4Test.java


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