本文整理汇总了Java中javax.net.ssl.SSLServerSocket.setWantClientAuth方法的典型用法代码示例。如果您正苦于以下问题:Java SSLServerSocket.setWantClientAuth方法的具体用法?Java SSLServerSocket.setWantClientAuth怎么用?Java SSLServerSocket.setWantClientAuth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.net.ssl.SSLServerSocket
的用法示例。
在下文中一共展示了SSLServerSocket.setWantClientAuth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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]);
}
}
}
示例2: 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;
}
示例3: 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();
}
示例4: 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;
}
示例5: 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;
}
示例6: test_WantClientAuth
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
* @throws IOException
* @tests javax.net.ssl.SSLServerSocket#setWantClientAuth(boolean want)
* @tests javax.net.ssl.SSLServerSocket#getWantClientAuthCreation()
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getWantClientAuth",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "setWantClientAuth",
args = {boolean.class}
)
})
public void test_WantClientAuth() throws Exception {
SSLServerSocket sss = getSSLServerSocket();
sss.setWantClientAuth(true);
assertTrue(sss.getWantClientAuth());
sss.setWantClientAuth(false);
assertFalse(sss.getWantClientAuth());
}
示例7: open
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
@Override
public ServerChannel open(InetAddress address, int port, int timeout)
throws IOException
{
SSLServerSocket sock =
(SSLServerSocket) _factory.createServerSocket(port,
_backlog, address);
try {
sock.setReuseAddress(_isReuseAddress);
sock.setWantClientAuth(_isWantClientAuth);
return new SSLServerChannel(sock, timeout);
} catch (Throwable t) {
if (!sock.isClosed()) {
try {
sock.close();
} catch (Throwable tt) {
t.addSuppressed(tt);
}
}
throw t;
}
}
示例8: testSetGetNeedClientAuth
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
* setNeedClientAuth(boolean need) method testing.
* getNeedClientAuth() method testing.
*/
public void testSetGetNeedClientAuth() throws Exception {
SSLServerSocket ssocket = createSSLServerSocket();
ssocket.setWantClientAuth(true);
ssocket.setNeedClientAuth(false);
assertFalse("Result does not correspond to expected",
ssocket.getNeedClientAuth());
assertFalse("Socket did not reset its want client auth state",
ssocket.getWantClientAuth());
ssocket.setWantClientAuth(true);
ssocket.setNeedClientAuth(true);
assertTrue("Result does not correspond to expected",
ssocket.getNeedClientAuth());
assertFalse("Socket did not reset its want client auth state",
ssocket.getWantClientAuth());
}
示例9: 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());
}
示例10: 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);
}
}
示例11: JSSEServer
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
JSSEServer(CipherTest cipherTest) throws Exception {
super(cipherTest);
SSLContext serverContext = SSLContext.getInstance("TLS");
serverContext.init(
new KeyManager[] { CipherTest.keyManager },
new TrustManager[] { CipherTest.trustManager },
CipherTest.secureRandom);
SSLServerSocketFactory factory = (SSLServerSocketFactory)serverContext.getServerSocketFactory();
serverSocket = (SSLServerSocket)factory.createServerSocket(0);
serverSocket.setSoTimeout(CipherTest.TIMEOUT);
CipherTest.serverPort = serverSocket.getLocalPort();
serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites());
serverSocket.setWantClientAuth(true);
}
示例12: JSSEServer
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
JSSEServer(CipherTest cipherTest) throws Exception {
super(cipherTest);
SSLContext serverContext = SSLContext.getInstance("TLS");
serverContext.init(new KeyManager[] {cipherTest.keyManager}, new TrustManager[] {cipherTest.trustManager}, cipherTest.secureRandom);
SSLServerSocketFactory factory = (SSLServerSocketFactory)serverContext.getServerSocketFactory();
serverSocket = (SSLServerSocket)factory.createServerSocket(0);
cipherTest.serverPort = serverSocket.getLocalPort();
serverSocket.setEnabledCipherSuites(factory.getSupportedCipherSuites());
serverSocket.setWantClientAuth(true);
}
示例13: getSSLServerSocketFactorySSLServerSocketConfigurers
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
@Override
protected List<Configurer<SSLServerSocket>> getSSLServerSocketFactorySSLServerSocketConfigurers(SSLContext context) {
List<Configurer<SSLServerSocket>> sslServerSocketConfigurers =
super.getSSLServerSocketFactorySSLServerSocketConfigurers(context);
if (this.getClientAuthentication() != null) {
final ClientAuthentication clientAuthValue =
ClientAuthentication.valueOf(this.parsePropertyValue(this.getClientAuthentication()));
Configurer<SSLServerSocket> sslServerSocketConfigurer = new Configurer<SSLServerSocket>() {
@Override
public SSLServerSocket configure(SSLServerSocket socket) {
LOG.trace("Configuring client-auth on SSLServerSocket [{}] to [{}].", socket, clientAuthValue);
switch (clientAuthValue) {
case NONE:
socket.setWantClientAuth(false);
socket.setNeedClientAuth(false);
break;
case WANT:
socket.setWantClientAuth(true);
break;
case REQUIRE:
socket.setNeedClientAuth(true);
break;
default:
throw new RuntimeCamelException("Unknown ClientAuthentication value: " + clientAuthValue);
}
return socket;
}
};
sslServerSocketConfigurers.add(sslServerSocketConfigurer);
}
return sslServerSocketConfigurers;
}
示例14: create
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
/**
* Creates the SSL ServerSocket.
*/
public ServerSocketBar create(InetAddress host, int port)
throws IOException, GeneralSecurityException
{
SSLServerSocketFactory ssFactory = null;
if (_keyStore != null) {
SSLContext sslContext = SSLContext.getInstance(_sslContext);
KeyManagerFactory kmf
= KeyManagerFactory.getInstance(keyManagerFactory());
kmf.init(_keyStore, keyStorePassword().toCharArray());
sslContext.init(kmf.getKeyManagers(), null, null);
/*
if (_cipherSuites != null)
sslContext.createSSLEngine().setEnabledCipherSuites(_cipherSuites);
if (_protocols != null)
sslContext.createSSLEngine().setEnabledProtocols(_protocols);
*/
SSLEngine engine = sslContext.createSSLEngine();
engine.setEnabledProtocols(enabledProtocols(engine.getSupportedProtocols()));
ssFactory = sslContext.getServerSocketFactory();
}
else {
ssFactory = createAnonymousServerFactory(host, port);
}
ServerSocket serverSocket;
int listen = 100;
if (host == null)
serverSocket = ssFactory.createServerSocket(port, listen);
else
serverSocket = ssFactory.createServerSocket(port, listen, host);
SSLServerSocket sslServerSocket = (SSLServerSocket) serverSocket;
if (_cipherSuites != null) {
sslServerSocket.setEnabledCipherSuites(_cipherSuites);
}
if (_cipherSuitesForbidden != null) {
String []cipherSuites = sslServerSocket.getEnabledCipherSuites();
if (cipherSuites == null)
cipherSuites = sslServerSocket.getSupportedCipherSuites();
ArrayList<String> cipherList = new ArrayList<String>();
for (String cipher : cipherSuites) {
if (! isCipherForbidden(cipher, _cipherSuitesForbidden)) {
cipherList.add(cipher);
}
}
cipherSuites = new String[cipherList.size()];
cipherList.toArray(cipherSuites);
sslServerSocket.setEnabledCipherSuites(cipherSuites);
}
sslServerSocket.setEnabledProtocols(enabledProtocols(sslServerSocket.getSupportedProtocols()));
if ("required".equals(_verifyClient))
sslServerSocket.setNeedClientAuth(true);
else if ("optional".equals(_verifyClient))
sslServerSocket.setWantClientAuth(true);
return new ServerSocketWrapper(serverSocket);
}
示例15: run
import javax.net.ssl.SSLServerSocket; //导入方法依赖的package包/类
public void run() {
try {
store = provideKeys ? getKeyStore(keys) : null;
KeyManager[] keyManagers = store != null ? getKeyManagers(store) : null;
TrustManager[] trustManagers = new TrustManager[] { trustManager };
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, trustManagers, null);
SSLServerSocket serverSocket = (SSLServerSocket)sslContext
.getServerSocketFactory().createServerSocket();
if (clientAuth == CLIENT_AUTH_WANTED) {
serverSocket.setWantClientAuth(true);
} else if (clientAuth == CLIENT_AUTH_NEEDED) {
serverSocket.setNeedClientAuth(true);
} else {
serverSocket.setWantClientAuth(false);
}
serverSocket.bind(new InetSocketAddress(port));
SSLSocket clientSocket = (SSLSocket)serverSocket.accept();
InputStream istream = clientSocket.getInputStream();
byte[] buffer = new byte[1024];
istream.read(buffer);
OutputStream ostream = clientSocket.getOutputStream();
ostream.write(testData.getBytes());
ostream.flush();
while (notFinished) {
Thread.currentThread().sleep(500);
}
clientSocket.close();
serverSocket.close();
} catch (Exception ex) {
exception = ex;
}
}