本文整理了Java中javax.net.ssl.SSLServerSocket.setNeedClientAuth()
方法的一些代码示例,展示了SSLServerSocket.setNeedClientAuth()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SSLServerSocket.setNeedClientAuth()
方法的具体详情如下:
包路径:javax.net.ssl.SSLServerSocket
类名称:SSLServerSocket
方法名:setNeedClientAuth
[英]Sets whether server-mode connections will be configured to require client authentication. The client authentication is one of the following:
代码示例来源:origin: wildfly/wildfly
default void setNeedClientAuth(SSLContext sslContext, SSLServerSocket sslServerSocket, boolean value) {
sslServerSocket.setNeedClientAuth(value);
}
代码示例来源:origin: wildfly/wildfly
default void setWantClientAuth(SSLContext sslContext, SSLServerSocket sslServerSocket, boolean value) {
sslServerSocket.setNeedClientAuth(value);
}
代码示例来源:origin: wildfly/wildfly
public void setNeedClientAuth(final SSLContext sslContext, final SSLServerSocket sslServerSocket, final boolean value) {
if (value) sslServerSocket.setNeedClientAuth(value);
}
代码示例来源:origin: wildfly/wildfly
public void setNeedClientAuth(final boolean need) {
delegate.setNeedClientAuth(need);
}
代码示例来源:origin: apache/nifi
private ServerSocket createServerSocket() throws IOException {
final InetAddress inetAddress = hostname == null ? null : InetAddress.getByName(hostname);
if (sslContext == null) {
return new ServerSocket(port, 50, InetAddress.getByName(hostname));
} else {
final ServerSocket serverSocket = sslContext.getServerSocketFactory().createServerSocket(port, 50, inetAddress);
((SSLServerSocket) serverSocket).setNeedClientAuth(true);
return serverSocket;
}
}
代码示例来源:origin: wildfly/wildfly
protected SSLServerSocket createServerSocket() throws Exception {
SSLContext ctx=getContext();
SSLServerSocketFactory sslServerSocketFactory=ctx.getServerSocketFactory();
SSLServerSocket sslServerSocket=null;
for(int i=0; i < port_range; i++) {
try {
sslServerSocket=(SSLServerSocket)sslServerSocketFactory.createServerSocket(port + i, 50, bind_addr);
sslServerSocket.setNeedClientAuth(require_client_authentication);
return sslServerSocket;
}
catch(Throwable t) {
}
}
throw new IllegalStateException(String.format("found no valid port to bind to in range [%d-%d]", port, port+port_range));
}
代码示例来源:origin: apache/activemq
/**
* Binds this socket to the previously specified URI.
*
* Overridden to allow for proper handling of needClientAuth.
*
* @throws IOException passed up from TcpTransportServer.
*/
@Override
public void bind() throws IOException {
super.bind();
if (needClientAuth) {
((SSLServerSocket)this.serverSocket).setNeedClientAuth(true);
} else if (wantClientAuth) {
((SSLServerSocket)this.serverSocket).setWantClientAuth(true);
}
}
代码示例来源:origin: apache/activemq
/**
* Binds this socket to the previously specified URI.
*
* Overridden to allow for proper handling of needClientAuth.
*
* @throws IOException passed up from TcpTransportServer.
*/
@Override
public void bind() throws IOException {
super.bind();
if (needClientAuth) {
((SSLServerSocket)this.serverSocket).setNeedClientAuth(true);
} else if (wantClientAuth) {
((SSLServerSocket)this.serverSocket).setWantClientAuth(true);
}
}
代码示例来源:origin: NanoHttpd/nanohttpd
@Override
public ServerSocket create() throws IOException {
SSLServerSocket ss = null;
ss = (SSLServerSocket) this.sslServerSocketFactory.createServerSocket();
if (this.sslProtocols != null) {
ss.setEnabledProtocols(this.sslProtocols);
} else {
ss.setEnabledProtocols(ss.getSupportedProtocols());
}
ss.setUseClientMode(false);
ss.setWantClientAuth(false);
ss.setNeedClientAuth(false);
return ss;
}
代码示例来源:origin: apache/nifi
public static ServerSocket createServerSocket(final int port, final ServerSocketConfiguration config)
throws IOException, KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, CertificateException {
if (config == null) {
throw new NullPointerException("Configuration may not be null.");
}
final SSLContext sslContext = config.createSSLContext();
final ServerSocket serverSocket;
if (sslContext == null) {
serverSocket = new ServerSocket(port);
} else {
serverSocket = sslContext.getServerSocketFactory().createServerSocket(port);
((SSLServerSocket) serverSocket).setNeedClientAuth(config.getNeedClientAuth());
}
if (config.getSocketTimeout() != null) {
serverSocket.setSoTimeout(config.getSocketTimeout());
}
if (config.getReuseAddress() != null) {
serverSocket.setReuseAddress(config.getReuseAddress());
}
if (config.getReceiveBufferSize() != null) {
serverSocket.setReceiveBufferSize(config.getReceiveBufferSize());
}
return serverSocket;
}
代码示例来源:origin: apache/geode
/**
* Configure the SSLServerSocket based on this SocketCreator's settings.
*/
private void finishServerSocket(SSLServerSocket serverSocket) throws IOException {
serverSocket.setUseClientMode(false);
if (this.sslConfig.isRequireAuth()) {
// serverSocket.setWantClientAuth( true );
serverSocket.setNeedClientAuth(true);
}
serverSocket.setEnableSessionCreation(true);
// restrict protocols
String[] protocols = this.sslConfig.getProtocolsAsStringArray();
if (!"any".equalsIgnoreCase(protocols[0])) {
serverSocket.setEnabledProtocols(protocols);
}
// restrict ciphers
String[] ciphers = this.sslConfig.getCiphersAsStringArray();
if (!"any".equalsIgnoreCase(ciphers[0])) {
serverSocket.setEnabledCipherSuites(ciphers);
}
}
代码示例来源:origin: wildfly/wildfly
public ServerSocket createSSLServerSocket(int port, int backlog, InetAddress inetAddress) throws IOException {
this.initSSLContext();
SSLServerSocketFactory serverSocketFactory = this.sslContext.getServerSocketFactory();
SSLServerSocket serverSocket = (SSLServerSocket) serverSocketFactory.createServerSocket(port, backlog, inetAddress);
if (this.jsseSecurityDomain.getProtocols() != null){
serverSocket.setEnabledProtocols(this.jsseSecurityDomain.getProtocols());
}
if (this.jsseSecurityDomain.getCipherSuites() != null){
serverSocket.setEnabledCipherSuites(this.jsseSecurityDomain.getCipherSuites());
}
if (this.jsseSecurityDomain.isClientAuth() || this.require_mutual_auth){
serverSocket.setNeedClientAuth(true);
} else {
serverSocket.setWantClientAuth(this.request_mutual_auth);
}
return serverSocket;
}
代码示例来源:origin: apache/ignite
.createServerSocket(port, 0, spi.locHost);
sslSock.setNeedClientAuth(true);
代码示例来源:origin: camunda/camunda-bpm-platform
public void setNeedClientAuth(boolean state) {
delegate.setNeedClientAuth(state);
}
代码示例来源:origin: spring-projects/spring-integration
@Override
public void postProcessServerSocket(ServerSocket serverSocket) {
((SSLServerSocket) serverSocket).setNeedClientAuth(true);
}
代码示例来源:origin: stackoverflow.com
KeyStore trustStore = KeyStore.getInstance("JKS");
InputStream tsis = new FileInputStream("trustedcerts.jks");
trustStore.load(tsis, "clientpublicpw".toCharArray());
tsis.close();
KeyStore serverKeyStore = KeyStore.getInstance("JKS");
InputStream ksis = new FileInputStream("server.jks");
clientKeyStore.load(ksis.close(), "serverprivatepw".toCharArray());
ksis.close();
TrustManagerFactory tmf =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(trustStore);
KeyManagerFactory kmf =
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(serverKeyStore, "serverprivatepw".toCharArray());
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
SSLServerSocketFactory sf = sslContext.getServerSocketFactory();
SSLServerSocket ss = (SSLServerSocket)sf.createServerSocket(SslServer.PORT);
ss.setNeedClientAuth(true);
代码示例来源:origin: javaee/glassfish
/**
* Configures the given SSL server socket with the requested cipher suites, protocol versions, and need for client
* authentication
*/
protected void initServerSocket(ServerSocket ssocket) {
if (!(ssocket instanceof SSLServerSocket)) {
throw new IllegalArgumentException("The ServerSocket has to be SSLServerSocket");
}
SSLServerSocket socket = (SSLServerSocket) ssocket;
if (attributes.get("ciphers") != null) {
socket.setEnabledCipherSuites(enabledCiphers);
}
String requestedProtocols = (String) attributes.get("protocols");
setEnabledProtocols(socket, getEnabledProtocols(socket,
requestedProtocols));
// we don't know if client auth is needed -
// after parsing the request we may re-handshake
if(clientAuthNeed) {
socket.setNeedClientAuth(clientAuthNeed);
} else {
socket.setWantClientAuth(clientAuthWant);
}
}
}
代码示例来源:origin: apache/servicecomb-java-chassis
public static SSLServerSocket createSSLServerSocket(SSLOption option,
SSLCustom custom) {
try {
SSLContext context = createSSLContext(option, custom);
SSLServerSocketFactory factory = context.getServerSocketFactory();
SSLServerSocket socket =
(SSLServerSocket) factory.createServerSocket();
socket.setEnabledProtocols(option.getProtocols().split(","));
String[] supported = socket.getSupportedCipherSuites();
String[] eanbled = option.getCiphers().split(",");
socket.setEnabledCipherSuites(getEnabledCiphers(supported, eanbled));
socket.setNeedClientAuth(option.isAuthPeer());
return socket;
} catch (UnknownHostException e) {
throw new IllegalArgumentException("unkown host");
} catch (IOException e) {
throw new IllegalArgumentException("unable create socket");
}
}
代码示例来源:origin: org.apache.thrift/libthrift
private static TServerSocket createServer(SSLServerSocketFactory factory, int port, int timeout, boolean clientAuth,
InetAddress ifAddress, TSSLTransportParameters params) throws TTransportException {
try {
SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(port, 100, ifAddress);
serverSocket.setSoTimeout(timeout);
serverSocket.setNeedClientAuth(clientAuth);
if (params != null && params.cipherSuites != null) {
serverSocket.setEnabledCipherSuites(params.cipherSuites);
}
return new TServerSocket(new TServerSocket.ServerSocketTransportArgs().
serverSocket(serverSocket).clientTimeout(timeout));
} catch (Exception e) {
throw new TTransportException("Could not bind to port " + port, e);
}
}
代码示例来源:origin: dcm4che/dcm4che
private ServerSocket createTLSServerSocket(Connection conn)
throws IOException, GeneralSecurityException {
SSLContext sslContext = conn.getDevice().sslContext();
SSLServerSocketFactory ssf = sslContext.getServerSocketFactory();
SSLServerSocket ss = (SSLServerSocket) ssf.createServerSocket();
ss.setEnabledProtocols(conn.getTlsProtocols());
ss.setEnabledCipherSuites(conn.getTlsCipherSuites());
ss.setNeedClientAuth(conn.isTlsNeedClientAuth());
return ss;
}
内容来源于网络,如有侵权,请联系作者删除!