Search in sources :

Example 1 with DocuDirCache

use of digilib.io.DocuDirCache in project digilib by robcast.

the class DigilibServletConfiguration method configure.

/*
     * (non-Javadoc)
     * 
     * @see digilib.conf.DigilibConfiguration#configure()
     */
@SuppressWarnings("unchecked")
public void configure(ServletContext context) {
    DigilibServletConfiguration config = this;
    super.configure();
    /*
         * configure factories
         */
    try {
        // initialise MetaFactory
        Class<FileMeta> fileMetaClass = (Class<FileMeta>) Class.forName(config.getAsString("filemeta-class"));
        config.setValue("servlet.filemeta.class", fileMetaClass);
        MetaFactory.setFileMetaClass(fileMetaClass);
        Class<DirMeta> dirMetaClass = (Class<DirMeta>) Class.forName(config.getAsString("dirmeta-class"));
        config.setValue("servlet.dirmeta.class", dirMetaClass);
        MetaFactory.setDirMetaClass(dirMetaClass);
    } catch (ClassNotFoundException e) {
        logger.error("Error setting Metadata classes!");
    }
    if (config.getAsBoolean("use-authorization")) {
        try {
            // initialise AuthnOpsFactory
            Class<AuthnOps> authnOpsClass = (Class<AuthnOps>) Class.forName(config.getAsString("authnops-class"));
            config.setValue("servlet.authnops.class", authnOpsClass);
            AuthnOpsFactory.setAuthnOpsClass(authnOpsClass);
        } catch (ClassNotFoundException e) {
            logger.error("Error setting AuthnOps class!");
        }
        try {
            // initialise AuthzOpsFactory
            Class<AuthzOps> authzOpsClass = (Class<AuthzOps>) Class.forName(config.getAsString("authzops-class"));
            config.setValue("servlet.authzops.class", authzOpsClass);
            AuthzOpsFactory.setAuthzOpsClass(authzOpsClass);
        } catch (ClassNotFoundException e) {
            logger.error("Error setting AuthzOps class!");
        }
    }
    try {
        // initialise DocuDirectoryFactory
        Class<DocuDirectory> docuDirectoryClass = (Class<DocuDirectory>) Class.forName(config.getAsString("docudirectory-class"));
        config.setValue("servlet.docudirectory.class", docuDirectoryClass);
        DocuDirectoryFactory.setDocuDirectoryClass(docuDirectoryClass);
        DocuDirectoryFactory.setDigilibConfig(this);
    } catch (ClassNotFoundException e) {
        logger.error("Error setting DocuDirectory class!");
    }
    /*
         * configure singletons
         */
    // set up the logger
    File logConf = ServletOps.getConfigFile((File) config.getValue("log-config-file"), context);
    if (logConf != null && logConf.canRead()) {
        DOMConfigurator.configure(logConf.getAbsolutePath());
        config.setValue("log-config-file", logConf);
    }
    // say hello in the log file
    logger.info("***** Digital Image Library Configuration (version " + getVersion() + ") *****");
    try {
        // directory cache
        DocuDirCache dirCache;
        if (config.getAsBoolean("use-mapping")) {
            // with mapping file
            File mapConf = ServletOps.getConfigFile((File) config.getValue("mapping-file"), context);
            dirCache = new AliasingDocuDirCache(FileClass.IMAGE, mapConf, config);
            config.setValue("mapping-file", mapConf);
        } else {
            // without mapping
            dirCache = new DocuDirCache(FileClass.IMAGE, this);
        }
        config.setValue(DIR_CACHE_KEY, dirCache);
        // useAuthorization
        if (config.getAsBoolean("use-authorization")) {
            // set auth config file
            File authConf = ServletOps.getConfigFile((File) config.getValue("auth-file"), context);
            config.setValue("auth-file", authConf);
            // initialise AuthnOps
            AuthnOps authnOps = AuthnOpsFactory.getAuthnOpsInstance();
            authnOps.init(this);
            config.setValue(AUTHN_OP_KEY, authnOps);
            // initialise AuthzOps (requires AuthnOps)
            AuthzOps authzOps = AuthzOpsFactory.getAuthzOpsInstance();
            authzOps.init(this);
            config.setValue(AUTHZ_OP_KEY, authzOps);
        }
        // digilib worker threads
        int nt = config.getAsInt("worker-threads");
        int mt = config.getAsInt("max-waiting-threads");
        DigilibJobCenter<DocuImage> imageExecutor = new DigilibJobCenter<DocuImage>(nt, mt, false, IMAGEEXECUTOR_KEY);
        config.setValue(IMAGEEXECUTOR_KEY, imageExecutor);
        /*
             * set as the servlets main config
             */
        setContextConfig(context);
    } catch (Exception e) {
        logger.error("Error configuring digilib servlet:", e);
    }
}
Also used : AliasingDocuDirCache(digilib.io.AliasingDocuDirCache) AuthnOps(digilib.auth.AuthnOps) AuthzOps(digilib.auth.AuthzOps) DocuImage(digilib.image.DocuImage) DigilibJobCenter(digilib.util.DigilibJobCenter) DirMeta(digilib.meta.DirMeta) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) DocuDirectory(digilib.io.DocuDirectory) AliasingDocuDirCache(digilib.io.AliasingDocuDirCache) DocuDirCache(digilib.io.DocuDirCache) FileClass(digilib.io.FileOps.FileClass) File(java.io.File) FileMeta(digilib.meta.FileMeta)

