You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2017/03/20 14:12:17 UTC
svn commit: r1787777 - in /sling/trunk/bundles/extensions/caconfig:
impl/src/main/java/org/apache/sling/caconfig/impl/def/
spi/src/main/java/org/apache/sling/caconfig/spi/
Author: sseifert
Date: Mon Mar 20 14:12:17 2017
New Revision: 1787777
URL: http://svn.apache.org/viewvc?rev=1787777&view=rev
Log:
SLING-6674 Context-Aware Config: Separate exception when persist failes due to missing access rights
Added:
sling/trunk/bundles/extensions/caconfig/spi/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceAccessDeniedException.java (with props)
Modified:
sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/impl/def/DefaultConfigurationPersistenceStrategy.java
sling/trunk/bundles/extensions/caconfig/spi/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceException.java
Modified: sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/impl/def/DefaultConfigurationPersistenceStrategy.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/impl/def/DefaultConfigurationPersistenceStrategy.java?rev=1787777&r1=1787776&r2=1787777&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/impl/def/DefaultConfigurationPersistenceStrategy.java (original)
+++ sling/trunk/bundles/extensions/caconfig/impl/src/main/java/org/apache/sling/caconfig/impl/def/DefaultConfigurationPersistenceStrategy.java Mon Mar 20 14:12:17 2017
@@ -22,6 +22,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
@@ -31,6 +32,7 @@ import org.apache.sling.caconfig.resourc
import org.apache.sling.caconfig.resource.impl.util.PropertiesFilterUtil;
import org.apache.sling.caconfig.spi.ConfigurationCollectionPersistData;
import org.apache.sling.caconfig.spi.ConfigurationPersistData;
+import org.apache.sling.caconfig.spi.ConfigurationPersistenceAccessDeniedException;
import org.apache.sling.caconfig.spi.ConfigurationPersistenceException;
import org.apache.sling.caconfig.spi.ConfigurationPersistenceStrategy2;
import org.osgi.service.component.ComponentContext;
@@ -184,7 +186,7 @@ public class DefaultConfigurationPersist
resourceResolver.delete(resource);
}
catch (PersistenceException ex) {
- throw new ConfigurationPersistenceException("Unable to delete configuration at " + configResourcePath, ex);
+ throw convertPeristenceException("Unable to delete configuration at " + configResourcePath, ex);
}
}
commit(resourceResolver);
@@ -200,7 +202,7 @@ public class DefaultConfigurationPersist
return resource;
}
catch (PersistenceException ex) {
- throw new ConfigurationPersistenceException("Unable to persist configuration to " + path, ex);
+ throw convertPeristenceException("Unable to persist configuration to " + path, ex);
}
}
@@ -213,7 +215,7 @@ public class DefaultConfigurationPersist
}
}
catch (PersistenceException ex) {
- throw new ConfigurationPersistenceException("Unable to remove children from " + resource.getPath(), ex);
+ throw convertPeristenceException("Unable to remove children from " + resource.getPath(), ex);
}
}
@@ -222,6 +224,9 @@ public class DefaultConfigurationPersist
log.trace("! Store properties for resource {}: {}", resource.getPath(), MapUtil.traceOutput(properties));
}
ModifiableValueMap modValueMap = resource.adaptTo(ModifiableValueMap.class);
+ if (modValueMap == null) {
+ throw new ConfigurationPersistenceAccessDeniedException("Unable to write properties to " + resource.getPath() + " - access is read-only.");
+ }
// remove all existing properties that are not filterd
Set<String> propertyNamesToRemove = new HashSet<>(modValueMap.keySet());
PropertiesFilterUtil.removeIgnoredProperties(propertyNamesToRemove);
@@ -236,8 +241,16 @@ public class DefaultConfigurationPersist
resourceResolver.commit();
}
catch (PersistenceException ex) {
- throw new ConfigurationPersistenceException("Unable to save configuration: " + ex.getMessage(), ex);
+ throw convertPeristenceException("Unable to commit configuration changes: " + ex.getMessage(), ex);
+ }
+ }
+
+ private ConfigurationPersistenceException convertPeristenceException(String message, PersistenceException ex) {
+ if (StringUtils.equals(ex.getCause().getClass().getName(), "javax.jcr.AccessDeniedException")) {
+ // detect if commit failed due to read-only access to repository
+ return new ConfigurationPersistenceAccessDeniedException(message, ex);
}
+ return new ConfigurationPersistenceException(message, ex);
}
}
Added: sling/trunk/bundles/extensions/caconfig/spi/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceAccessDeniedException.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/caconfig/spi/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceAccessDeniedException.java?rev=1787777&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/caconfig/spi/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceAccessDeniedException.java (added)
+++ sling/trunk/bundles/extensions/caconfig/spi/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceAccessDeniedException.java Mon Mar 20 14:12:17 2017
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under 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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.caconfig.spi;
+
+import org.osgi.annotation.versioning.ProviderType;
+
+/**
+ * Is thrown when configuration cannot be persisted because the user is not allowed to write to repository.
+ */
+@ProviderType
+public final class ConfigurationPersistenceAccessDeniedException extends ConfigurationPersistenceException {
+ private static final long serialVersionUID = 1L;
+
+ public ConfigurationPersistenceAccessDeniedException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ConfigurationPersistenceAccessDeniedException(String message) {
+ super(message);
+ }
+
+}
Propchange: sling/trunk/bundles/extensions/caconfig/spi/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceAccessDeniedException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/bundles/extensions/caconfig/spi/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceAccessDeniedException.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon Mar 20 14:12:17 2017
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/bundles/extensions/caconfig/spi/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceAccessDeniedException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/bundles/extensions/caconfig/spi/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceException.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/caconfig/spi/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceException.java?rev=1787777&r1=1787776&r2=1787777&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/caconfig/spi/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceException.java (original)
+++ sling/trunk/bundles/extensions/caconfig/spi/src/main/java/org/apache/sling/caconfig/spi/ConfigurationPersistenceException.java Mon Mar 20 14:12:17 2017
@@ -24,7 +24,7 @@ import org.osgi.annotation.versioning.Pr
* Is thrown when configuration cannot be persisted.
*/
@ProviderType
-public final class ConfigurationPersistenceException extends RuntimeException {
+public class ConfigurationPersistenceException extends RuntimeException {
private static final long serialVersionUID = 1L;
public ConfigurationPersistenceException(String message, Throwable cause) {