@Override protected KeyPair[] loadKeys() { if (!SecurityUtils.isBouncyCastleRegistered()) { throw new IllegalStateException("BouncyCastle must be registered as a JCE provider"); } List<KeyPair> keys = new ArrayList<KeyPair>(); if (key != null) { try { PEMReader r = new PEMReader(new InputStreamReader(new ByteArrayInputStream(key.getContent()))); try { Object o = r.readObject(); if (o instanceof KeyPair) { keys.add((KeyPair) o); } } finally { r.close(); } } catch (Exception e) { LOG.info("Unable to read key {}: {}", key, e); } } return keys.toArray(new KeyPair[keys.size()]); }
Class<? extends T> getClass(String name) throws NoSuchCommandException, NullPointerException { if (name == null) { throw new NullPointerException("No null argument allowed"); } TimestampedObject<Class<? extends T>> providerRef = classes.get(name); // Resource script = context.loadResource(name, kind); // if (script != null) { if (providerRef != null) { if (script.getTimestamp() != providerRef.getTimestamp()) { providerRef = null; } } // if (providerRef == null) { Class<?> clazz; try { GroovyCodeSource gcs = new GroovyCodeSource(new String(script.getContent(), "UTF-8"), name, "/groovy/shell"); GroovyClassLoader gcl = new GroovyClassLoader(context.getLoader(), config); clazz = gcl.parseClass(gcs, false); } catch (UnsupportedEncodingException e) { throw new NoSuchCommandException( name, ErrorType.INTERNAL, "Could not compile command script " + name, e); } catch (CompilationFailedException e) { throw new NoSuchCommandException( name, ErrorType.INTERNAL, "Could not compile command script " + name, e); } // if (baseClass.isAssignableFrom(clazz)) { Class<? extends T> providerClass = clazz.asSubclass(baseClass); providerRef = new TimestampedObject<Class<? extends T>>(script.getTimestamp(), providerClass); classes.put(name, providerRef); } else { throw new NoSuchCommandException( name, ErrorType.INTERNAL, "Parsed script " + clazz.getName() + " does not implements " + CommandInvoker.class.getName()); } } } // if (providerRef == null) { return null; } // return providerRef.getObject(); }