use of com.disney.http.auth.server.Verifier 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.Verifier 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);
}
use of com.disney.http.auth.server.Verifier in project groovity by disney.
the class VerifierFactory method processPolicy.
private PolicyVerifierImpl processPolicy(@SuppressWarnings("rawtypes") final Map policy, Class<Script> scriptClass) throws MalformedURLException, URISyntaxException, InstantiationException, IllegalAccessException, ClassNotFoundException {
PolicyVerifierImpl verifier = new PolicyVerifierImpl();
processCommon(verifier, policy, scriptClass);
verifier.setPolicyLoader(new Callable<Verifier>() {
String curPolicy = null;
Callable<Verifier> curLoader = null;
public Verifier call() throws Exception {
String loc = resolve(policy, "policy", String.class);
if (!loc.equals(curPolicy)) {
// location has changed, update loaded policy
URI policyURI = null;
if (loc.startsWith("/")) {
URL url = viewResolver.getServletContext().getResource(loc);
if (url != null) {
policyURI = url.toURI();
} else {
ViewPolicyLoader vpl = new ViewPolicyLoader();
vpl.setLocation(loc);
vpl.setViewResolver(viewResolver);
curLoader = vpl;
}
} else {
policyURI = new URI(loc);
}
if (policyURI != null) {
Number ttl = (Number) policy.get("ttl");
// set right loader based on location: view, file, HTTP url or servlet url ...
URIParcel<Verifier> parcel = new URIParcel<Verifier>(Verifier.class, policyURI);
if (ttl != null) {
parcel.setRefresh(ttl.longValue());
}
curLoader = parcel;
}
curPolicy = loc;
}
return curLoader.call();
}
});
return verifier;
}
use of com.disney.http.auth.server.Verifier in project groovity by disney.
the class PolicyVerifierImpl method doVerifyInternal.
@Override
protected VerifierResult doVerifyInternal(ServerAuthorizationRequest request) throws Exception {
Verifier vf = getPolicyLoader().call();
if (vf != null) {
return vf.verify(request);
}
VerifierResult vr = new VerifierResult();
vr.setMessage("No verifier found in loaded auth policy");
return vr;
}
Aggregations