@Override
 public HttpServerAuthenticationMechanism createAuthenticationMechanism(
     String mechanismName, Map<String, ?> properties, CallbackHandler callbackHandler) {
   for (Provider current : providers.get()) {
     Set<Service> services = current.getServices();
     if (services != null) {
       for (Service currentService : services) {
         if (SERVICE_TYPE.equals(currentService.getType())) {
           try {
             HttpServerAuthenticationMechanismFactory factory =
                 (HttpServerAuthenticationMechanismFactory) currentService.newInstance(null);
             HttpServerAuthenticationMechanism mechanism =
                 factory.createAuthenticationMechanism(mechanismName, properties, callbackHandler);
             if (mechanism != null) {
               return mechanism;
             }
           } catch (NoSuchAlgorithmException e) {
             log.debug(e);
           }
         }
       }
     }
   }
   return null;
 }
Пример #2
0
 static Instance getInstance(String type, Class<?> clazz, String algorithm, String provider)
     throws NoSuchAlgorithmException, NoSuchProviderException {
   Service s = GetInstance.getService(type, algorithm, provider);
   Exception ve = getVerificationResult(s.getProvider());
   if (ve != null) {
     String msg = "JCE cannot authenticate the provider " + provider;
     throw (NoSuchProviderException) new NoSuchProviderException(msg).initCause(ve);
   }
   return GetInstance.getInstance(s, clazz);
 }
Пример #3
0
 static Instance getInstance(String type, Class<?> clazz, String algorithm)
     throws NoSuchAlgorithmException {
   List<Service> services = GetInstance.getServices(type, algorithm);
   NoSuchAlgorithmException failure = null;
   for (Service s : services) {
     if (canUseProvider(s.getProvider()) == false) {
       // allow only signed providers
       continue;
     }
     try {
       Instance instance = GetInstance.getInstance(s, clazz);
       return instance;
     } catch (NoSuchAlgorithmException e) {
       failure = e;
     }
   }
   throw new NoSuchAlgorithmException("Algorithm " + algorithm + " not available", failure);
 }
Пример #4
0
 /**
  * Update the active spi of this class and return the next implementation for failover. If no
  * more implemenations are available, this method returns null. However, the active spi of this
  * class is never set to null.
  */
 private KeyPairGeneratorSpi nextSpi(KeyPairGeneratorSpi oldSpi, boolean reinit) {
   synchronized (lock) {
     // somebody else did a failover concurrently
     // try that spi now
     if ((oldSpi != null) && (oldSpi != spi)) {
       return spi;
     }
     if (serviceIterator == null) {
       return null;
     }
     while (serviceIterator.hasNext()) {
       Service s = serviceIterator.next();
       try {
         Object inst = s.newInstance(null);
         // ignore non-spis
         if (inst instanceof KeyPairGeneratorSpi == false) {
           continue;
         }
         if (inst instanceof KeyPairGenerator) {
           continue;
         }
         KeyPairGeneratorSpi spi = (KeyPairGeneratorSpi) inst;
         if (reinit) {
           if (initType == I_SIZE) {
             spi.initialize(initKeySize, initRandom);
           } else if (initType == I_PARAMS) {
             spi.initialize(initParams, initRandom);
           } else if (initType != I_NONE) {
             throw new AssertionError("KeyPairGenerator initType: " + initType);
           }
         }
         provider = s.getProvider();
         this.spi = spi;
         return spi;
       } catch (Exception e) {
         // ignore
       }
     }
     disableFailover();
     return null;
   }
 }
 @Override
 public String[] getMechanismNames(Map<String, ?> properties) {
   Set<String> mechanismNames = new LinkedHashSet<>();
   for (Provider current : providers.get()) {
     Set<Service> services = current.getServices();
     if (services != null) {
       for (Service currentService : services) {
         if (SERVICE_TYPE.equals(currentService.getType())) {
           try {
             String[] serviceMechNames =
                 ((HttpServerAuthenticationMechanismFactory) currentService.newInstance(null))
                     .getMechanismNames(properties);
             Collections.addAll(mechanismNames, serviceMechNames);
           } catch (NoSuchAlgorithmException e) {
             log.debug(e);
           }
         }
       }
     }
   }
   return mechanismNames.toArray(new String[mechanismNames.size()]);
 }