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 
     34 public class MyTrustManagerFactorySpi extends TrustManagerFactorySpi {
     35     @Override
     36     protected void engineInit(KeyStore ks) throws KeyStoreException {
     37         if (ks == null) {
     38             throw new KeyStoreException("Not supported operation for null KeyStore");
     39         }
     40     }
     41 
     42     @Override
     43     protected void engineInit(ManagerFactoryParameters spec)
     44             throws InvalidAlgorithmParameterException {
     45         if (spec == null) {
     46             throw new InvalidAlgorithmParameterException("Null parameter");
     47         }
     48         if (spec instanceof Parameters) {
     49             try {
     50                 engineInit(((Parameters)spec).getKeyStore());
     51             } catch (KeyStoreException e) {
     52                 throw new RuntimeException(e);
     53             }
     54         } else {
     55             throw new InvalidAlgorithmParameterException("Invalid parameter");
     56         }
     57     }
     58 
     59     @Override
     60     protected TrustManager[] engineGetTrustManagers() {
     61         return null;
     62     }
     63 
     64 
     65     public static class Parameters implements ManagerFactoryParameters {
     66         private KeyStore keyStore;
     67         public Parameters (KeyStore ks) {
     68             this.keyStore = ks;
     69         }
     70         public KeyStore getKeyStore() {
     71             return keyStore;
     72         }
     73     }
     74 }