Example 2 with DocuDirCache

use of digilib.io.DocuDirCache in project digilib by robcast.

the class TextServletConfiguration method configure.

/*
     * (non-Javadoc)
     * 
     * @see digilib.conf.DigilibServletConfiguration#configure(javax.servlet.
     * ServletContext)
     */
@Override
public void configure(ServletContext context) {
    super.configure(context);
    DigilibServletConfiguration config = this;
    // set version
    setValue("servlet.version", getVersion());
    try {
        // directory cache for text files
        DocuDirCache dirCache;
        if (config.getAsBoolean("use-mapping")) {
            // with mapping file
            File mapConf = ServletOps.getConfigFile((File) config.getValue("mapping-file"), context);
            dirCache = new AliasingDocuDirCache(FileClass.TEXT, mapConf, config);
            config.setValue("mapping-file", mapConf);
        } else {
            // without mapping
            dirCache = new DocuDirCache(FileClass.TEXT, this);
        }
        config.setValue(TEXT_DIR_CACHE_KEY, dirCache);
    } catch (Exception e) {
        logger.error("Error configuring digilib servlet:", e);
    }
}
Also used : AliasingDocuDirCache(digilib.io.AliasingDocuDirCache) AliasingDocuDirCache(digilib.io.AliasingDocuDirCache) DocuDirCache(digilib.io.DocuDirCache) File(java.io.File)

Example 3 with DocuDirCache

use of digilib.io.DocuDirCache in project digilib by robcast.

the class MetaAccessAuthzOps method rolesForPath.

/**
 * Return authorization roles needed for request.
 *
 * Returns the list of authorization roles that are needed to access the
 * specified path. No list means the path is free.
 *
 * The location information of the request is also considered.
 *
 * @param request
 *            ServletRequest with address information.
 * @throws AuthOpException
 *             Exception thrown on error.
 * @return List of Strings with role names.
 */
@Override
public List<String> rolesForPath(DigilibServletRequest dlRequest) throws AuthOpException {
    DocuDirent imgs;
    try {
        // try to get image file from JobDescription
        ImageJobDescription ticket = dlRequest.getJobDescription();
        if (ticket != null) {
            imgs = (DocuDirent) ticket.getImageSet();
        } else {
            // try to get image file from DirCache
            DigilibConfiguration config = dlRequest.getDigilibConfig();
            DocuDirCache cache = (DocuDirCache) config.getValue(DigilibServletConfiguration.DIR_CACHE_KEY);
            imgs = cache.getFile(dlRequest.getFilePath(), dlRequest.getAsInt("pn"));
        }
    } catch (FileOpException e) {
        throw new AuthOpException("No file for auth check!");
    }
    /*
         * get access restrictions from metadata
         */
    String access = null;
    try {
        imgs.checkMeta();
        MetadataMap meta = imgs.getMeta().getFileMeta();
        if (meta != null) {
            access = meta.get("access");
        }
    } catch (Exception e) {
        logger.error("Error getting access meta for file!");
    }
    if (access == null) {
        // no access tag - use default
        logger.debug("Roles required for " + imgs.getName() + ": " + defaultRoles + "(default)");
        return defaultRoles;
    } else if (access.equalsIgnoreCase("free")) {
        // access free
        logger.debug("Roles required for " + imgs.getName() + ": (free)");
        return null;
    }
    // get required roles
    if (rolesMap.containsKey(access)) {
        List<String> required = rolesMap.get(access);
        logger.debug("Roles required for " + imgs.getName() + ": " + required);
        return required;
    } else {
        // no mapping to role
        logger.error("Error: no role for access type '" + access + "'");
        // use default
        logger.debug("Roles required for " + imgs.getName() + ": " + defaultRoles + "(substituted default)");
        return defaultRoles;
    }
}
Also used : MetadataMap(digilib.meta.MetadataMap) ImageJobDescription(digilib.image.ImageJobDescription) DigilibConfiguration(digilib.conf.DigilibConfiguration) FileOpException(digilib.io.FileOpException) DocuDirent(digilib.io.DocuDirent) DocuDirCache(digilib.io.DocuDirCache) FileOpException(digilib.io.FileOpException)

Aggregations

DocuDirCache (digilib.io.DocuDirCache)3 AliasingDocuDirCache (digilib.io.AliasingDocuDirCache)2 File (java.io.File)2 AuthnOps (digilib.auth.AuthnOps)1 AuthzOps (digilib.auth.AuthzOps)1 DigilibConfiguration (digilib.conf.DigilibConfiguration)1 DocuImage (digilib.image.DocuImage)1 ImageJobDescription (digilib.image.ImageJobDescription)1 DocuDirectory (digilib.io.DocuDirectory)1 DocuDirent (digilib.io.DocuDirent)1 FileOpException (digilib.io.FileOpException)1 FileClass (digilib.io.FileOps.FileClass)1 DirMeta (digilib.meta.DirMeta)1 FileMeta (digilib.meta.FileMeta)1 MetadataMap (digilib.meta.MetadataMap)1 DigilibJobCenter (digilib.util.DigilibJobCenter)1 IOException (java.io.IOException)1 SAXException (org.xml.sax.SAXException)1