1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.internal.net.http.common; 27 28 import java.security.Principal; 29 import java.util.List; 30 import javax.net.ssl.SSLSession; 31 import javax.net.ssl.SSLSessionContext; 32 import javax.net.ssl.SSLPeerUnverifiedException; 33 import javax.net.ssl.SNIServerName; 34 35 /** 36 * All mutating methods throw UnsupportedOperationException 37 */ 38 public class ImmutableSSLSession implements SSLSession { 39 private final SSLSession delegate; 40 ImmutableSSLSession(SSLSession session)41 ImmutableSSLSession(SSLSession session) { 42 this.delegate = session; 43 } 44 getId()45 public byte[] getId() { 46 return delegate.getId(); 47 } 48 getSessionContext()49 public SSLSessionContext getSessionContext() { 50 return delegate.getSessionContext(); 51 } 52 getCreationTime()53 public long getCreationTime() { 54 return delegate.getCreationTime(); 55 } 56 getLastAccessedTime()57 public long getLastAccessedTime() { 58 return delegate.getLastAccessedTime(); 59 } 60 invalidate()61 public void invalidate() { 62 throw new UnsupportedOperationException("session is not mutable"); 63 } 64 isValid()65 public boolean isValid() { 66 return delegate.isValid(); 67 } 68 putValue(String name, Object value)69 public void putValue(String name, Object value) { 70 throw new UnsupportedOperationException("session is not mutable"); 71 } 72 getValue(String name)73 public Object getValue(String name) { 74 return delegate.getValue(name); 75 } 76 removeValue(String name)77 public void removeValue(String name) { 78 throw new UnsupportedOperationException("session is not mutable"); 79 } 80 getValueNames()81 public String [] getValueNames() { 82 return delegate.getValueNames(); 83 } 84 getPeerCertificates()85 public java.security.cert.Certificate [] getPeerCertificates() 86 throws SSLPeerUnverifiedException { 87 return delegate.getPeerCertificates(); 88 } 89 getLocalCertificates()90 public java.security.cert.Certificate [] getLocalCertificates() { 91 return delegate.getLocalCertificates(); 92 } 93 94 @SuppressWarnings("removal") 95 @Deprecated(since="11", forRemoval=true) getPeerCertificateChain()96 public javax.security.cert.X509Certificate [] getPeerCertificateChain() 97 throws SSLPeerUnverifiedException { 98 return delegate.getPeerCertificateChain(); 99 } 100 getPeerPrincipal()101 public Principal getPeerPrincipal() 102 throws SSLPeerUnverifiedException { 103 return delegate.getPeerPrincipal(); 104 } 105 getLocalPrincipal()106 public Principal getLocalPrincipal() { 107 return delegate.getLocalPrincipal(); 108 } 109 getCipherSuite()110 public String getCipherSuite() { 111 return delegate.getCipherSuite(); 112 } 113 getProtocol()114 public String getProtocol() { 115 return delegate.getProtocol(); 116 } 117 getPeerHost()118 public String getPeerHost() { 119 return delegate.getPeerHost(); 120 } 121 getPeerPort()122 public int getPeerPort() { 123 return delegate.getPeerPort(); 124 } 125 getPacketBufferSize()126 public int getPacketBufferSize() { 127 return delegate.getPacketBufferSize(); 128 } 129 getApplicationBufferSize()130 public int getApplicationBufferSize() { 131 return delegate.getApplicationBufferSize(); 132 } 133 } 134