本文整理汇总了Java中javax.net.ssl.SSLServerSocket.setNeedClientAuth方法的典型用法代码示例。如果您正苦于以下问题:Java SSLServerSocket.setNeedClientAuth方法的具体用法?Java SSLServerSocket.setNeedClientAuth怎么用?Java SSLServerSocket.setNeedClientAuth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.net.ssl.SSLServerSocket
的用法示例。
在下文中一共展示了SSLServerSocket.setNeedClientAuth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: finishServerSocket
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
* 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);
}
}
示例2: configureServerSocket
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
* Set the server socket configuration to our required
* QOS values.
*
* A small experiment shows that setting either (want, need) parameter to either true or false sets the
* other parameter to false.
*
* @param serverSocket
* The newly created SSLServerSocket.
*
* @throws IOException if server socket can't be configured
*/
private void configureServerSocket(SSLServerSocket serverSocket) throws IOException {
// set the authentication value and cipher suite info.
serverSocket.setEnabledCipherSuites(cipherSuites);
if (clientAuthRequired) {
serverSocket.setNeedClientAuth(true);
} else if (clientAuthSupported) {
serverSocket.setWantClientAuth(true);
} else {
serverSocket.setNeedClientAuth(false); //could set want with the same effect
}
serverSocket.setSoTimeout(SOCKET_TIMEOUT_MS);
if (log.isDebugEnabled()) {
log.debug("Created SSL server socket on port " + serverSocket.getLocalPort());
log.debug(" client authentication " + (clientAuthSupported ? "SUPPORTED" : "UNSUPPORTED"));
log.debug(" client authentication " + (clientAuthRequired ? "REQUIRED" : "OPTIONAL"));
log.debug(" cipher suites:");
for (int i = 0; i < cipherSuites.length; i++) {
log.debug(" " + cipherSuites[i]);
}
}
}
示例3: doServerSide
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
void doServerSide() throws Exception {
SSLServerSocketFactory sslssf = getSSLServerSF();
SSLServerSocket sslServerSocket =
(SSLServerSocket) sslssf.createServerSocket(serverPort);
// require client authentication.
sslServerSocket.setNeedClientAuth(true);
serverPort = sslServerSocket.getLocalPort();
/*
* Signal Client, we're ready for his connect.
*/
serverReady = true;
SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
InputStream sslIS = sslSocket.getInputStream();
OutputStream sslOS = sslSocket.getOutputStream();
sslIS.read();
sslOS.write('A');
sslOS.flush();
sslSocket.close();
}
示例4: newSslServerSocket
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
public SSLServerSocket newSslServerSocket(String host,int port,int backlog) throws IOException {
SSLServerSocketFactory factory = sslContext.getServerSocketFactory();
SSLServerSocket socket =
(SSLServerSocket) (host==null ?
factory.createServerSocket(port, backlog):
factory.createServerSocket(port, backlog, InetAddress.getByName(host)));
if (sslConfig.getWantClientAuth())
socket.setWantClientAuth(sslConfig.getWantClientAuth());
if (sslConfig.getNeedClientAuth())
socket.setNeedClientAuth(sslConfig.getNeedClientAuth());
socket.setEnabledCipherSuites(selectCipherSuites(socket.getEnabledCipherSuites(),
socket.getSupportedCipherSuites()));
socket.setEnabledProtocols(selectProtocols(socket.getEnabledProtocols(),socket.getSupportedProtocols()));
return socket;
}
示例5: start
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
* Starts this test server.
*/
public void start() throws Exception {
Asserts.check(servicedSocket == null, "Already running");
final ServerSocket ssock;
if (sslcontext != null) {
final SSLServerSocketFactory sf = sslcontext.getServerSocketFactory();
final SSLServerSocket sslsock = (SSLServerSocket) sf.createServerSocket();
if (forceSSLAuth) {
sslsock.setNeedClientAuth(true);
} else {
sslsock.setWantClientAuth(true);
}
ssock = sslsock;
} else {
ssock = new ServerSocket();
}
ssock.setReuseAddress(true); // probably pointless for port '0'
ssock.bind(TEST_SERVER_ADDR);
servicedSocket = ssock;
listenerThread = new ListenerThread();
listenerThread.setDaemon(false);
listenerThread.start();
}
示例6: createServer
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
private static GfxdTSSLServerSocket createServer(
SSLServerSocketFactory factory, InetSocketAddress bindAddress,
SocketParameters params) throws TTransportException {
try {
SSLServerSocket serverSocket = (SSLServerSocket)factory
.createServerSocket(bindAddress.getPort(), 100,
bindAddress.getAddress());
if (params != null) {
if (params.getSSLEnabledProtocols() != null) {
serverSocket.setEnabledProtocols(params.getSSLEnabledProtocols());
}
if (params.getSSLCipherSuites() != null) {
serverSocket.setEnabledCipherSuites(params.getSSLCipherSuites());
}
serverSocket.setNeedClientAuth(params.getSSLClientAuth());
}
return new GfxdTSSLServerSocket(serverSocket, bindAddress, params);
} catch (Exception e) {
throw new TTransportException(TTransportException.NOT_OPEN,
"Could not bind to host:port " + bindAddress.toString(), e);
}
}
示例7: initSslServerSocket
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
* Initializes the SSL server socket. Configures the certificate request
* (need or want) and the enabled cipher suites.
*
* @param sslServerSocket
* The server socket to initialize.
* @return The initialized server socket.
*/
protected SSLServerSocket initSslServerSocket(
SSLServerSocket sslServerSocket) {
if (getContextFactory().isNeedClientAuthentication()) {
sslServerSocket.setNeedClientAuth(true);
} else if (getContextFactory().isWantClientAuthentication()) {
sslServerSocket.setWantClientAuth(true);
}
if ((getContextFactory().getEnabledCipherSuites() != null)
|| (getContextFactory().getDisabledCipherSuites() != null)) {
sslServerSocket.setEnabledCipherSuites(getContextFactory()
.getSelectedCipherSuites(
sslServerSocket.getSupportedCipherSuites()));
}
if ((getContextFactory().getEnabledProtocols() != null)
|| (getContextFactory().getDisabledProtocols() != null)) {
sslServerSocket.setEnabledProtocols(getContextFactory()
.getSelectedSslProtocols(
sslServerSocket.getSupportedProtocols()));
}
return sslServerSocket;
}
示例8: newSslServerSocket
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
public SSLServerSocket newSslServerSocket(String host,int port,int backlog) throws IOException
{
SSLServerSocketFactory factory = _context.getServerSocketFactory();
SSLServerSocket socket =
(SSLServerSocket) (host==null ?
factory.createServerSocket(port,backlog):
factory.createServerSocket(port,backlog,InetAddress.getByName(host)));
if (getWantClientAuth())
socket.setWantClientAuth(getWantClientAuth());
if (getNeedClientAuth())
socket.setNeedClientAuth(getNeedClientAuth());
socket.setEnabledCipherSuites(selectCipherSuites(
socket.getEnabledCipherSuites(),
socket.getSupportedCipherSuites()));
socket.setEnabledProtocols(selectProtocols(socket.getEnabledProtocols(),socket.getSupportedProtocols()));
return socket;
}
示例9: test_NeedClientAuth
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
* @throws IOException
* @tests javax.net.ssl.SSLServerSocket#setNeedClientAuth(boolean need)
* @tests javax.net.ssl.SSLServerSocket#getNeedClientAuthCreation()
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setNeedClientAuth",
args = {boolean.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getNeedClientAuth",
args = {}
)
})
public void test_NeedClientAuth() throws Exception {
SSLServerSocket sss = getSSLServerSocket();
sss.setNeedClientAuth(true);
assertTrue(sss.getNeedClientAuth());
sss.setNeedClientAuth(false);
assertFalse(sss.getNeedClientAuth());
}
示例10: TestAmqpPeerRunner
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
public TestAmqpPeerRunner(TestAmqpPeer peer, SSLContext sslContext, boolean needClientCert) throws IOException
{
int port = useFixedPort ? PORT : 0;
this.needClientCert = needClientCert;
if (sslContext == null)
{
_serverSocket = new ServerSocket(port);
}
else
{
SSLServerSocketFactory socketFactory = sslContext.getServerSocketFactory();
_serverSocket = socketFactory.createServerSocket(port);
SSLServerSocket sslServerSocket = (SSLServerSocket) _serverSocket;
if (this.needClientCert)
{
sslServerSocket.setNeedClientAuth(true);
}
}
_testFrameParser = new TestFrameParser(peer);
_peer = peer;
}
示例11: testSetGetWantClientAuth
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
* setWantClientAuth(boolean want) method testing.
* getWantClientAuth() method testing.
*/
public void testSetGetWantClientAuth() throws Exception {
SSLServerSocket ssocket = createSSLServerSocket();
ssocket.setNeedClientAuth(true);
ssocket.setWantClientAuth(false);
assertFalse("Result does not correspond to expected",
ssocket.getWantClientAuth());
assertFalse("Socket did not reset its want client auth state",
ssocket.getNeedClientAuth());
ssocket.setNeedClientAuth(true);
ssocket.setWantClientAuth(true);
assertTrue("Result does not correspond to expected",
ssocket.getWantClientAuth());
assertFalse("Socket did not reset its want client auth state",
ssocket.getNeedClientAuth());
}
示例12: createServerSocket
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
private ServerSocket createServerSocket( int port , int tcpBackLog , InetAddress localAddr , boolean useSSL ) throws JMSException
{
try
{
if (useSSL)
{
SSLServerSocket socket = (SSLServerSocket)createSSLContext().getServerSocketFactory().createServerSocket(port,tcpBackLog,localAddr);
socket.setNeedClientAuth(false);
return socket;
}
else
return new ServerSocket(port,tcpBackLog,localAddr);
}
catch (Exception e)
{
throw new FFMQException("Cannot create server socket","NETWORK_ERROR",e);
}
}
示例13: createServerSocket
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
@Override
public ServerSocket createServerSocket(int port) throws IOException {
SSLServerSocket sslServerSocket =
(SSLServerSocket) sslServerSocketFactory.createServerSocket(port, 0, bindAddress);
if (getEnabledCipherSuites() != null) {
sslServerSocket.setEnabledCipherSuites(getEnabledCipherSuites());
}
if (getEnabledProtocols() == null) {
sslServerSocket.setEnabledProtocols(defaultProtocols);
} else {
sslServerSocket.setEnabledProtocols(getEnabledProtocols());
}
sslServerSocket.setNeedClientAuth(getNeedClientAuth());
return sslServerSocket;
}
示例14: configureClientAuth
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
* Configure Client authentication for this version of JSSE. The
* JSSE included in Java 1.4 supports the 'want' value. Prior
* versions of JSSE will treat 'want' as 'false'.
* @param socket the SSLServerSocket
*/
protected void configureClientAuth(SSLServerSocket socket){
if (wantClientAuth){
socket.setWantClientAuth(wantClientAuth);
} else {
socket.setNeedClientAuth(requireClientAuth);
}
}
示例15: init
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
public void init() throws Exception {
//这个类是原生包中的SSL连接的上下文类
SSLContext context = SSLContext.getInstance("SSL");
//服务器端证书库
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream keystoreFis = new FileInputStream(keystorePath);
keystore.load(keystoreFis, keystorePassword.toCharArray());
//信任证书库
KeyStore trustKeystore = KeyStore.getInstance("jks");
FileInputStream trustKeystoreFis = new FileInputStream(trustKeystorePath);
trustKeystore.load(trustKeystoreFis, truststorePassword.toCharArray());
//密钥库
KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509");
kmf.init(keystore, keystorePassword.toCharArray());
//信任库
TrustManagerFactory tmf = TrustManagerFactory.getInstance("sunx509");
tmf.init(trustKeystore);
//初始化SSL上下文
context.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
//初始化SSLSocket
sslServerSocket = (SSLServerSocket)context.getServerSocketFactory().createServerSocket(port);
//设置这个SSLServerSocket需要授权的客户端访问
sslServerSocket.setNeedClientAuth(true);
keystoreFis.close();
trustKeystoreFis.close();
System.out.println("SSLServer initialized.");
}