本文整理了Java中org.apache.thrift.transport.TSaslServerTransport
类的一些代码示例,展示了TSaslServerTransport
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TSaslServerTransport
类的具体详情如下:
包路径:org.apache.thrift.transport.TSaslServerTransport
类名称:TSaslServerTransport
[英]Wraps another Thrift TTransport
, but performs SASL server negotiation on the call to open()
. This class will wrap ensuing communication over it, if a SASL QOP is negotiated with the other party.
[中]包装另一个ThriftTTransport
,但在调用open()
时执行SASL服务器协商。如果与另一方协商SASL QOP,则该类将在其上封装后续通信。
代码示例来源:origin: alibaba/jstorm
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);
}
}
代码示例来源:origin: org.apache.thrift/libthrift
/**
* Creates a SaslServer
using the given SASL-specific parameters.
* See the Java documentation for Sasl.createSaslServer
for the
* details of the parameters.
*
* @param transport
* The underlying Thrift transport.
*/
public TSaslServerTransport(String mechanism, String protocol, String serverName,
Map
super(transport);
addServerDefinition(mechanism, protocol, serverName, props, cbh);
}
代码示例来源:origin: apache/hive
private void setUserName(final TProtocol in) {
TTransport transport = in.getTransport();
if (transport instanceof TSaslServerTransport) {
String userName = ((TSaslServerTransport) transport).getSaslServer().getAuthorizationID();
THREAD_LOCAL_USER_NAME.set(userName);
}
}
代码示例来源:origin: apache/hive
private TSocket getUnderlyingSocketFromTransport(TTransport transport) {
while (transport != null) {
if (transport instanceof TSaslServerTransport) {
transport = ((TSaslServerTransport) transport).getUnderlyingTransport();
}
if (transport instanceof TSaslClientTransport) {
transport = ((TSaslClientTransport) transport).getUnderlyingTransport();
}
if (transport instanceof TSocket) {
return (TSocket) transport;
}
}
return null;
}
代码示例来源:origin: org.apache.thrift/libthrift
/**
* 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;
try {
mechanismName = new String(message.payload, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new TTransportException("JVM DOES NOT SUPPORT UTF-8");
}
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);
}
代码示例来源:origin: org.apache.thrift/libthrift
/**
* Get a new TSaslServerTransport
instance, or reuse the
* existing one if a TSaslServerTransport
has already been
* created before using the given TTransport
as an underlying
* transport. This ensures that a given underlying transport instance
* receives the same TSaslServerTransport
.
*/
@Override
public TTransport getTransport(TTransport base) {
WeakReference
if (ret == null || ret.get() == null) {
LOGGER.debug("transport map does not contain key", base);
ret = new WeakReference
try {
ret.get().open();
} catch (TTransportException e) {
LOGGER.debug("failed to open server transport", e);
throw new RuntimeException(e);
}
transportMap.put(base, ret); // No need for putIfAbsent().
// Concurrent calls to getTransport() will pass in different TTransports.
} else {
LOGGER.debug("transport map does contain key {}", base);
}
return ret.get();
}
}
代码示例来源:origin: apache/hbase
TSaslServerTransport saslServerTransport =
(TSaslServerTransport)inProt.getTransport();
SaslServer saslServer = saslServerTransport.getSaslServer();
String principal = saslServer.getAuthorizationID();
hbaseServiceHandler.setEffectiveUser(principal);
代码示例来源:origin: org.spark-project.hive/hive-service
private TSocket getUnderlyingSocketFromTransport(TTransport transport) {
while (transport != null) {
if (transport instanceof TSaslServerTransport) {
transport = ((TSaslServerTransport) transport).getUnderlyingTransport();
}
if (transport instanceof TSaslClientTransport) {
transport = ((TSaslClientTransport) transport).getUnderlyingTransport();
}
if (transport instanceof TSocket) {
return (TSocket) transport;
}
}
return null;
}
代码示例来源:origin: com.twitter/libthrift
/**
* 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) {
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) {
sendAndThrowMessage(NegotiationStatus.BAD, "Unsupported mechanism type " + mechanismName);
}
SaslServer saslServer = Sasl.createSaslServer(serverDefinition.mechanism,
serverDefinition.protocol, serverDefinition.serverName, serverDefinition.props,
serverDefinition.cbh);
setSaslServer(saslServer);
}
代码示例来源:origin: com.twitter/libthrift
/**
* Get a new TSaslServerTransport
instance, or reuse the
* existing one if a TSaslServerTransport
has already been
* created before using the given TTransport
as an underlying
* transport. This ensures that a given underlying transport instance
* receives the same TSaslServerTransport
.
*/
@Override
public TTransport getTransport(TTransport base) {
TSaslServerTransport ret = transportMap.get(base);
if (ret == null) {
LOGGER.debug("transport map does not contain key", base);
ret = new TSaslServerTransport(serverDefinitionMap, base);
try {
ret.open();
} catch (TTransportException e) {
LOGGER.debug("failed to open server transport", e);
throw new RuntimeException(e);
}
transportMap.put(base, ret);
} else {
LOGGER.debug("transport map does contain key {}", base);
}
return ret;
}
}
代码示例来源:origin: apache/hive
SaslServer saslServer = saslTrans.getSaslServer();
String authId = saslServer.getAuthorizationID();
LOG.debug("AUTH ID ======>" + authId);
String endUser = authId;
Socket socket = ((TSocket)(saslTrans.getUnderlyingTransport())).getSocket();
remoteAddress.set(socket.getInetAddress());
代码示例来源:origin: apache/accumulo
SaslServer saslServer = saslTrans.getSaslServer();
String endUser = saslServer.getAuthorizationID();
代码示例来源:origin: com.github.hyukjinkwon/hive-service
private TSocket getUnderlyingSocketFromTransport(TTransport transport) {
while (transport != null) {
if (transport instanceof TSaslServerTransport) {
transport = ((TSaslServerTransport) transport).getUnderlyingTransport();
}
if (transport instanceof TSaslClientTransport) {
transport = ((TSaslClientTransport) transport).getUnderlyingTransport();
}
if (transport instanceof TSocket) {
return (TSocket) transport;
}
}
return null;
}
代码示例来源:origin: org.apache.cassandra.deps/libthrift
/**
* 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) {
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) {
sendAndThrowMessage(NegotiationStatus.BAD, "Unsupported mechanism type " + mechanismName);
}
SaslServer saslServer = Sasl.createSaslServer(serverDefinition.mechanism,
serverDefinition.protocol, serverDefinition.serverName, serverDefinition.props,
serverDefinition.cbh);
setSaslServer(saslServer);
}
代码示例来源:origin: org.apache.cassandra.deps/libthrift
/**
* Get a new TSaslServerTransport
instance, or reuse the
* existing one if a TSaslServerTransport
has already been
* created before using the given TTransport
as an underlying
* transport. This ensures that a given underlying transport instance
* receives the same TSaslServerTransport
.
*/
@Override
public TTransport getTransport(TTransport base) {
TSaslServerTransport ret = transportMap.get(base);
if (ret == null) {
LOGGER.debug("transport map does not contain key", base);
ret = new TSaslServerTransport(serverDefinitionMap, base);
try {
ret.open();
} catch (TTransportException e) {
LOGGER.debug("failed to open server transport", e);
throw new RuntimeException(e);
}
transportMap.put(base, ret);
} else {
LOGGER.debug("transport map does contain key {}", base);
}
return ret;
}
}
代码示例来源:origin: org.apache.cassandra.deps/libthrift
/**
* Creates a SaslServer
using the given SASL-specific parameters.
* See the Java documentation for Sasl.createSaslServer
for the
* details of the parameters.
*
* @param transport
* The underlying Thrift transport.
*/
public TSaslServerTransport(String mechanism, String protocol, String serverName,
Map
super(transport);
addServerDefinition(mechanism, protocol, serverName, props, cbh);
}
代码示例来源:origin: org.apache.hive.shims/hive-shims-common-secure
SaslServer saslServer = saslTrans.getSaslServer();
String authId = saslServer.getAuthorizationID();
authenticationMethod.set(AuthenticationMethod.KERBEROS);
Socket socket = ((TSocket)(saslTrans.getUnderlyingTransport())).getSocket();
remoteAddress.set(socket.getInetAddress());
UserGroupInformation clientUgi = null;
代码示例来源:origin: org.apache.hive/hive-service
private void setUserName(final TProtocol in) {
TTransport transport = in.getTransport();
if (transport instanceof TSaslServerTransport) {
String userName = ((TSaslServerTransport) transport).getSaslServer().getAuthorizationID();
THREAD_LOCAL_USER_NAME.set(userName);
}
}
代码示例来源:origin: apache/sentry
/**
* Returns the underlying TSocket from the transport, or null of the transport type is unknown.
*/
private static TSocket getUnderlyingSocketFromTransport(TTransport transport) {
Preconditions.checkNotNull(transport);
if (transport instanceof TSaslServerTransport) {
return (TSocket) ((TSaslServerTransport) transport).getUnderlyingTransport();
} else if (transport instanceof TSaslClientTransport) {
return (TSocket) ((TSaslClientTransport) transport).getUnderlyingTransport();
} else if (transport instanceof TSocket) {
return (TSocket) transport;
}
return null;
}
代码示例来源:origin: com.twitter/libthrift
/**
* Creates a SaslServer
using the given SASL-specific parameters.
* See the Java documentation for Sasl.createSaslServer
for the
* details of the parameters.
*
* @param transport
* The underlying Thrift transport.
*/
public TSaslServerTransport(String mechanism, String protocol, String serverName,
Map
super(transport);
addServerDefinition(mechanism, protocol, serverName, props, cbh);
}