Search in sources :

Example 1 with DigilibConfiguration

use of digilib.conf.DigilibConfiguration 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

DigilibConfiguration (digilib.conf.DigilibConfiguration)1 ImageJobDescription (digilib.image.ImageJobDescription)1 DocuDirCache (digilib.io.DocuDirCache)1 DocuDirent (digilib.io.DocuDirent)1 FileOpException (digilib.io.FileOpException)1 MetadataMap (digilib.meta.MetadataMap)1