You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2009/02/14 13:41:01 UTC
svn commit: r744491 - in /lenya/trunk:
org.apache.lenya.core.ac/src/main/resources/META-INF/cocoon/spring/
org.apache.lenya.core.cache/src/main/java/org/apache/lenya/ac/cache/
org.apache.lenya.core.usecase/src/main/java/org/apache/lenya/cms/ac/usecase/...
Author: andreas
Date: Sat Feb 14 12:41:00 2009
New Revision: 744491
URL: http://svn.apache.org/viewvc?rev=744491&view=rev
Log:
Fixed access control component declarations and bean wiring.
Modified:
lenya/trunk/org.apache.lenya.core.ac/src/main/resources/META-INF/cocoon/spring/lenya-core-ac-components.xml
lenya/trunk/org.apache.lenya.core.cache/src/main/java/org/apache/lenya/ac/cache/SourceCacheImpl.java
lenya/trunk/org.apache.lenya.core.usecase/src/main/java/org/apache/lenya/cms/ac/usecase/impl/UsecaseAuthorizerImpl.java
lenya/trunk/org.apache.lenya.core.usecase/src/main/java/org/apache/lenya/cms/ac/usecase/impl/UsecaseRolesBuilder.java
lenya/trunk/org.apache.lenya.core.usecase/src/main/resources/META-INF/cocoon/spring/lenya-core-usecase.xml
Modified: lenya/trunk/org.apache.lenya.core.ac/src/main/resources/META-INF/cocoon/spring/lenya-core-ac-components.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.ac/src/main/resources/META-INF/cocoon/spring/lenya-core-ac-components.xml?rev=744491&r1=744490&r2=744491&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.ac/src/main/resources/META-INF/cocoon/spring/lenya-core-ac-components.xml (original)
+++ lenya/trunk/org.apache.lenya.core.ac/src/main/resources/META-INF/cocoon/spring/lenya-core-ac-components.xml Sat Feb 14 12:41:00 2009
@@ -70,7 +70,10 @@
</bean>
<bean name="org.apache.lenya.ac.file.FilePolicyManagerFactory"
- class="org.apache.lenya.ac.file.FilePolicyManagerFactory"/>
+ class="org.apache.lenya.ac.file.FilePolicyManagerFactory">
+ <property name="sourceResolver" ref="org.apache.excalibur.source.SourceResolver"/>
+ <property name="cache" ref="org.apache.lenya.ac.cache.SourceCache"/>
+ </bean>
<bean name="org.apache.lenya.ac.PolicyManager/file"
class="org.apache.lenya.ac.file.FilePolicyManager" scope="prototype"
Modified: lenya/trunk/org.apache.lenya.core.cache/src/main/java/org/apache/lenya/ac/cache/SourceCacheImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.cache/src/main/java/org/apache/lenya/ac/cache/SourceCacheImpl.java?rev=744491&r1=744490&r2=744491&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.cache/src/main/java/org/apache/lenya/ac/cache/SourceCacheImpl.java (original)
+++ lenya/trunk/org.apache.lenya.core.cache/src/main/java/org/apache/lenya/ac/cache/SourceCacheImpl.java Sat Feb 14 12:41:00 2009
@@ -22,7 +22,8 @@
import java.io.InputStream;
import java.net.MalformedURLException;
-import org.apache.cocoon.util.AbstractLogEnabled;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceNotFoundException;
import org.apache.excalibur.source.SourceResolver;
@@ -33,7 +34,9 @@
* Basic implementation of a source cache.
* @version $Id$
*/
-public class SourceCacheImpl extends AbstractLogEnabled implements SourceCache {
+public class SourceCacheImpl implements SourceCache {
+
+ private static final Log logger = LogFactory.getLog(SourceCacheImpl.class);
private SourceResolver sourceResolver;
protected static final int CAPACITY = 1000;
@@ -45,7 +48,7 @@
*/
protected CacheMap getCache() {
if (this.cache == null) {
- this.cache = new CacheMap(CAPACITY, getLogger());
+ this.cache = new CacheMap(CAPACITY, logger);
}
return this.cache;
}
@@ -66,8 +69,8 @@
try {
if (cachedObject != null) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Found cached object [" + cachedObject + "]");
+ if (logger.isDebugEnabled()) {
+ logger.debug("Found cached object [" + cachedObject + "]");
}
SourceValidity cachedValidity = cachedObject.getValidityObject();
@@ -92,15 +95,15 @@
}
if (valid) {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger()
+ if (logger.isDebugEnabled()) {
+ logger
.debug("Using valid cached source for '" + sourceUri + "'.");
}
usedCache = true;
value = cachedObject.getValue();
} else {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger()
+ if (logger.isDebugEnabled()) {
+ logger
.debug("Cached content is invalid for '" + sourceUri + "'.");
}
// remove invalid cached object
@@ -108,22 +111,22 @@
}
} else {
- getLogger().debug("Did not find cached object.");
+ logger.debug("Did not find cached object.");
}
if (!usedCache) {
- getLogger().debug("Did not use cache.");
+ logger.debug("Did not use cache.");
if (key != null) {
if (sourceValidity == null) {
sourceValidity = getSourceValidity(sourceUri);
}
if (sourceValidity != null) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Source validity is not null.");
+ if (logger.isDebugEnabled()) {
+ logger.debug("Source validity is not null.");
}
} else {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Source validity is null - not caching.");
+ if (logger.isDebugEnabled()) {
+ logger.debug("Source validity is null - not caching.");
}
key = null;
}
@@ -133,8 +136,8 @@
// store the response
if (key != null) {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug(
+ if (logger.isDebugEnabled()) {
+ logger.debug(
"Caching object [" + value + "] for further requests of ["
+ sourceUri + "].");
}
Modified: lenya/trunk/org.apache.lenya.core.usecase/src/main/java/org/apache/lenya/cms/ac/usecase/impl/UsecaseAuthorizerImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.usecase/src/main/java/org/apache/lenya/cms/ac/usecase/impl/UsecaseAuthorizerImpl.java?rev=744491&r1=744490&r2=744491&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.usecase/src/main/java/org/apache/lenya/cms/ac/usecase/impl/UsecaseAuthorizerImpl.java (original)
+++ lenya/trunk/org.apache.lenya.core.usecase/src/main/java/org/apache/lenya/cms/ac/usecase/impl/UsecaseAuthorizerImpl.java Sat Feb 14 12:41:00 2009
@@ -21,15 +21,12 @@
import java.util.Arrays;
import java.util.List;
-import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.framework.parameters.Parameterizable;
import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.util.AbstractLogEnabled;
+import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.ac.AccessControlException;
import org.apache.lenya.ac.Role;
import org.apache.lenya.ac.cache.BuildException;
@@ -47,13 +44,13 @@
* Supported parameters via {@link Parameterizable}:
* </p>
* <ul>
- * <li> {@link #PARAMETER_CONFIGURATION} - location of the usecase policies file
- * (parameterizable for testing purposes) </li>
+ * <li> {@link #PARAMETER_CONFIGURATION} - location of the usecase policies file (parameterizable for
+ * testing purposes)</li>
* </ul>
* @version $Id: UsecaseAuthorizer.java 392449 2006-04-07 23:20:38Z michi $
*/
public class UsecaseAuthorizerImpl extends AbstractLogEnabled implements UsecaseAuthorizer,
- Serviceable, Disposable, Parameterizable {
+ Parameterizable {
/**
* The name of the pseudo-usecase that governs access to pages.
@@ -68,12 +65,12 @@
* the configuration URI for this component
*/
private String configurationUri;
- private ServiceManager manager;
+
+ private SourceResolver sourceResolver;
/**
* @see org.apache.lenya.cms.ac.usecase.UsecaseAuthorizer#authorizeUsecase(java.lang.String,
- * org.apache.lenya.ac.Role[],
- * org.apache.lenya.cms.publication.Publication)
+ * org.apache.lenya.ac.Role[], org.apache.lenya.cms.publication.Publication)
*/
public boolean authorizeUsecase(String usecase, Role[] roles, Publication pub)
throws AccessControlException {
@@ -114,8 +111,7 @@
/**
* @see org.apache.lenya.cms.ac.usecase.UsecaseAuthorizer#isPermitted(java.lang.String,
- * org.apache.lenya.cms.publication.Publication,
- * org.apache.lenya.ac.Role)
+ * org.apache.lenya.cms.publication.Publication, org.apache.lenya.ac.Role)
*/
public boolean isPermitted(String usecase, Publication publication, Role role)
throws AccessControlException {
@@ -127,8 +123,7 @@
/**
* @see org.apache.lenya.cms.ac.usecase.UsecaseAuthorizer#setPermission(java.lang.String,
- * org.apache.lenya.cms.publication.Publication,
- * org.apache.lenya.ac.Role, boolean)
+ * org.apache.lenya.cms.publication.Publication, org.apache.lenya.ac.Role, boolean)
*/
public void setPermission(String usecase, Publication publication, Role role, boolean granted)
throws AccessControlException {
@@ -150,15 +145,15 @@
}
UsecaseRolesBuilder builder = new UsecaseRolesBuilder();
try {
- builder.save(usecaseRoles, configUri, this.manager);
+ builder.save(usecaseRoles, configUri, this.sourceResolver);
} catch (BuildException e) {
throw new AccessControlException(e);
}
}
/**
- * This method will substitute VISIT_USECASE if no USECASE_PARAMETER is set,
- * so that it can be used to authorize plain page access as well.
+ * This method will substitute VISIT_USECASE if no USECASE_PARAMETER is set, so that it can be
+ * used to authorize plain page access as well.
* @see org.apache.lenya.ac.Authorizer#authorize(org.apache.cocoon.environment.Request)
*/
public boolean authorize(Request request) throws AccessControlException {
@@ -182,16 +177,7 @@
}
/**
- * Returns the configuration source cache.
- * @return A source cache.
- */
- private SourceCache getCache() {
- return this.cache;
- }
-
- /**
- * Returns the source URI of the usecase role configuration file for a
- * certain publication.
+ * Returns the source URI of the usecase role configuration file for a certain publication.
*
* @param publication The publication.
* @return A string representing a URI.
@@ -204,34 +190,18 @@
UsecaseRolesBuilder builder = new UsecaseRolesBuilder();
UsecaseRoles usecaseRoles;
try {
- usecaseRoles = (UsecaseRoles) getCache().get(_configurationUri, builder);
+ usecaseRoles = (UsecaseRoles) this.cache.get(_configurationUri, builder);
} catch (CachingException e) {
throw new AccessControlException(e);
}
return usecaseRoles;
}
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager _manager) throws ServiceException {
- getLogger().debug("Servicing [" + getClass().getName() + "]");
- this.manager = _manager;
- this.cache = (SourceCache) _manager.lookup(SourceCache.ROLE);
- }
-
- /**
- * @see org.apache.avalon.framework.activity.Disposable#dispose()
- */
- public void dispose() {
- if (getCache() != null) {
- this.manager.release(getCache());
- }
- }
-
public void parameterize(Parameters parameters) throws ParameterException {
if (parameters.isParameter(PARAMETER_CONFIGURATION)) {
- getLogger().warn("Configuring the location of the usecase policies file is not supported anymore.");
+ getLogger()
+ .warn(
+ "Configuring the location of the usecase policies file is not supported anymore.");
}
}
@@ -239,4 +209,8 @@
return this.configurationUri;
}
+ public void setSourceResolver(SourceResolver sourceResolver) {
+ this.sourceResolver = sourceResolver;
+ }
+
}
Modified: lenya/trunk/org.apache.lenya.core.usecase/src/main/java/org/apache/lenya/cms/ac/usecase/impl/UsecaseRolesBuilder.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.usecase/src/main/java/org/apache/lenya/cms/ac/usecase/impl/UsecaseRolesBuilder.java?rev=744491&r1=744490&r2=744491&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.usecase/src/main/java/org/apache/lenya/cms/ac/usecase/impl/UsecaseRolesBuilder.java (original)
+++ lenya/trunk/org.apache.lenya.core.usecase/src/main/java/org/apache/lenya/cms/ac/usecase/impl/UsecaseRolesBuilder.java Sat Feb 14 12:41:00 2009
@@ -22,7 +22,7 @@
import java.util.HashSet;
import java.util.Set;
-import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.ac.AccessController;
import org.apache.lenya.ac.cache.BuildException;
import org.apache.lenya.ac.cache.InputStreamBuilder;
@@ -57,8 +57,7 @@
} catch (Exception e) {
throw new BuildException(e);
}
- assert document.getDocumentElement().getLocalName()
- .equals(USECASES_ELEMENT);
+ assert document.getDocumentElement().getLocalName().equals(USECASES_ELEMENT);
NamespaceHelper helper = new NamespaceHelper(AccessController.NAMESPACE,
AccessController.DEFAULT_PREFIX, document);
@@ -71,7 +70,7 @@
// add roles only if not overridden by child publication
if (!usecaseRoles.hasRoles(usecaseId)) {
Element[] roleElements = helper.getChildren(usecaseElements[i], ROLE_ELEMENT);
- Set roleIds = new HashSet();
+ Set<String> roleIds = new HashSet<String>();
for (int j = 0; j < roleElements.length; j++) {
String roleId = roleElements[j].getAttribute(ID_ATTRIBUTE);
roleIds.add(roleId);
@@ -87,10 +86,11 @@
* Saves the usecase roles.
* @param usecaseRoles The roles.
* @param sourceUri The source to save to.
- * @param manager The service manager.
+ * @param sourceResolver The source resolver.
* @throws BuildException if an error occurs.
*/
- public void save(UsecaseRoles usecaseRoles, String sourceUri, ServiceManager manager) throws BuildException {
+ public void save(UsecaseRoles usecaseRoles, String sourceUri, SourceResolver sourceResolver)
+ throws BuildException {
try {
NamespaceHelper helper = new NamespaceHelper(AccessController.NAMESPACE,
AccessController.DEFAULT_PREFIX, USECASES_ELEMENT);
@@ -106,7 +106,7 @@
roleElement.setAttribute(ID_ATTRIBUTE, roles[r]);
}
}
- SourceUtil.writeDOM(helper.getDocument(), sourceUri, manager);
+ SourceUtil.writeDOM(helper.getDocument(), sourceUri, sourceResolver);
} catch (Exception e) {
throw new BuildException(e);
}
Modified: lenya/trunk/org.apache.lenya.core.usecase/src/main/resources/META-INF/cocoon/spring/lenya-core-usecase.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.usecase/src/main/resources/META-INF/cocoon/spring/lenya-core-usecase.xml?rev=744491&r1=744490&r2=744491&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.usecase/src/main/resources/META-INF/cocoon/spring/lenya-core-usecase.xml (original)
+++ lenya/trunk/org.apache.lenya.core.usecase/src/main/resources/META-INF/cocoon/spring/lenya-core-usecase.xml Sat Feb 14 12:41:00 2009
@@ -19,4 +19,11 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
xmlns="http://www.springframework.org/schema/beans">
+
+ <bean name="org.apache.lenya.ac.Authorizer/usecase"
+ class="org.apache.lenya.cms.ac.usecase.impl.UsecaseAuthorizerIMpl">
+ <property name="sourceResolver" ref="org.apache.excalibur.source.SourceResolver"/>
+ <property name="cache" ref="org.apache.lenya.ac.cache.SourceCache"/>
+ </bean>
+
</beans>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org