本文整理汇总了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;
}
示例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));
}
});
}
示例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());
}
示例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());
}
}
}
示例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());
}
}
}
示例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());
}
}
}
示例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;
}
示例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()));
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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) {
}
}