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

java.fedora.server.security.ContextAttributeFinderModule 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.Hashtable; import java.net.URI; import java.net.URISyntaxException; import com.sun.xacml.EvaluationCtx; import com.sun.xacml.attr.AttributeDesignator; import com.sun.xacml.attr.StringAttribute; import com.sun.xacml.cond.EvaluationResult; import org.apache.log4j.Logger; import fedora.common.Constants; import fedora.server.Context; /** * @author [email protected] */ class ContextAttributeFinderModule extends AttributeFinderModule { /** Logger for this class. */ private static final Logger LOG = Logger.getLogger( ContextAttributeFinderModule.class.getName()); protected boolean canHandleAdhoc() { return true; } static private final ContextAttributeFinderModule singleton = new ContextAttributeFinderModule(); private final Hashtable contexts = new Hashtable(); private ContextAttributeFinderModule() { super(); try { registerSupportedDesignatorType(AttributeDesignator.SUBJECT_TARGET); registerSupportedDesignatorType(AttributeDesignator.ACTION_TARGET); //< context.nSubjectValues(attributeId)) { values = null; } else { LOG.debug("getting n values for " + attributeId + "=" + context.nSubjectValues(attributeId)); switch(context.nSubjectValues(attributeId)) { case 0: values = null; /* values = new String[1]; ((String[])values)[0] = Authorization.UNDEFINED; */ break; case 1: values = new String[1]; ((String[])values)[0] = context.getSubjectValue(attributeId); break; default: values = context.getSubjectValues(attributeId); } if (values == null) { LOG.debug("RETURNING NO VALUES FOR " + attributeId); } else { StringBuffer sb = new StringBuffer(); sb.append("RETURNING " + ((String[])values).length + " VALUES FOR " + attributeId + " =="); for (int i = 0; i < ((String[])values).length; i++) { sb.append(" " + ((String[])values)[i]); } LOG.debug(sb); } } break; case AttributeDesignator.ACTION_TARGET: if (0 > context.nActionValues(attributeId)) { values = null; } else { switch(context.nActionValues(attributeId)) { case 0: values = null; /* values = new String[1]; ((String[])values)[0] = Authorization.UNDEFINED; */ break; case 1: values = new String[1]; ((String[])values)[0] = context.getActionValue(attributeId); break; default: values = context.getActionValues(attributeId); } } break; case AttributeDesignator.RESOURCE_TARGET: if (0 > context.nResourceValues(attributeId)) { values = null; } else { switch(context.nResourceValues(attributeId)) { case 0: values = null; /* values = new String[1]; ((String[])values)[0] = Authorization.UNDEFINED; */ break; case 1: values = new String[1]; ((String[])values)[0] = context.getResourceValue(attributeId); break; default: values = context.getResourceValues(attributeId); } } break; case AttributeDesignator.ENVIRONMENT_TARGET: if (0 > context.nEnvironmentValues(attributeId)) { values = null; } else { switch(context.nEnvironmentValues(attributeId)) { case 0: values = null; /* values = new String[1]; ((String[])values)[0] = Authorization.UNDEFINED; */ break; case 1: values = new String[1]; ((String[])values)[0] = context.getEnvironmentValue(attributeId); break; default: values = context.getEnvironmentValues(attributeId); } } break; default: } if (values instanceof String) { LOG.debug("getAttributeLocally string value=" + ((String)values)); } else if (values instanceof String[]) { LOG.debug("getAttributeLocally string values=" + values); for (int i=0; i<((String[])values).length; i++) { LOG.debug("another string value=" + ((String[])values)[i]); } } else { LOG.debug("getAttributeLocally object value=" + values); } return values; } final void registerContext(Object key, Context value) { LOG.debug("registering " + key); contexts.put(key, value); } final void unregisterContext(Object key) { LOG.debug("unregistering " + key); contexts.remove(key); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy