本文整理匯總了Java中javax.net.ssl.SSLSocket.setNeedClientAuth方法的典型用法代碼示例。如果您正苦於以下問題:Java SSLSocket.setNeedClientAuth方法的具體用法?Java SSLSocket.setNeedClientAuth怎麽用?Java SSLSocket.setNeedClientAuth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.net.ssl.SSLSocket
的用法示例。
在下文中一共展示了SSLSocket.setNeedClientAuth方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildServerSslSocketFactory
import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
public SSLSocketFactory buildServerSslSocketFactory(final ClientAuth clientAuth) {
SslClient serverSslClient = new SslClient.Builder()
.addTrustedCertificate(serverRootCa.certificate)
.addTrustedCertificate(clientRootCa.certificate)
.certificateChain(serverCert, serverIntermediateCa)
.build();
return new DelegatingSSLSocketFactory(serverSslClient.socketFactory) {
@Override protected SSLSocket configureSocket(SSLSocket sslSocket) throws IOException {
if (clientAuth == ClientAuth.NEEDS) {
sslSocket.setNeedClientAuth(true);
} else if (clientAuth == ClientAuth.WANTS) {
sslSocket.setWantClientAuth(true);
}
return super.configureSocket(sslSocket);
}
};
}
示例2: createServerSocket
import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
/**
* <p>Creates a server socket that accepts SSL connections
* configured according to this factory's SSL socket configuration
* parameters.</p>
*/
public ServerSocket createServerSocket(int port) throws IOException {
final SSLSocketFactory sslSocketFactory =
context == null ?
getDefaultSSLSocketFactory() : context.getSocketFactory();
return new ServerSocket(port) {
public Socket accept() throws IOException {
Socket socket = super.accept();
SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
socket, socket.getInetAddress().getHostName(),
socket.getPort(), true);
sslSocket.setUseClientMode(false);
if (enabledCipherSuites != null) {
sslSocket.setEnabledCipherSuites(enabledCipherSuites);
}
if (enabledProtocols != null) {
sslSocket.setEnabledProtocols(enabledProtocols);
}
sslSocket.setNeedClientAuth(needClientAuth);
return sslSocket;
}
};
}
示例3: accept
import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
@Override
public Socket accept() throws IOException {
final SSLSocketFactory sslSocketFactory =
context == null ?
getDefaultSSLSocketFactory() : context.getSocketFactory();
Socket socket = super.accept();
SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
socket, socket.getInetAddress().getHostName(),
socket.getPort(), true);
sslSocket.setUseClientMode(false);
if (enabledCipherSuites != null) {
sslSocket.setEnabledCipherSuites(enabledCipherSuites);
}
if (enabledProtocols != null) {
sslSocket.setEnabledProtocols(enabledProtocols);
}
sslSocket.setNeedClientAuth(needClientAuth);
return sslSocket;
}
示例4: sslNegotiation
import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
/**
* SSL/TLS negotiation. Acquires an SSL socket of a control
* connection and carries out handshake processing.
* @throws java.io.IOException If server negotiation fails
*/
protected void sslNegotiation() throws IOException {
plainSocket = _socket_;
initSslContext();
SSLSocketFactory ssf = context.getSocketFactory();
String ip = _socket_.getInetAddress().getHostAddress();
int port = _socket_.getPort();
SSLSocket socket =
(SSLSocket) ssf.createSocket(_socket_, ip, port, false);
socket.setEnableSessionCreation(isCreation);
socket.setUseClientMode(isClientMode);
// server mode
if (!isClientMode) {
socket.setNeedClientAuth(isNeedClientAuth);
socket.setWantClientAuth(isWantClientAuth);
}
if (protocols != null) {
socket.setEnabledProtocols(protocols);
}
if (suites != null) {
socket.setEnabledCipherSuites(suites);
}
socket.startHandshake();
_socket_ = socket;
_controlInput_ = new BufferedReader(new InputStreamReader(
socket .getInputStream(), getControlEncoding()));
_controlOutput_ = new BufferedWriter(new OutputStreamWriter(
socket.getOutputStream(), getControlEncoding()));
}
示例5: _openDataConnection_
import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
/**
* Returns a socket of the data connection.
* Wrapped as an {@link javax.net.ssl.SSLSocket}, which carries out handshake processing.
* @param command The textual representation of the FTP command to send.
* @param arg The arguments to the FTP command.
* If this parameter is set to null, then the command is sent with
* no arguments.
* @return corresponding to the established data connection.
* Null is returned if an FTP protocol error is reported at any point
* during the establishment and initialization of the connection.
* @throws java.io.IOException If there is any problem with the connection.
* @see org.apache.commons.net.ftp.FTPClient#_openDataConnection_(int, String)
* @since 3.2
*/
@Override
protected Socket _openDataConnection_(String command, String arg)
throws IOException {
Socket socket = super._openDataConnection_(command, arg);
_prepareDataSocket_(socket);
if (socket instanceof SSLSocket) {
SSLSocket sslSocket = (SSLSocket)socket;
sslSocket.setUseClientMode(isClientMode);
sslSocket.setEnableSessionCreation(isCreation);
// server mode
if (!isClientMode) {
sslSocket.setNeedClientAuth(isNeedClientAuth);
sslSocket.setWantClientAuth(isWantClientAuth);
}
if (suites != null) {
sslSocket.setEnabledCipherSuites(suites);
}
if (protocols != null) {
sslSocket.setEnabledProtocols(protocols);
}
sslSocket.startHandshake();
}
return socket;
}
示例6: TLSMessageChannel
import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
/**
* Constructor - gets called from the SIPStack class with a socket on
* accepting a new client. All the processing of the message is done here
* with the sipStack being freed up to handle new connections. The sock
* input is the socket that is returned from the accept. Global data that is
* shared by all threads is accessible in the Server structure.
*
* @param sock
* Socket from which to read and write messages. The socket is
* already connected (was created as a result of an accept).
*
* @param sipStack
* Ptr to SIP Stack
*
* @param msgProcessor
* -- the message processor that created us.
*/
protected TLSMessageChannel(Socket sock, SIPTransactionStack sipStack,
TLSMessageProcessor msgProcessor, String threadName) throws IOException {
super(sipStack);
if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
logger.logDebug(
"creating new TLSMessageChannel (incoming)");
logger.logStackTrace();
}
mySock = (SSLSocket) sock;
if (sock instanceof SSLSocket) {
SSLSocket sslSock = (SSLSocket) sock;
if(sipStack.getClientAuth() != ClientAuthType.Want && sipStack.getClientAuth() != ClientAuthType.Disabled && sipStack.getClientAuth() != ClientAuthType.DisabledAll) {
sslSock.setNeedClientAuth(true);
}
if(logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
logger.logDebug("SSLServerSocket need client auth " + sslSock.getNeedClientAuth());
}
}
peerAddress = mySock.getInetAddress();
myAddress = msgProcessor.getIpAddress().getHostAddress();
myClientInputStream = mySock.getInputStream();
mythread = new Thread(this);
mythread.setDaemon(true);
mythread.setName(threadName);
this.myPort = msgProcessor.getPort();
this.peerPort = mySock.getPort();
this.key = MessageChannel.getKey(peerAddress, peerPort, "TLS");
// Bug report by Vishwashanti Raj Kadiayl
super.messageProcessor = msgProcessor;
// Can drop this after response is sent potentially.
mythread.start();
}
示例7: createSSLClientSocket
import javax.net.ssl.SSLSocket; //導入方法依賴的package包/類
/**
* Used for peering tls connection.
* Prepare socket for handshake negotiation.
*
* @param socket
* @return
* @throws IOException
*/
public static SSLSocket createSSLClientSocket(Socket socket) throws IOException{
//autoClose - close the underlying socket when this socket is closed.
SSLSocket sslsocket = (SSLSocket) sslContext.getSocketFactory().createSocket(socket, null, true);
sslsocket.setUseClientMode(true);//client
sslsocket.setNeedClientAuth(true);
return sslsocket;
}