Home | History | Annotate | Download | only in ssl
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 /**
     19  * @author Vera Y. Petrashkova
     20  */
     21 
     22 package javax.net.ssl;
     23 
     24 import java.security.InvalidAlgorithmParameterException;
     25 import java.security.KeyStore;
     26 import java.security.KeyStoreException;
     27 
     28 /**
     29  * Class for vertifying TrustManagerFactorySpi and TrustManagerFactory
     30  * functionality
     31  */
     32 
     33 public class MyTrustManagerFactorySpi extends TrustManagerFactorySpi {
     34     @Override
     35     protected void engineInit(KeyStore ks) throws KeyStoreException {
     36         if (ks == null) {
     37             throw new KeyStoreException("Not supported operation for null KeyStore");
     38         }
     39     }
     40 
     41     @Override
     42     protected void engineInit(ManagerFactoryParameters spec)
     43             throws InvalidAlgorithmParameterException {
     44         if (spec == null) {
     45             throw new InvalidAlgorithmParameterException("Null parameter");
     46         }
     47         if (spec instanceof Parameters) {
     48             try {
     49                 engineInit(((Parameters) spec).getKeyStore());
     50             } catch (KeyStoreException e) {
     51                 throw new RuntimeException(e);
     52             }
     53         } else {
     54             throw new InvalidAlgorithmParameterException("Invalid parameter");
     55         }
     56     }
     57 
     58     @Override
     59     protected TrustManager[] engineGetTrustManagers() {
     60         return null;
     61     }
     62 
     63 
     64     public static class Parameters implements ManagerFactoryParameters {
     65         private KeyStore keyStore;
     66 
     67         public Parameters(KeyStore ks) {
     68             this.keyStore = ks;
     69         }
     70 
     71         public KeyStore getKeyStore() {
     72             return keyStore;
     73         }
     74     }
     75 }