下面列出了javax.net.ssl.SSLSession#getLocalPrincipal ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Opens a WebSocket to the server
*
* @throws Exception complete exceptionally with one of the following errors:
* <ul>
* <li>{@link IOException} - if an I/O error occurs
* <li>{@link WebSocketHandshakeException} - if the opening handshake fails
* <li>{@link HttpTimeoutException} - if the opening handshake does not complete within
* the timeout
* <li>{@link InterruptedException} - if the operation is interrupted
* <li>{@link SecurityException} - if a security manager has been installed and it denies
* {@link java.net.URLPermission access} to {@code uri}.
* <a href="HttpRequest.html#securitychecks">Security checks</a> contains more information
* relating to the security context in which the the listener is invoked.
* <li>{@link IllegalArgumentException} - if any of the arguments to the constructor are
* invalid
* </ul>
*
*/
public void open() throws Exception {
while (!connectedCriticalSection.compareAndSet(false, true)) {
Thread.yield();
}
try {
if (webSocket == null) {
final HttpClient httpClient = HttpClient.newHttpClient();
webSocket = httpClient.newWebSocketBuilder().subprotocols(subprotocol)
.connectTimeout(Duration.ofSeconds(timeoutSeconds)).buildAsync(uri, listener).get();
final SSLSessionContext clientSessionContext =
httpClient.sslContext().getClientSessionContext();
byte[] id = clientSessionContext.getIds().nextElement();
SSLSession sslSession = clientSessionContext.getSession(id);
Principal principal = sslSession.getLocalPrincipal();
source = (null != principal) ? principal.getName() : new String(id);
}
} finally {
connectedCriticalSection.compareAndSet(true, false);
}
}
public void setSSLSession(SSLSession sslsession) {
session = sslsession;
synchronized (sessionLock) {
sslState = sslsession.getLocalPrincipal();
sslURL = url;
sessionLock.notifyAll();
}
}
public RecordedRequest(String requestLine, List<String> headers, List<Integer> chunkSizes,
int bodySize, byte[] body, int sequenceNumber, Socket socket) {
this.requestLine = requestLine;
this.headers = headers;
this.chunkSizes = chunkSizes;
this.bodySize = bodySize;
this.body = body;
this.sequenceNumber = sequenceNumber;
if (socket instanceof SSLSocket) {
SSLSocket sslSocket = (SSLSocket) socket;
SSLSession session = sslSocket.getSession();
sslProtocol = session.getProtocol();
sslCipherSuite = session.getCipherSuite();
sslLocalPrincipal = session.getLocalPrincipal();
sslLocalCertificates = session.getLocalCertificates();
Principal peerPrincipal = null;
Certificate[] peerCertificates = null;
try {
peerPrincipal = session.getPeerPrincipal();
peerCertificates = session.getPeerCertificates();
} catch (SSLPeerUnverifiedException e) {
// No-op: use nulls instead
}
sslPeerPrincipal = peerPrincipal;
sslPeerCertificates = peerCertificates;
} else {
sslProtocol = null;
sslCipherSuite = null;
sslLocalPrincipal = null;
sslLocalCertificates = null;
sslPeerPrincipal = null;
sslPeerCertificates = null;
}
if (requestLine != null) {
int methodEnd = requestLine.indexOf(' ');
int pathEnd = requestLine.indexOf(' ', methodEnd + 1);
this.method = requestLine.substring(0, methodEnd);
this.path = requestLine.substring(methodEnd + 1, pathEnd);
} else {
this.method = null;
this.path = null;
}
}