Search in sources :

Example 1 with PolicyVerifierImpl

use of com.disney.http.auth.server.policy.PolicyVerifierImpl 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;
}
Also used : URIParcel(com.disney.uriparcel.URIParcel) PolicyVerifierImpl(com.disney.http.auth.server.policy.PolicyVerifierImpl) AbstractVerifier(com.disney.http.auth.server.AbstractVerifier) Verifier(com.disney.http.auth.server.Verifier) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) MalformedURLException(java.net.MalformedURLException) CertificateException(java.security.cert.CertificateException) URL(java.net.URL)

Aggregations

AbstractVerifier (com.disney.http.auth.server.AbstractVerifier)1 Verifier (com.disney.http.auth.server.Verifier)1 PolicyVerifierImpl (com.disney.http.auth.server.policy.PolicyVerifierImpl)1 URIParcel (com.disney.uriparcel.URIParcel)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1