Search in sources :

Example 1 with LocalPolicy

use of org.freshcookies.security.policy.LocalPolicy in project jspwiki by apache.

the class AuthorizationManager method initialize.

/**
 * Initializes AuthorizationManager with an engine and set of properties.
 * Expects to find property 'jspwiki.authorizer' with a valid Authorizer
 * implementation name to take care of role lookup operations.
 * @param engine the wiki engine
 * @param properties the set of properties used to initialize the wiki engine
 * @throws WikiException if the AuthorizationManager cannot be initialized
 */
public void initialize(WikiEngine engine, Properties properties) throws WikiException {
    m_engine = engine;
    // 
    // JAAS authorization continues
    // 
    m_authorizer = getAuthorizerImplementation(properties);
    m_authorizer.initialize(engine, properties);
    // Initialize local security policy
    try {
        String policyFileName = properties.getProperty(POLICY, DEFAULT_POLICY);
        URL policyURL = AuthenticationManager.findConfigFile(engine, policyFileName);
        if (policyURL != null) {
            File policyFile = new File(policyURL.toURI().getPath());
            log.info("We found security policy URL: " + policyURL + " and transformed it to file " + policyFile.getAbsolutePath());
            m_localPolicy = new LocalPolicy(policyFile, engine.getContentEncoding());
            m_localPolicy.refresh();
            log.info("Initialized default security policy: " + policyFile.getAbsolutePath());
        } else {
            String sb = "JSPWiki was unable to initialize the default security policy (WEB-INF/jspwiki.policy) file. " + "Please ensure that the jspwiki.policy file exists in the default location. " + "This file should exist regardless of the existance of a global policy file. " + "The global policy file is identified by the java.security.policy variable. ";
            WikiSecurityException wse = new WikiSecurityException(sb);
            log.fatal(sb, wse);
            throw wse;
        }
    } catch (Exception e) {
        log.error("Could not initialize local security policy: " + e.getMessage());
        throw new WikiException("Could not initialize local security policy: " + e.getMessage(), e);
    }
}
Also used : WikiException(org.apache.wiki.api.exceptions.WikiException) LocalPolicy(org.freshcookies.security.policy.LocalPolicy) File(java.io.File) URL(java.net.URL) WikiException(org.apache.wiki.api.exceptions.WikiException) NoRequiredPropertyException(org.apache.wiki.api.exceptions.NoRequiredPropertyException) IOException(java.io.IOException) AccessControlException(java.security.AccessControlException)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 AccessControlException (java.security.AccessControlException)1 NoRequiredPropertyException (org.apache.wiki.api.exceptions.NoRequiredPropertyException)1 WikiException (org.apache.wiki.api.exceptions.WikiException)1 LocalPolicy (org.freshcookies.security.policy.LocalPolicy)1