1 /* 2 * Copyright (c) 2018, 2020, 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 getPeerPrincipal()94 public Principal getPeerPrincipal() 95 throws SSLPeerUnverifiedException { 96 return delegate.getPeerPrincipal(); 97 } 98 getLocalPrincipal()99 public Principal getLocalPrincipal() { 100 return delegate.getLocalPrincipal(); 101 } 102 getCipherSuite()103 public String getCipherSuite() { 104 return delegate.getCipherSuite(); 105 } 106 getProtocol()107 public String getProtocol() { 108 return delegate.getProtocol(); 109 } 110 getPeerHost()111 public String getPeerHost() { 112 return delegate.getPeerHost(); 113 } 114 getPeerPort()115 public int getPeerPort() { 116 return delegate.getPeerPort(); 117 } 118 getPacketBufferSize()119 public int getPacketBufferSize() { 120 return delegate.getPacketBufferSize(); 121 } 122 getApplicationBufferSize()123 public int getApplicationBufferSize() { 124 return delegate.getApplicationBufferSize(); 125 } 126 } 127