use of com.disney.http.auth.server.VerifierChain in project groovity by disney.
the class VerifierFactory method createVerifier.
@SuppressWarnings("rawtypes")
public Verifier createVerifier(List auths, Class<Script> scriptClass) throws InstantiationException, IllegalAccessException, ClassNotFoundException, MalformedURLException, URISyntaxException, NoSuchAlgorithmException, InvalidKeySpecException, CertificateException {
ArrayList<Verifier> verifiers = new ArrayList<Verifier>(auths.size());
for (Object auth : auths) {
if (auth instanceof Map) {
Map conf = (Map) auth;
Object policy = conf.get("policy");
if (policy != null) {
verifiers.add(processPolicy(conf, scriptClass));
} else {
String type = (String) conf.get("type");
if ("signature".equals(type)) {
verifiers.add(processSignature(conf, scriptClass));
} else if ("basic".equals(type)) {
verifiers.add(processBasic(conf, scriptClass));
} else if ("digest".equals(type)) {
verifiers.add(processDigest(conf, scriptClass));
} else {
throw new IllegalArgumentException("Unkown auth type: " + type);
}
}
} else if (auth instanceof CharSequence) {
verifiers.add((Verifier) fallbackConstruct(auth, scriptClass));
} else if (auth instanceof Closure) {
verifiers.add(new Verifier() {
@Override
public VerifierResult verify(ServerAuthorizationRequest request) throws Exception {
Object result = ((Closure) auth).call(request);
if (!(result instanceof VerifierResult)) {
result = DefaultTypeTransformation.castToType(result, VerifierResult.class);
}
return (VerifierResult) result;
}
});
}
}
return new VerifierChain(verifiers);
}
use of com.disney.http.auth.server.VerifierChain in project groovity by disney.
the class XmlPolicyParser method parsePolicy.
public static Verifier parsePolicy(InputSource source, ServletContext servletContext) throws SAXException, ParserConfigurationException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchAlgorithmException, InvalidKeySpecException, URISyntaxException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(false);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
// System.out.println("Getting entity for "+systemId);
if (systemId.endsWith("auth.dtd")) {
return new InputSource(XmlPolicyParser.class.getResourceAsStream("/auth.dtd"));
}
return null;
}
});
Document doc = builder.parse(source);
List<Verifier> configs = new ArrayList<Verifier>();
NodeList cnodes = doc.getDocumentElement().getChildNodes();
for (int i = 0; i < cnodes.getLength(); i++) {
Node cnode = cnodes.item(i);
if (cnode instanceof Element) {
Element cel = (Element) cnode;
if (cel.getNodeName().equals("basic")) {
configs.add(processBasic(cel));
} else if (cel.getNodeName().equals("signature")) {
configs.add(processSignature(cel, servletContext));
} else if (cel.getNodeName().equals("digest")) {
configs.add(processDigest(cel));
}
}
}
if (configs.size() == 0) {
return null;
}
if (configs.size() == 1) {
return configs.get(0);
}
return new VerifierChain(configs);
}
Aggregations