All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.fedora.server.security.DefaultBackendSecurity Maven / Gradle / Ivy

Go to download

The Fedora Client is a Java Library that allows API access to a Fedora Repository. The client is typically one part of a full Fedora installation.

The newest version!
/*
 * -----------------------------------------------------------------------------
 *
 * 

License and Copyright: The contents of this file are subject to the * Apache License, Version 2.0 (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of * the License at * http://www.fedora-commons.org/licenses.

* *

Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License.

* *

The entire file consists of original code.

*

Copyright © 2008 Fedora Commons, Inc.
*

Copyright © 2002-2007 The Rector and Visitors of the University of * Virginia and Cornell University
* All rights reserved.

* * ----------------------------------------------------------------------------- */ package fedora.server.security; import java.util.Set; import java.util.Iterator; import java.util.Map; import org.apache.log4j.Logger; import fedora.common.Constants; import fedora.server.Module; import fedora.server.Server; import fedora.server.errors.BackendSecurityParserException; import fedora.server.errors.ModuleInitializationException; import fedora.server.security.BackendSecurityDeserializer; import fedora.server.security.BackendSecuritySpec; /** * A Module for accessing backend service security configuration information. * * @author [email protected] * @version $Id: DefaultBackendSecurity.java 5313 2006-12-06 12:14:27Z cwilper $ */ public class DefaultBackendSecurity extends Module implements BackendSecurity{ /** Logger for this class. */ private static final Logger LOG = Logger.getLogger( DefaultBackendSecurity.class.getName()); public static BackendSecuritySpec beSS = null; private boolean m_validate = false; private String m_encoding = null; private static String m_beSecurityPath = null; /** *

Creates a new DefaultBackendSecurity.

* * @param moduleParameters The name/value pair map of module parameters. * @param server The server instance. * @param role The module role name. * @throws ModuleInitializationException If initialization values are * invalid or initialization fails for some other reason. */ public DefaultBackendSecurity(Map moduleParameters, Server server, String role) throws ModuleInitializationException { super(moduleParameters, server, role); } /** * Post-Initializes the Module based on configuration parameters. The * implementation of this method is dependent on the schema used to define * the parameter names for the role of * fedora.server.storage.DefaultBackendSecurity. * * @throws ModuleInitializationException If initialization values are * invalid or initialization fails for some other reason. */ public void postInitModule() throws ModuleInitializationException { try { Server s_server = this.getServer(); LOG.debug("DefaultBackendSecurity initialized"); String fedoraHome = Constants.FEDORA_HOME; if (fedoraHome == null) { throw new ModuleInitializationException( "[DefaultBackendSecurity] Module failed to initialize: " + "FEDORA_HOME is undefined", getRole()); } else { m_beSecurityPath = fedoraHome + "/server/config/beSecurity.xml"; } LOG.debug("m_beSecurityPath: " + m_beSecurityPath); String validate = getParameter("beSecurity_validation"); if (validate!=null) { if (!validate.equals("true") && !validate.equals("false")) { LOG.warn("Validation setting for backend " + "security configuration file must be either \"true\" or \"false\". " + "Value specified was: \"" + validate + "\". Validation is defaulted to " + "\"false\"."); } else { m_validate = new Boolean(validate).booleanValue(); } } else { LOG.warn("Validation setting for backend " + "security configuration file was not specified. Validation is defaulted to " + "\"false\"."); } LOG.debug("beSecurity_validate: " + m_validate); m_encoding = getParameter("beSecurity_char_encoding"); if (m_encoding==null) { m_encoding = "utf-8"; LOG.warn("Character encoding for backend " + "security configuration file was not specified. Encoding defaulted to " + "\"utf-8\"."); } LOG.debug("beSecurity_char_encoding: " + m_encoding); // initialize static BackendSecuritySpec instance setBackendSecuritySpec(); if (LOG.isDebugEnabled()) { Set roleList = (Set) beSS.listRoleKeys(); Iterator iter = roleList.iterator(); while (iter.hasNext()) { LOG.debug("beSecurity ROLE: "+iter.next()); } } } catch (Throwable th) { throw new ModuleInitializationException("[DefaultBackendSecurity] " + "BackendSecurity " + "could not be instantiated. The underlying error was a " + th.getClass().getName() + "The message was \"" + th.getMessage() + "\".", getRole()); } } /** * Parses the beSecurity configuration file. * * @throws BackendSecurityParserException If an error occurs in attempting * to parse the beSecurity configuration file. */ public BackendSecuritySpec parseBeSecurity() throws BackendSecurityParserException { try { BackendSecurityDeserializer bsd = new BackendSecurityDeserializer(m_encoding, m_validate); return bsd.deserialize(m_beSecurityPath); } catch (Throwable th) { throw new BackendSecurityParserException("[DefaultBackendSecurity] " + "An error has occured in parsing the backend security " + "configuration file located at \"" + m_beSecurityPath + "\". " + "The underlying error was a " + th.getClass().getName() + "The message was \"" + th.getMessage() + "\"."); } } /** * Gets the static instance of BackendSecuritySpec. */ public BackendSecuritySpec getBackendSecuritySpec() { return beSS; } /** * Initializes the static BackendSecuritySpec instance. * * @throws BackendSecurityParserException If an error occurs in attempting * to parse the beSecurity configuration file. */ public void setBackendSecuritySpec() throws BackendSecurityParserException{ beSS = parseBeSecurity(); } /** * Re-initializes the static backendSecuritySpec instance by rereading the * beSecurity configurationfile. This method is used to refresh the beSecurity * configuration on the server when changes have been made to the configuration * file. * * @throws BackendSecurityParserException If an error occurs in attempting * to parse the beSecurity configuration file. */ public BackendSecuritySpec reloadBeSecurity() throws BackendSecurityParserException { return parseBeSecurity(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy